discord-kurante/src/passive/fufufu.rs

67 lines
2.2 KiB
Rust

use futures::future::BoxFuture;
use lazy_static::lazy_static;
use regex::Regex;
use serenity::async_trait;
use serenity::model::channel::Message;
use serenity::prelude::{Context, EventHandler};
lazy_static! {
static ref REGEX: Regex = Regex::new("(?i:fu){3,}").unwrap();
}
pub(crate) struct FufufuResponder;
#[async_trait]
impl EventHandler for FufufuResponder {
async fn message(&self, ctx: Context, message: Message) {
if REGEX.is_match(&message.content_safe(ctx.clone()).await) {
use rand::seq::SliceRandom;
use rand::thread_rng;
let random_action = DESU_ACTIONS.choose(&mut thread_rng()).unwrap().clone();
let random_action = random_action(ctx, message);
random_action.await.unwrap();
}
}
}
type DesuAction<'r, T> = &'r (dyn Fn(Context, Message) -> T + Sync);
const DESU_ACTIONS: &[DesuAction<BoxFuture<Result<Message, serenity::Error>>>] = &[
&|ctx, msg| Box::pin(msg.channel_id.say(ctx, "です。")),
&|ctx, msg| Box::pin(msg.channel_id.say(ctx, "desu~")),
&|ctx, msg| Box::pin(msg.channel_id.say(ctx, "desu.")),
&|ctx, msg| {
Box::pin(msg.channel_id.say(
ctx,
r#"
```
ででででででででででで      すす
     ででで     すすすすすすすすす
    でで  でで      すす
   でで   でで     すすす
  でで           す す
  でで           すすす
   でで           すす
    でで          すす
     でで        すす
```"#,
))
},
&|ctx, msg| {
// https://imgur.com/a/yOb5n
// One day.
Box::pin(
msg.channel_id
.say(ctx, "https://www.youtube.com/watch?v=60mLvBWOMb4"),
)
},
&|ctx, msg| {
Box::pin(msg.channel_id.send_message(ctx, |m| {
m.add_file(serenity::http::AttachmentType::Bytes {
data: std::borrow::Cow::from(&include_bytes!("../desu.jpg")[..]),
filename: "desu.jpg".to_string(),
})
}))
},
];