From 5a65fdf54d8f09e52d59c24cab20e969eca4edd7 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Sun, 13 Nov 2022 20:14:46 -0700 Subject: [PATCH] New memes + clippy + fmt --- src/config.rs | 7 ++++++ src/discord/celeryman.rs | 49 ++++++++++++++++++++++++++++++++++++++++ src/discord/mod.rs | 33 +++++++++++++++++++++++++++ src/error.rs | 1 + src/main.rs | 10 ++++++-- 5 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/discord/celeryman.rs diff --git a/src/config.rs b/src/config.rs index 681ecd2..a5b301a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,5 +1,6 @@ use config::{Config, File}; use serde::{Deserialize, Serialize}; +use serenity::model::prelude::UserId; use serenity::prelude::TypeMapKey; use std::path::{Path, PathBuf}; use structopt::StructOpt; @@ -43,10 +44,16 @@ impl BotConfig { } } +#[derive(Debug, Clone, Default)] +pub struct BotState { + pub accepted_nsfw: Option, +} + #[derive(Debug)] pub struct GlobalData { pub args: Args, pub cfg: BotConfig, + pub bot_state: BotState, } impl TypeMapKey for GlobalData { diff --git a/src/discord/celeryman.rs b/src/discord/celeryman.rs new file mode 100644 index 0000000..7530db4 --- /dev/null +++ b/src/discord/celeryman.rs @@ -0,0 +1,49 @@ +use crate::{command, group, GlobalData}; +use serenity::client::Context; +use serenity::framework::standard::{Args, CommandResult}; +use serenity::model::channel::Message; + +#[group] +#[commands(nudetayne, tayne, celeryman)] +pub struct CeleryMan; + +#[command] +#[aliases("NUDETAYNE")] +#[only_in(guilds)] +async fn nudetayne(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { + if msg.content.starts_with("!nudetayne") { + msg.reply(&ctx.http, "Not computing, please repeat.") + .await?; + } else if msg.content.starts_with("!NUDETAYNE") { + let mut data = ctx.data.write().await; + let global_data = data.get_mut::().unwrap(); + msg.reply(&ctx.http, "This is not suitable for work are you sure?") + .await?; + + global_data.bot_state.accepted_nsfw = Some(msg.author.id); + } + + Ok(()) +} + +#[command] +#[only_in(guilds)] +async fn tayne(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { + msg.reply( + &ctx.http, + "https://media.tenor.com/115eUl2XUaAAAAAM/flarhgunnstow-paul-rudd.gif", + ) + .await?; + Ok(()) +} + +#[command] +#[only_in(guilds)] +async fn celeryman(ctx: &Context, msg: &Message, _args: Args) -> CommandResult { + msg.reply( + &ctx.http, + "https://media.tenor.com/1iOUXZFLpBgAAAAM/dance-dancing.gif", + ) + .await?; + Ok(()) +} diff --git a/src/discord/mod.rs b/src/discord/mod.rs index b1bc9f8..1825b80 100644 --- a/src/discord/mod.rs +++ b/src/discord/mod.rs @@ -1,17 +1,50 @@ pub mod album; +pub mod celeryman; pub mod color; use crate::error::Error; use crate::{help, hook, imgur, GlobalData}; use rand::prelude::SliceRandom; +use serenity::async_trait; use serenity::client::Context; use serenity::framework::standard::{ help_commands, Args, CommandGroup, CommandResult, HelpOptions, }; use serenity::model::channel::Message; use serenity::model::id::UserId; +use serenity::model::prelude::Ready; +use serenity::prelude::EventHandler; use std::collections::HashSet; +pub struct Handler; + +#[async_trait] +impl EventHandler for Handler { + async fn message(&self, ctx: Context, new_message: Message) { + if new_message.author.bot { + return; + } + + if new_message.content.eq_ignore_ascii_case("yes") + || new_message.content.eq_ignore_ascii_case("mhmm") + { + let mut data = ctx.data.write().await; + let global_data = data.get_mut::().unwrap(); + + if let Some(u) = global_data.bot_state.accepted_nsfw { + if new_message.author.id == u { + new_message.reply(&ctx.http, "||https://cdn.discordapp.com/attachments/614891432079130625/1041545254362423368/unknown.png||").await.unwrap(); + global_data.bot_state.accepted_nsfw = None; + } + } + } + } + + async fn ready(&self, _: Context, ready: Ready) { + println!("Connected as {}", ready.user.name); + } +} + #[hook] pub async fn after( _ctx: &Context, diff --git a/src/error.rs b/src/error.rs index 35b4937..b03b54d 100644 --- a/src/error.rs +++ b/src/error.rs @@ -2,6 +2,7 @@ use crate::imgur::ImgurError; use std::fmt::{Display, Formatter}; #[derive(Debug)] +#[allow(clippy::enum_variant_names)] pub enum Error { ConfigError(config::ConfigError), ImgurError(ImgurError), diff --git a/src/main.rs b/src/main.rs index 0804993..c876092 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,7 +3,7 @@ mod discord; mod error; mod imgur; -use crate::config::{Args, BotConfig, GlobalData}; +use crate::config::{Args, BotConfig, BotState, GlobalData}; use crate::discord::unrecognised_command_hook; use serenity::framework::standard::macros::{command, group, help, hook}; use serenity::framework::standard::StandardFramework; @@ -22,12 +22,17 @@ async fn main() { } }; - let global_data = GlobalData { args, cfg }; + let global_data = GlobalData { + args, + cfg, + bot_state: BotState::default(), + }; let framework = StandardFramework::new() .configure(|c| c.with_whitespace(true).prefix("!").ignore_bots(true)) .group(&discord::color::COLOR_GROUP) .group(&discord::album::ALBUM_GROUP) + .group(&discord::celeryman::CELERYMAN_GROUP) .unrecognised_command(unrecognised_command_hook) .help(&discord::MY_HELP) .after(discord::after); @@ -36,6 +41,7 @@ async fn main() { let mut client = Client::builder(&global_data.cfg.bot_token, intents) .framework(framework) .type_map_insert::(global_data) + .event_handler(discord::Handler) .await .expect("Unable to create client.");