From 6f215d3065164303aae8a913a5a90dd157b7482d Mon Sep 17 00:00:00 2001 From: Fuwn Date: Wed, 4 Nov 2020 18:18:00 -0800 Subject: feat, fix, chore, revert (desc) feat: - not working: presence now checks if environment variable is present, if not, set to `0.1.0`. - `@everyone` abuse handling - urban dictionary to nsfw fix: - rename cc environment variables file chore: - bump version from `0.1.1` to `0.1.2` revert: - display presence now, but static --- Cargo.toml | 2 +- Cross-Compilation_Enviorment_Variables.txt | 5 -- Cross-Compilation_Environment_Variables.txt | 5 ++ src/core/handler.rs | 5 +- src/modules/commands/admins/config.rs | 10 ++++ src/modules/commands/general/fun.rs | 16 +++--- src/modules/commands/general/misc.rs | 79 ---------------------------- src/modules/commands/general/nsfw.rs | 81 +++++++++++++++++++++++++++++ 8 files changed, 110 insertions(+), 93 deletions(-) delete mode 100644 Cross-Compilation_Enviorment_Variables.txt create mode 100644 Cross-Compilation_Environment_Variables.txt diff --git a/Cargo.toml b/Cargo.toml index 656956f..1cc65c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "wisp" -version = "0.1.1" +version = "0.1.2" authors = ["Fuwn "] edition = "2018" description = "Wisp, your all-in-one Discord companion." diff --git a/Cross-Compilation_Enviorment_Variables.txt b/Cross-Compilation_Enviorment_Variables.txt deleted file mode 100644 index 6a97000..0000000 --- a/Cross-Compilation_Enviorment_Variables.txt +++ /dev/null @@ -1,5 +0,0 @@ -CC=E:/cygwin64/usr/local/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-gcc.exe -CFLAGS=E:\msys64\usr\include; -OPENSSL_DIR=E:\msys64\mingw64 -OPENSSL_LIB_DIR=E:\msys64\mingw64\lib -PQ_LIB_DIR=E:\Program Files\PostgreSQL\13\lib diff --git a/Cross-Compilation_Environment_Variables.txt b/Cross-Compilation_Environment_Variables.txt new file mode 100644 index 0000000..6a97000 --- /dev/null +++ b/Cross-Compilation_Environment_Variables.txt @@ -0,0 +1,5 @@ +CC=E:/cygwin64/usr/local/x86_64-unknown-linux-gnu/bin/x86_64-unknown-linux-gnu-gcc.exe +CFLAGS=E:\msys64\usr\include; +OPENSSL_DIR=E:\msys64\mingw64 +OPENSSL_LIB_DIR=E:\msys64\mingw64\lib +PQ_LIB_DIR=E:\Program Files\PostgreSQL\13\lib diff --git a/src/core/handler.rs b/src/core/handler.rs index 2074567..60258db 100644 --- a/src/core/handler.rs +++ b/src/core/handler.rs @@ -106,8 +106,9 @@ impl EventHandler for Handler { // let guild_count = guilds.len(); // ctx.set_game(Game::listening(&format!("{} guilds | m!help", guild_count))); - // ctx.set_game(Game::playing("w.help | v0.1.0")); - ctx.set_game(Game::playing(&*format!("w.help | v{}", env!("CARGO_PKG_VERSION")))); + ctx.set_game(Game::playing("w.help | v0.1.2")); + // ctx.set_game(Game::playing(&*format!("w.help | v{}", + // option_env!("CARGO_PKG_VERSION").unwrap_or("0.1.0")))); info!("Caching complete."); } diff --git a/src/modules/commands/admins/config.rs b/src/modules/commands/admins/config.rs index e0533ab..926da7b 100644 --- a/src/modules/commands/admins/config.rs +++ b/src/modules/commands/admins/config.rs @@ -80,6 +80,11 @@ impl Command for ConfigPrefix { } fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { + if message.content.to_lowercase().contains("@everyone") { + message.channel_id.say("Sorry, but the prefix can't mention everyone.")?; + return Ok(()); + } + if let Some(guild_id) = message.guild_id { let mut guild_data = db.get_guild(guild_id.0 as i64)?; let pre = args.single::()?; @@ -454,6 +459,11 @@ impl Command for ConfigWelcome { } fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { + if message.content.to_lowercase().contains("@everyone") { + message.channel_id.say("Try again, my welcome greeting can't mention everyone.")?; + return Ok(()); + } + if let Some(guild_id) = message.guild_id { let mut guild_data = db.get_guild(guild_id.0 as i64)?; let op = args.single::().unwrap_or(String::new()); diff --git a/src/modules/commands/general/fun.rs b/src/modules/commands/general/fun.rs index 86be4fe..55880b3 100644 --- a/src/modules/commands/general/fun.rs +++ b/src/modules/commands/general/fun.rs @@ -29,8 +29,8 @@ impl Command for Clapify { } fn execute(&self, _: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { - if message.mention_everyone { - message.channel_id.say("Hmm, that message mentions everyone, try again, but this time, be nice.")?; + if message.content.to_lowercase().contains("@everyone") { + message.channel_id.say("I refuse to clap everyone!")?; return Ok(()); } @@ -190,6 +190,10 @@ impl Command for Opinion { } fn execute(&self, _ctx: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { + if message.content.to_lowercase().contains("@everyone") { + message.channel_id.say("I can't give my opinion on everyone all at once!")?; + return Ok(()); + } let random = thread_rng().gen_bool(5.4); // TODO: Make this an embed eventually. if random { @@ -218,8 +222,8 @@ impl Command for Rate { } fn execute(&self, _ctx: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { - if message.mention_everyone { - message.channel_id.say("Hmm, that message mentions everyone, try again, but this time, be nice.")?; + if message.content.to_lowercase().contains("@everyone") { + message.channel_id.say("I can't rate everyone at once!")?; return Ok(()); } @@ -269,8 +273,8 @@ impl Command for Uwufy { } fn execute(&self, _: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { - if message.mention_everyone { - message.channel_id.say("Hmm, that message mentions everyone, try again, but this time, be nice.")?; + if message.content.to_lowercase().contains("@everyone") { + message.channel_id.say("I seriously doubt everyone will be interested in \"uwufying\" something...")?; return Ok(()); } diff --git a/src/modules/commands/general/misc.rs b/src/modules/commands/general/misc.rs index f2b3cdd..9e225b0 100644 --- a/src/modules/commands/general/misc.rs +++ b/src/modules/commands/general/misc.rs @@ -194,85 +194,6 @@ impl Command for Manga { } } -pub struct UrbanDictionary; // Urban -impl Command for UrbanDictionary { - fn options(&self) -> Arc { - let default = CommandOptions::default(); - let options = CommandOptions { - desc: Some("Hmm, be responsible.".to_string()), - usage: Some(r#"<"term"> [count]"#.to_string()), - example: Some(r#""boku no pico" 5"#.to_string()), - aliases: vec!["urban", "ud", "urbandict"].iter().map(|e| e.to_string()).collect(), - ..default - }; - Arc::new(options) - } - - fn execute(&self, ctx: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { - let api = { - let data = ctx.data.lock(); - data.get::().cloned() - }; - if let Some(api) = api { - let term = args.single_quoted::().unwrap_or(String::new()); - let res = api.urban(term.as_str())?; - if !res.definitions.is_empty() { - let count = args.single::().unwrap_or(1); - let mut tags: Vec = Vec::new(); - if let Some(res_tags) = &res.tags { - tags = res_tags.clone(); - tags.sort(); - tags.dedup(); - } - if count == 1 { - let item = &res.definitions[0]; - let tags_list = { - let list = tags.iter().map(|t| "#".to_string()+t).collect::>().join(", "); - if !list.is_empty() { - list - } else { - "None".to_string() - } - }; - let definition = { - let mut i = item.definition.clone(); - if i.len() > 1000 { - i.truncate(997); - i += "..."; - } - i - }; - message.channel_id.send_message(|m| m - .embed(|e| e - .colour(*colours::MAIN) - .field(format!(r#"Definition of "{}" by {}"#, item.word, item.author), &item.permalink, false) - .field("Thumbs Up", &item.thumbs_up, true) - .field("Thumbs Down", &item.thumbs_down, true) - .field("Definition", definition, false) - .field("Example", &item.example, false) - .field("Tags", tags_list, false) - ))?; - } else { - let mut list = res.definitions; - list.truncate(count as usize); - let list = list.iter() - .map(|c| format!(r#""{}" by {}: {}"#, c.word, c.author, c.permalink)) - .collect::>() - .join("\n"); - message.channel_id.send_message(|m| m - .embed(|e| e - .title(format!("Top {} results for {}", count, term)) - .description(list) - .colour(*colours::MAIN) - ))?; - } - } - } else { failed!(API_FAIL); } - - Ok(()) - } -} - // pub struct Waifu; // impl Command for Waifu { // fn options(&self) -> Arc { diff --git a/src/modules/commands/general/nsfw.rs b/src/modules/commands/general/nsfw.rs index 1a699d0..13506c0 100644 --- a/src/modules/commands/general/nsfw.rs +++ b/src/modules/commands/general/nsfw.rs @@ -1,4 +1,5 @@ use crate::core::model::ApiClient; +use crate::core::colours; use crate::core::consts::*; use serenity::framework::standard::{ Args, @@ -48,3 +49,83 @@ impl Command for Furry { Ok(()) } } + +pub struct UrbanDictionary; // Urban +impl Command for UrbanDictionary { + fn options(&self) -> Arc { + let default = CommandOptions::default(); + let options = CommandOptions { + desc: Some("Hmm, be responsible.".to_string()), + usage: Some(r#"<"term"> [count]"#.to_string()), + example: Some(r#""boku no pico" 5"#.to_string()), + aliases: vec!["urban", "ud", "urbandict"].iter().map(|e| e.to_string()).collect(), + owner_privileges: false, + ..default + }; + Arc::new(options) + } + + fn execute(&self, ctx: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { + let api = { + let data = ctx.data.lock(); + data.get::().cloned() + }; + if let Some(api) = api { + let term = args.single_quoted::().unwrap_or(String::new()); + let res = api.urban(term.as_str())?; + if !res.definitions.is_empty() { + let count = args.single::().unwrap_or(1); + let mut tags: Vec = Vec::new(); + if let Some(res_tags) = &res.tags { + tags = res_tags.clone(); + tags.sort(); + tags.dedup(); + } + if count == 1 { + let item = &res.definitions[0]; + let tags_list = { + let list = tags.iter().map(|t| "#".to_string()+t).collect::>().join(", "); + if !list.is_empty() { + list + } else { + "None".to_string() + } + }; + let definition = { + let mut i = item.definition.clone(); + if i.len() > 1000 { + i.truncate(997); + i += "..."; + } + i + }; + message.channel_id.send_message(|m| m + .embed(|e| e + .colour(*colours::MAIN) + .field(format!(r#"Definition of "{}" by {}"#, item.word, item.author), &item.permalink, false) + .field("Thumbs Up", &item.thumbs_up, true) + .field("Thumbs Down", &item.thumbs_down, true) + .field("Definition", definition, false) + .field("Example", &item.example, false) + .field("Tags", tags_list, false) + ))?; + } else { + let mut list = res.definitions; + list.truncate(count as usize); + let list = list.iter() + .map(|c| format!(r#""{}" by {}: {}"#, c.word, c.author, c.permalink)) + .collect::>() + .join("\n"); + message.channel_id.send_message(|m| m + .embed(|e| e + .title(format!("Top {} results for {}", count, term)) + .description(list) + .colour(*colours::MAIN) + ))?; + } + } + } else { failed!(API_FAIL); } + + Ok(()) + } +} -- cgit v1.2.3