diff --git a/Cargo.toml b/Cargo.toml index 3eeabc1..14abdcb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,11 @@ features = [ [dependencies.serenity] version = "0.12.4" -features = ["interactions_endpoint"] +features = [ + "interactions_endpoint", + "utils", + "collector" +] [build-dependencies] serde = { version = "1.0.217", features = ["derive"] } diff --git a/src/ayy.rs b/src/ayy.rs new file mode 100644 index 0000000..832ef80 --- /dev/null +++ b/src/ayy.rs @@ -0,0 +1,65 @@ +use once_cell::sync::Lazy; +use regex::Regex; +use serenity::all::{Context, EventHandler, Message}; +use serenity::async_trait; + +static AY_REGEX: Lazy = + Lazy::new(|| Regex::new("(^|\\s)[Aa][Yy]+($|\\s)").expect("invalid regex")); +pub struct AyyHandler; + +#[async_trait] +impl EventHandler for AyyHandler { + async fn message(&self, ctx: Context, msg: Message) { + if msg.author.bot{ + return; + } + + if AY_REGEX.is_match(&msg.content){ + let mut output = "".to_owned(); + let mut lastpos = 0; + for ay in AY_REGEX.find_iter(&msg.content){ + output += &msg.content[lastpos..ay.start()]; + + lastpos = ay.end(); + + let mut str = ay.as_str(); + + if str.starts_with(' '){ + str = &str[1..]; + output.push(' '); + } + + let mut chars = str.chars(); + + let Some(first_char) = chars.next() else{ + return + }; + + if first_char.is_lowercase(){ + output.push_str("lma") + } else { + output.push_str("LMA") + } + + for char in chars{ + if char == ' '{ + output.push(' '); + break; + } + + if char.is_lowercase(){ + output.push('o'); + } else { + output.push('O'); + } + + + } + } + + output += &msg.content[lastpos..]; + + msg.reply(&ctx.http, output).await.ok(); + } + } +} \ No newline at end of file diff --git a/src/cheeseburger.rs b/src/cheeseburger.rs new file mode 100644 index 0000000..cbef327 --- /dev/null +++ b/src/cheeseburger.rs @@ -0,0 +1,22 @@ +use once_cell::sync::Lazy; +use regex::Regex; +use serenity::all::{Context, CreateCommand, EventHandler, Message}; +use serenity::async_trait; +use crate::error_codes::ErrorCodeHandler; + +static CHEESEBURGER_REGEX: Lazy = + Lazy::new(|| Regex::new("[Cc]heeseburger(s)?").expect("invalid regex")); +pub struct CheeseburgerHandler; + +#[async_trait] +impl EventHandler for CheeseburgerHandler { + async fn message(&self, ctx: Context, msg: Message) { + if msg.author.bot{ + return; + } + + if CHEESEBURGER_REGEX.is_match(&msg.content){ + msg.reply(&ctx.http, "currently scratching the FUCK out of my bum bum idgaf").await.ok(); + } + } +} \ No newline at end of file diff --git a/src/error_codes.rs b/src/error_codes.rs index d722712..dad306b 100644 --- a/src/error_codes.rs +++ b/src/error_codes.rs @@ -55,11 +55,8 @@ impl Default for ErrorInfo{ static ERROR_CODE_REGEX: Lazy = Lazy::new(|| Regex::new("\\d\\d\\d-\\d\\d\\d\\d").expect("invalid regex")); -static CHEESEBURGER_REGEX: Lazy = - Lazy::new(|| Regex::new("[Cc]heeseburger(s)?").expect("invalid regex")); -static AY_REGEX: Lazy = - Lazy::new(|| Regex::new("(^|\\s)[Aa][Yy]+($|\\s)").expect("invalid regex")); + pub struct ErrorCodeHandler; @@ -155,58 +152,6 @@ impl EventHandler for ErrorCodeHandler { start_timed_explanation_collapse(msg, ctx.http.clone(), str_code); } - - if CHEESEBURGER_REGEX.is_match(&msg.content){ - msg.reply(&ctx.http, "currently scratching the FUCK out of my bum bum idgaf").await.ok(); - } - - if AY_REGEX.is_match(&msg.content){ - let mut output = "".to_owned(); - let mut lastpos = 0; - for ay in AY_REGEX.find_iter(&msg.content){ - output += &msg.content[lastpos..ay.start()]; - - lastpos = ay.end(); - - let mut str = ay.as_str(); - - if str.starts_with(' '){ - str = &str[1..]; - output.push(' '); - } - - let mut chars = str.chars(); - - let Some(first_char) = chars.next() else{ - return - }; - - if first_char.is_lowercase(){ - output.push_str("lma") - } else { - output.push_str("LMA") - } - - for char in chars{ - if char == ' '{ - output.push(' '); - break; - } - - if char.is_lowercase(){ - output.push('o'); - } else { - output.push('O'); - } - - - } - } - - output += &msg.content[lastpos..]; - - msg.reply(&ctx.http, output).await.ok(); - } } async fn interaction_create(&self, ctx: Context, interaction: Interaction) { diff --git a/src/main.rs b/src/main.rs index 59b867b..0c9ef27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,7 @@ mod error_codes; +mod cheeseburger; +mod ayy; +mod miiverse_mod_application; use std::env; use once_cell::sync::Lazy; @@ -21,6 +24,9 @@ async fn main() { let mut client = Client::builder(&token, intents) .event_handler(error_codes::ErrorCodeHandler) + .event_handler(ayy::AyyHandler) + .event_handler(cheeseburger::CheeseburgerHandler) + .event_handler(miiverse_mod_application::MiiverseModApplicationHandler::default()) .await.expect("unable to create client"); client.start().await.expect("error running bot"); diff --git a/src/miiverse_mod_application.rs b/src/miiverse_mod_application.rs new file mode 100644 index 0000000..ac6a6f0 --- /dev/null +++ b/src/miiverse_mod_application.rs @@ -0,0 +1,56 @@ + +use crate::cheeseburger::CheeseburgerHandler; +use serenity::all::{ActivityData, ActivityType, Command, CommandId, Context, CreateCommand, CreateInputText, CreateQuickModal, EventHandler, Guild, GuildId, InputTextStyle, Interaction, Message, Ready}; +use serenity::async_trait; +use tokio::sync::OnceCell; + +#[derive(Default)] +pub struct MiiverseModApplicationHandler{ + command_id: OnceCell +} + +#[async_trait] +impl EventHandler for MiiverseModApplicationHandler { + async fn ready(&self, ctx: Context, data_about_bot: Ready) { + let command = CreateCommand::new("miivserse-mod-application") + .description("Apply for miiverse moderator"); + + let cmd = Command::create_global_command(&ctx.http, command).await.expect("unable to register command"); + + self.command_id.set(cmd.id).ok(); + } + + async fn interaction_create(&self, ctx: Context, interaction: Interaction) { + let Interaction::Command(cmd) = interaction else { + return; + }; + + let Some(id) = self.command_id.get() else { + return; + }; + + if cmd.data.id != *id{ + return; + } + + let main_field = CreateInputText::new( + InputTextStyle::Paragraph, + "Text", + "MAIN_CONTENT" + ); + + let modal = CreateQuickModal::new("Miiverse Moderator Application Form") + .field(main_field); + + let response = match cmd.quick_modal(&ctx, modal).await{ + Ok(v) => v, + Err(e) => { eprintln!("{}", e); return } + }; + + let Some(response) = response else { + return + }; + + + } +}