more refactor
This commit is contained in:
parent
a57fa13004
commit
4b3dfcbc68
4 changed files with 18 additions and 63 deletions
|
@ -22,7 +22,7 @@ impl EventHandler for YellResponder {
|
||||||
if self.regex.is_match(content) {
|
if self.regex.is_match(content) {
|
||||||
message
|
message
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(ctx, "no, u is smol brain doctor..")
|
.say(ctx, "its ok ur gonna get a 6* someday")
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
|
@ -22,7 +22,7 @@ impl EventHandler for BestDoctorResponder {
|
||||||
if self.regex.is_match(content) {
|
if self.regex.is_match(content) {
|
||||||
message
|
message
|
||||||
.channel_id
|
.channel_id
|
||||||
.say(ctx, "its ok ur gonna get a 6* someday")
|
.say(ctx, "smol brain doctor..")
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,11 @@ use serenity::async_trait;
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::prelude::{Context, EventHandler};
|
use serenity::prelude::{Context, EventHandler};
|
||||||
|
|
||||||
pub(crate) struct BestDoctorResponder {
|
pub(crate) struct FufufuResponder {
|
||||||
regex: Regex,
|
regex: Regex,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for BestDoctorResponder {
|
impl Default for FufufuResponder {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
regex: Regex::new(r"(?:[fF][uU]){3,}").unwrap(),
|
regex: Regex::new(r"(?:[fF][uU]){3,}").unwrap(),
|
||||||
|
@ -16,15 +16,11 @@ impl Default for BestDoctorResponder {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for BestDoctorResponder {
|
impl EventHandler for FufufuResponder {
|
||||||
async fn message(&self, ctx: Context, message: Message) {
|
async fn message(&self, ctx: Context, message: Message) {
|
||||||
let content = &message.content_safe(ctx.clone()).await;
|
let content = &message.content_safe(ctx.clone()).await;
|
||||||
if self.regex.is_match(content) {
|
if self.regex.is_match(content) {
|
||||||
message
|
message.channel_id.say(ctx, get_desu()).await.unwrap();
|
||||||
.channel_id
|
|
||||||
.say(ctx, get_desu())
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,26 @@
|
||||||
use regex::Regex;
|
use ahhhh::YellResponder;
|
||||||
|
use best_doctor::BestDoctorResponder;
|
||||||
|
use fufufu::FufufuResponder;
|
||||||
use serenity::async_trait;
|
use serenity::async_trait;
|
||||||
use serenity::model::channel::Message;
|
use serenity::model::channel::Message;
|
||||||
use serenity::prelude::{Context, EventHandler};
|
use serenity::prelude::{Context, EventHandler};
|
||||||
|
|
||||||
|
mod ahhhh;
|
||||||
mod best_doctor;
|
mod best_doctor;
|
||||||
mod fufufu;
|
mod fufufu;
|
||||||
mod yell_resp;
|
|
||||||
|
|
||||||
pub(crate) struct Handler {
|
pub(crate) struct Handler {
|
||||||
ah_regex: Regex,
|
responders: Vec<Box<dyn EventHandler>>,
|
||||||
best_doctor_regex: Regex,
|
|
||||||
fufufu_regex: Regex,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Handler {
|
impl Default for Handler {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
ah_regex: Regex::new(r"A+H{5,}").unwrap(),
|
responders: vec![
|
||||||
best_doctor_regex: Regex::new(r"[iI].*(?:best|genius) doc").unwrap(),
|
Box::new(BestDoctorResponder::default()),
|
||||||
fufufu_regex: Regex::new(r"(?:[fF][uU]){3,}").unwrap(),
|
Box::new(FufufuResponder::default()),
|
||||||
|
Box::new(YellResponder::default()),
|
||||||
|
],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,51 +28,8 @@ impl Default for Handler {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for Handler {
|
impl EventHandler for Handler {
|
||||||
async fn message(&self, ctx: Context, message: Message) {
|
async fn message(&self, ctx: Context, message: Message) {
|
||||||
let content = &message.content_safe(ctx.clone()).await;
|
for responder in self.responders.iter() {
|
||||||
if self.ah_regex.is_match(content) {
|
responder.message(ctx.clone(), message.clone()).await;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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~"));
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue