more refactor

This commit is contained in:
Edward Shen 2020-05-01 22:27:40 -04:00
parent a57fa13004
commit 4b3dfcbc68
Signed by: edward
GPG key ID: 19182661E818369F
4 changed files with 18 additions and 63 deletions

View file

@ -22,7 +22,7 @@ impl EventHandler for YellResponder {
if self.regex.is_match(content) {
message
.channel_id
.say(ctx, "no, u is smol brain doctor..")
.say(ctx, "its ok ur gonna get a 6* someday")
.await
.unwrap();
}

View file

@ -22,7 +22,7 @@ impl EventHandler for BestDoctorResponder {
if self.regex.is_match(content) {
message
.channel_id
.say(ctx, "its ok ur gonna get a 6* someday")
.say(ctx, "smol brain doctor..")
.await
.unwrap();
}

View file

@ -3,11 +3,11 @@ use serenity::async_trait;
use serenity::model::channel::Message;
use serenity::prelude::{Context, EventHandler};
pub(crate) struct BestDoctorResponder {
pub(crate) struct FufufuResponder {
regex: Regex,
}
impl Default for BestDoctorResponder {
impl Default for FufufuResponder {
fn default() -> Self {
Self {
regex: Regex::new(r"(?:[fF][uU]){3,}").unwrap(),
@ -16,15 +16,11 @@ impl Default for BestDoctorResponder {
}
#[async_trait]
impl EventHandler for BestDoctorResponder {
impl EventHandler for FufufuResponder {
async fn message(&self, ctx: Context, message: Message) {
let content = &message.content_safe(ctx.clone()).await;
if self.regex.is_match(content) {
message
.channel_id
.say(ctx, get_desu())
.await
.unwrap();
message.channel_id.say(ctx, get_desu()).await.unwrap();
}
}
}

View file

@ -1,24 +1,26 @@
use regex::Regex;
use ahhhh::YellResponder;
use best_doctor::BestDoctorResponder;
use fufufu::FufufuResponder;
use serenity::async_trait;
use serenity::model::channel::Message;
use serenity::prelude::{Context, EventHandler};
mod ahhhh;
mod best_doctor;
mod fufufu;
mod yell_resp;
pub(crate) struct Handler {
ah_regex: Regex,
best_doctor_regex: Regex,
fufufu_regex: Regex,
responders: Vec<Box<dyn EventHandler>>,
}
impl Default for Handler {
fn default() -> Self {
Self {
ah_regex: Regex::new(r"A+H{5,}").unwrap(),
best_doctor_regex: Regex::new(r"[iI].*(?:best|genius) doc").unwrap(),
fufufu_regex: Regex::new(r"(?:[fF][uU]){3,}").unwrap(),
responders: vec![
Box::new(BestDoctorResponder::default()),
Box::new(FufufuResponder::default()),
Box::new(YellResponder::default()),
],
}
}
}
@ -26,51 +28,8 @@ impl Default for Handler {
#[async_trait]
impl EventHandler for Handler {
async fn message(&self, ctx: Context, message: Message) {
let content = &message.content_safe(ctx.clone()).await;
if self.ah_regex.is_match(content) {
message
.channel_id
.say(ctx, "its ok ur gonna get a 6* someday")
.await
.unwrap();
} else if self.best_doctor_regex.is_match(content) {
message
.channel_id
.say(ctx, "no, u is smol brain doctor...")
.await
.unwrap();
} else if self.fufufu_regex.is_match(content) {
message.channel_id.say(ctx, get_desu()).await.unwrap();
for responder in self.responders.iter() {
responder.message(ctx.clone(), message.clone()).await;
}
}
}
const DESU_STRINGS: &[&str] = &[
"です。",
"desu~",
"desu.",
r#"
```
      
          
            
           
              
             
              
              
             
```"#,
];
fn get_desu() -> &'static str {
use rand::seq::SliceRandom;
use rand::thread_rng;
DESU_STRINGS.choose(&mut thread_rng()).unwrap()
// // https://imgur.com/a/yOb5n
// messageList.add(channel -> channel.sendMessage(new MessageBuilder()
// .setContent("https://www.youtube.com/watch?v=60mLvBWOMb4").build()));
// messageList.add(channel -> channel.sendFile(Desu.class.getResourceAsStream("/desu/desu.jpg"), "desu.jpg"));
// messageList.add(channel -> channel.sendMessage("desu~"));
}