desu
This commit is contained in:
parent
8de3dd8d0e
commit
9026acdc19
2 changed files with 15 additions and 10 deletions
|
@ -1,5 +1,8 @@
|
|||
use futures::future::BoxFuture;
|
||||
use lazy_static::lazy_static;
|
||||
use rand::seq::SliceRandom;
|
||||
use rand::thread_rng;
|
||||
use rand::Rng;
|
||||
use regex::Regex;
|
||||
use serenity::async_trait;
|
||||
use serenity::model::channel::Message;
|
||||
|
@ -7,18 +10,20 @@ use serenity::prelude::{Context, EventHandler};
|
|||
|
||||
lazy_static! {
|
||||
static ref REGEX: Regex = Regex::new("(?i:fu){3,}").unwrap();
|
||||
static ref DESU_REGEX: Regex = Regex::new("(?i:desu)|(?:です)").unwrap();
|
||||
}
|
||||
|
||||
pub(crate) struct FufufuResponder;
|
||||
pub(crate) struct DesuResponder;
|
||||
|
||||
#[async_trait]
|
||||
impl EventHandler for FufufuResponder {
|
||||
impl EventHandler for DesuResponder {
|
||||
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);
|
||||
let content = message.content_safe(ctx.clone()).await;
|
||||
if REGEX.is_match(&content)
|
||||
|| (DESU_REGEX.is_match(&content) && thread_rng().gen::<f32>() < 0.1)
|
||||
{
|
||||
let random_action =
|
||||
DESU_ACTIONS.choose(&mut thread_rng()).unwrap().clone()(ctx, message);
|
||||
random_action.await.unwrap();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
use ahhhh::YellResponder;
|
||||
use best_doctor::BestDoctorResponder;
|
||||
use fufufu::FufufuResponder;
|
||||
use desu::DesuResponder;
|
||||
use reee::ReeeResponder;
|
||||
use serenity::async_trait;
|
||||
use serenity::model::channel::Message;
|
||||
|
@ -8,7 +8,7 @@ use serenity::prelude::{Context, EventHandler};
|
|||
|
||||
mod ahhhh;
|
||||
mod best_doctor;
|
||||
mod fufufu;
|
||||
mod desu;
|
||||
mod reee;
|
||||
|
||||
pub(crate) struct Handler {
|
||||
|
@ -20,7 +20,7 @@ impl Default for Handler {
|
|||
Self {
|
||||
responders: vec![
|
||||
Box::new(BestDoctorResponder),
|
||||
Box::new(FufufuResponder),
|
||||
Box::new(DesuResponder),
|
||||
Box::new(YellResponder),
|
||||
Box::new(ReeeResponder),
|
||||
],
|
||||
|
|
Loading…
Reference in a new issue