aboutsummaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorFuwn <[email protected]>2020-11-04 18:18:00 -0800
committerFuwn <[email protected]>2020-11-04 18:18:00 -0800
commit6f215d3065164303aae8a913a5a90dd157b7482d (patch)
tree354192c5d093166b6681d84e7a4fe52047b9eb54 /src/modules
parentfix: (urbandict to nsfw), (clapify, uwufy, and rate return if mention everyone) (diff)
downloaddep-core-next-6f215d3065164303aae8a913a5a90dd157b7482d.tar.xz
dep-core-next-6f215d3065164303aae8a913a5a90dd157b7482d.zip
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
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/commands/admins/config.rs10
-rw-r--r--src/modules/commands/general/fun.rs16
-rw-r--r--src/modules/commands/general/misc.rs79
-rw-r--r--src/modules/commands/general/nsfw.rs81
4 files changed, 101 insertions, 85 deletions
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::<String>()?;
@@ -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::<String>().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<CommandOptions> {
- 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::<ApiClient>().cloned()
- };
- if let Some(api) = api {
- let term = args.single_quoted::<String>().unwrap_or(String::new());
- let res = api.urban(term.as_str())?;
- if !res.definitions.is_empty() {
- let count = args.single::<u32>().unwrap_or(1);
- let mut tags: Vec<String> = 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::<Vec<String>>().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::<Vec<String>>()
- .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<CommandOptions> {
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<CommandOptions> {
+ 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::<ApiClient>().cloned()
+ };
+ if let Some(api) = api {
+ let term = args.single_quoted::<String>().unwrap_or(String::new());
+ let res = api.urban(term.as_str())?;
+ if !res.definitions.is_empty() {
+ let count = args.single::<u32>().unwrap_or(1);
+ let mut tags: Vec<String> = 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::<Vec<String>>().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::<Vec<String>>()
+ .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(())
+ }
+}