From 1a85d05133d3b5403b5372444923868f22c6802c Mon Sep 17 00:00:00 2001 From: Stephen D <webmaster@scd31.com> Date: Thu, 29 Sep 2022 18:38:18 -0300 Subject: [PATCH] dumb horse meme --- Cargo.lock | 1 + Cargo.toml | 1 + src/handlers/horse.rs | 22 ++++++++++++++++++++++ src/handlers/mod.rs | 3 +++ src/handlers/react.rs | 3 ++- src/handlers/xbasic.rs | 12 ++++++------ 6 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 src/handlers/horse.rs diff --git a/Cargo.lock b/Cargo.lock index ad41dd1..b6c74ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,6 +121,7 @@ dependencies = [ "dotenv", "phf", "png", + "rand 0.8.3", "reqwest", "rusttype", "serde", diff --git a/Cargo.toml b/Cargo.toml index 3d6dc6b..4d34e16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,3 +20,4 @@ bigdecimal = "0.1.2" reqwest = { version = "0.10", features = ["json"] } serde_json = "1.0" rusttype = "0.4.3" +rand = "0.8" diff --git a/src/handlers/horse.rs b/src/handlers/horse.rs new file mode 100644 index 0000000..32a4a97 --- /dev/null +++ b/src/handlers/horse.rs @@ -0,0 +1,22 @@ +use crate::handlers::LineHandler; +use serenity::async_trait; +use serenity::model::channel::{Message, ReactionType}; +use serenity::prelude::*; +use std::str::FromStr; + +#[derive(Default)] +pub struct HorseHandler; + +#[async_trait] +impl LineHandler for HorseHandler { + async fn message(&self, ctx: &Context, msg: &Message) { + let reaction = match ReactionType::from_str("ðŸŽ") { + Ok(x) => x, + Err(_) => return, + }; + + if rand::random::<f64>() <= 0.001 { + let _ = msg.react(&ctx, reaction).await; + } + } +} diff --git a/src/handlers/mod.rs b/src/handlers/mod.rs index f02fdb0..419c0b7 100644 --- a/src/handlers/mod.rs +++ b/src/handlers/mod.rs @@ -1,8 +1,10 @@ +mod horse; mod joke; mod react; mod sus; mod xbasic; +use crate::handlers::horse::HorseHandler; use crate::handlers::joke::*; use crate::handlers::react::*; use crate::handlers::sus::*; @@ -49,6 +51,7 @@ impl Default for Dispatcher { Box::new(JokeHandler::default()), Box::new(ReactHandler::default()), Box::new(SusHandler::default()), + Box::new(HorseHandler::default()), ], } } diff --git a/src/handlers/react.rs b/src/handlers/react.rs index b401597..f65d38f 100644 --- a/src/handlers/react.rs +++ b/src/handlers/react.rs @@ -13,7 +13,8 @@ static EMOJI_MAP: phf::Map<&'static str, &'static str> = phf_map! { "bot" => "🤖", "mango" => "ðŸ¥", "banana" => "ðŸŒ", - "bee" => "ðŸ" + "bee" => "ðŸ", + "hose" => "ðŸŽ", }; pub struct ReactHandler; diff --git a/src/handlers/xbasic.rs b/src/handlers/xbasic.rs index 9047474..6961004 100644 --- a/src/handlers/xbasic.rs +++ b/src/handlers/xbasic.rs @@ -141,16 +141,16 @@ impl XbasicHandler { Some(x) => { if x.is_empty() { let _ = - get_user_programs!(&self, &msg.author.id).code.remove(&num); + get_user_programs!(self, &msg.author.id).code.remove(&num); return; } - get_user_programs!(&self, &msg.author.id) + get_user_programs!(self, &msg.author.id) .code .insert(num, x.to_owned()); } None => { - let _ = get_user_programs!(&self, &msg.author.id).code.remove(&num); + let _ = get_user_programs!(self, &msg.author.id).code.remove(&num); } } } @@ -245,7 +245,7 @@ impl XbasicHandler { } async fn load_published_program(&self, msg: &Message, ctx: &Context, id: i32) -> Option<()> { - let name = get_user_programs!(&self, &msg.author.id) + let name = get_user_programs!(self, &msg.author.id) .load_published_program(self.conn.lock().ok()?.borrow(), id)?; msg.channel_id @@ -270,7 +270,7 @@ impl XbasicHandler { } async fn interpreter_load(&self, name: &str, msg: &Message, ctx: &Context) { - let result = get_user_programs!(&self, &msg.author.id).load_program( + let result = get_user_programs!(self, &msg.author.id).load_program( &self.conn.lock().unwrap(), msg.author.id, name, @@ -292,7 +292,7 @@ impl XbasicHandler { } async fn interpreter_save(&self, name: &str, msg: &Message, ctx: &Context) { - let result = get_user_programs!(&self, &msg.author.id).save_program( + let result = get_user_programs!(self, &msg.author.id).save_program( &self.conn.lock().unwrap(), msg.author.id, name, -- GitLab