diff options
| author | seth <[email protected]> | 2023-07-10 00:18:36 -0400 |
|---|---|---|
| committer | seth <[email protected]> | 2023-11-16 00:35:07 +0000 |
| commit | a4a9353e1c8f902b7d7b3cf74e3e5b129c214330 (patch) | |
| tree | b58da1d30af52e97c0251e0d6882cd0ccdfeb20a /src/handler | |
| parent | 5e9ec7f008e01d25c0b7f782c5ae043bc9ca0933 (diff) | |
start using poise
Diffstat (limited to 'src/handler')
| -rw-r--r-- | src/handler/events.rs | 24 | ||||
| -rw-r--r-- | src/handler/mod.rs | 34 |
2 files changed, 58 insertions, 0 deletions
diff --git a/src/handler/events.rs b/src/handler/events.rs new file mode 100644 index 0000000..d971b25 --- /dev/null +++ b/src/handler/events.rs @@ -0,0 +1,24 @@ +use crate::handler::Handler; +use log::*; +use poise::async_trait; +use poise::serenity_prelude::{ChannelPinsUpdateEvent, Context, EventHandler, Message}; + +#[async_trait] +impl EventHandler for Handler { + async fn message(&self, ctx: Context, msg: Message) { + if self.should_echo(&msg) { + let send = msg.reply(&ctx, &msg.content); + if let Err(why) = send.await { + error!("error when replying to {:?}: {:?}", msg.content, why); + } + } + } + + async fn channel_pins_update(&self, ctx: Context, pin: ChannelPinsUpdateEvent) { + let Some(pin_board) = &self.data.pin_board else { + return; + }; + + pin_board.handle_pin(&ctx, &pin).await; + } +} diff --git a/src/handler/mod.rs b/src/handler/mod.rs new file mode 100644 index 0000000..7f7c881 --- /dev/null +++ b/src/handler/mod.rs @@ -0,0 +1,34 @@ +use crate::utils; +use crate::{consts, Data}; +use log::*; + +use poise::serenity_prelude::Message; + +mod events; + +pub struct Handler { + data: Data, +} + +impl Handler { + pub fn new(data: Data) -> Self { + Self { data } + } + + fn should_echo(&self, msg: &Message) -> bool { + let gid = msg.guild_id.unwrap_or_default(); + if msg.author.id == self.data.bot || !utils::is_guild_allowed(gid) { + info!("not running copypasta command in {gid}"); + return false; + } + + let content = &msg.content; + + content == "🗿" + || consts::TEAMOJIS.contains(&content.as_str()) + || content.to_ascii_lowercase() == "moyai" + || content + .to_ascii_lowercase() + .contains("twitter's recommendation algorithm") + } +} |
