improve desu

This commit is contained in:
Edward Shen 2020-05-02 03:06:43 -04:00
parent ea414b0577
commit 408cd38d4c
Signed by: edward
GPG key ID: 19182661E818369F
2 changed files with 47 additions and 21 deletions

BIN
src/desu.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

View file

@ -1,19 +1,39 @@
use crate::simple_responder; use futures::future::BoxFuture;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use regex::Regex; use regex::Regex;
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};
// Yes, the blocks are necessary, rustc is bugged; check macro declaration lazy_static! {
// for more info. static ref REGEX: Regex = Regex::new("(?:[fF][uU]){3,}").unwrap();
simple_responder!(FufufuResponder, r"(?:[fF][uU]){3,}", { get_desu() }); }
const DESU_STRINGS: &[&str] = &[ pub(crate) struct FufufuResponder;
"です。",
"desu~", #[async_trait]
"desu.", impl EventHandler for FufufuResponder {
r#" 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#"
``` ```
             
                     
@ -25,16 +45,22 @@ const DESU_STRINGS: &[&str] = &[
                             
                           
```"#, ```"#,
))
},
&|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(),
})
}))
},
]; ];
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~"));
}