diff options
| author | Fuwn <[email protected]> | 2020-11-04 20:42:40 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2020-11-04 20:42:40 -0800 |
| commit | ed4bf9cb63576c89cad9179d9de3e0e2dd67a8ea (patch) | |
| tree | 9883d6cfbe7f9f0e5708e0b0cfc3b9fcac096549 | |
| parent | fix: parse for mentions not just @everyone (diff) | |
| download | dep-core-next-ed4bf9cb63576c89cad9179d9de3e0e2dd67a8ea.tar.xz dep-core-next-ed4bf9cb63576c89cad9179d9de3e0e2dd67a8ea.zip | |
fix: mention handling where it should be handled
| -rw-r--r-- | src/core/consts.rs | 6 | ||||
| -rw-r--r-- | src/core/utils.rs | 10 | ||||
| -rw-r--r-- | src/modules/commands/admins/config.rs | 18 | ||||
| -rw-r--r-- | src/modules/commands/general/fun.rs | 26 |
4 files changed, 38 insertions, 22 deletions
diff --git a/src/core/consts.rs b/src/core/consts.rs index df214c5..35da1af 100644 --- a/src/core/consts.rs +++ b/src/core/consts.rs @@ -1,5 +1,5 @@ use crate::db::Database; -use serenity::model::id::{GuildId, ChannelId, RoleId}; +use serenity::model::id::{GuildId, ChannelId, RoleId, UserId}; lazy_static!{ pub static ref DB: Database = Database::connect(); @@ -31,6 +31,8 @@ pub const GUILD_LOG: ChannelId = ChannelId(770117277416554526); // 40611549 pub const NOW_LIVE: RoleId = RoleId(370395740406546432); pub const SUPPORT_SERVER: GuildId = GuildId(704032355987488791); // 373561057639268352 pub const TRANSCEND: GuildId = GuildId(348660188951216129); +pub const BOT_ID: UserId = UserId(712088369206919269); +pub const BOT_BETA_ID: UserId = UserId(772434317841530882); pub const SUPPORT_SERV_INVITE: &str = "https://discord.gg/ASrM7p9"; pub const BOT_INVITE: &str = "https://discordapp.com/oauth2/authorize/?permissions=335670488&scope=bot&client_id=712088369206919269"; @@ -54,3 +56,5 @@ pub const GUILDID_FAIL: &str = "Failed to get GuildId"; pub const MEMBER_FAIL: &str = "Failed to get member"; pub const TC_FAIL: &str = "Failed to get TimerClient"; pub const USER_FAIL: &str = "Failed to get user"; + +pub const MENTION_FAIL: &str = "Sorry, but it seems to me that you are mentioning someone where you aren't allowed to."; diff --git a/src/core/utils.rs b/src/core/utils.rs index 2fb690b..2a79366 100644 --- a/src/core/utils.rs +++ b/src/core/utils.rs @@ -7,6 +7,7 @@ use serenity::model::guild::{Guild, Role, Member}; use serenity::model::id::*; use serenity::model::misc::Mentionable; use serenity::prelude::RwLock; +use serenity::framework::standard::CommandError; use std::collections::HashMap; use std::str::FromStr; use std::sync::Arc; @@ -158,6 +159,15 @@ pub fn check_rank<T: AsRef<Vec<RoleId>>>(roles: Vec<i64>, member: T) -> bool { false } +pub fn check_mentions(message: &Message) -> bool { // Result<(), CommandError> + if message.mentions.len() >= 1 { + if message.mentions.len() == 1 { + if !message.mentions_user_id(BOT_ID) { return true } + } else { return true } + } + false +} + /// Parses a string for flags preceded by `/` /// The HashMap returned correlates to `/{key} {value}` where value may be an empty string. /// Additionally, the map will contain the key "rest" which contains anything in the string prior diff --git a/src/modules/commands/admins/config.rs b/src/modules/commands/admins/config.rs index eedd087..c3a0252 100644 --- a/src/modules/commands/admins/config.rs +++ b/src/modules/commands/admins/config.rs @@ -80,9 +80,9 @@ impl Command for ConfigPrefix { } fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { - if !message.mentions.is_empty() { - message.channel_id.say("Sorry, but the prefix can't mention people.")?; - return Ok(()); + if check_mentions(message) { + message.channel_id.say(MENTION_FAIL)?; + return Ok(()) } if let Some(guild_id) = message.guild_id { @@ -91,10 +91,10 @@ impl Command for ConfigPrefix { guild_data.prefix = pre; match db.update_guild(guild_id.0 as i64, guild_data) { Ok(guild) => { - message.channel_id.say(format!("Set prefix to {}", guild.prefix))?; + message.channel_id.say(format!("Set guild prefix to `{}`.", guild.prefix))?; }, Err(_) => { - message.channel_id.say("Failed to change prefix")?; + message.channel_id.say("Unexpected error while changing prefix.")?; }, } } else { @@ -249,7 +249,7 @@ impl Command for ConfigMod { fn options(&self) -> Arc<CommandOptions> { let default = CommandOptions::default(); let options = CommandOptions { - desc: Some("Welcome to moderation!".to_string()), + desc: Some("Configure the moderation log, superstitious much.".to_string()), usage: Some("<add|remove> <role_resolvable>".to_string()), example: Some("add staff".to_string()), min_args: Some(2), @@ -459,9 +459,9 @@ impl Command for ConfigWelcome { } fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { - if !message.mentions.is_empty() { - message.channel_id.say("Try again, my welcome greeting can't be initialized when it mentions someone!.")?; - return Ok(()); + if check_mentions(message) { + message.channel_id.say(MENTION_FAIL)?; + return Ok(()) } if let Some(guild_id) = message.guild_id { diff --git a/src/modules/commands/general/fun.rs b/src/modules/commands/general/fun.rs index 31deeeb..eb3c1e1 100644 --- a/src/modules/commands/general/fun.rs +++ b/src/modules/commands/general/fun.rs @@ -12,6 +12,7 @@ use serenity::framework::standard::{ use serenity::model::channel::Message; use serenity::prelude::Context; use std::sync::Arc; +use crate::core::utils::check_mentions; lazy_static! { static ref DICE_MATCH: Regex = Regex::new(r"(?P<count>\d+)d?(?P<sides>\d*)").expect("Failed to create Regex"); @@ -29,9 +30,9 @@ impl Command for Clapify { } fn execute(&self, _: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { - if !message.mentions.is_empty() { - message.channel_id.say("Sorry, but I can only clapify non-human things!")?; - return Ok(()); + if check_mentions(message) { + message.channel_id.say(MENTION_FAIL)?; + return Ok(()) } let to_say = args; @@ -190,10 +191,11 @@ impl Command for Opinion { } fn execute(&self, _ctx: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { - if message.mentions.len() > 1 { - message.channel_id.say("I can't give my opinion on everyone all at once!")?; - return Ok(()); + if check_mentions(message) { + message.channel_id.say(MENTION_FAIL)?; + return Ok(()) } + let random = thread_rng().gen_bool(5.4); // TODO: Make this an embed eventually. if random { @@ -222,9 +224,9 @@ impl Command for Rate { } fn execute(&self, _ctx: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { - if message.mentions.len() > 1 { - message.channel_id.say("I can't rate everyone at once!")?; - return Ok(()); + if check_mentions(message) { + message.channel_id.say(MENTION_FAIL)?; + return Ok(()) } let random = thread_rng().gen_range(1, 10); @@ -273,9 +275,9 @@ impl Command for Uwufy { } fn execute(&self, _: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { - if !message.mentions.is_empty() { - message.channel_id.say("Try again, but next time, don't tag anyone please.")?; - return Ok(()); + if check_mentions(message) { + message.channel_id.say(MENTION_FAIL)?; + return Ok(()) } let to_say = args; |