diff options
| author | Fuwn <[email protected]> | 2020-10-26 19:03:53 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2020-10-26 19:03:53 -0700 |
| commit | 9742614a1dc4699c1f2c69d923d402237672335d (patch) | |
| tree | a49f7d834372f37cef06b30a28ff1b40bdfaa079 /src/modules/commands/mods/hackbans.rs | |
| parent | Create README.md (diff) | |
| download | dep-core-next-9742614a1dc4699c1f2c69d923d402237672335d.tar.xz dep-core-next-9742614a1dc4699c1f2c69d923d402237672335d.zip | |
repo: push main from local to remote
Diffstat (limited to 'src/modules/commands/mods/hackbans.rs')
| -rw-r--r-- | src/modules/commands/mods/hackbans.rs | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/src/modules/commands/mods/hackbans.rs b/src/modules/commands/mods/hackbans.rs new file mode 100644 index 0000000..5cf8030 --- /dev/null +++ b/src/modules/commands/mods/hackbans.rs @@ -0,0 +1,117 @@ +use crate::core::colours; +use crate::core::consts::DB as db; +use serenity::framework::standard::{ + Args, + Command, + CommandError, + CommandOptions +}; +use serenity::model::channel::Message; +use serenity::model::id::UserId; +use serenity::model::Permissions; +use serenity::prelude::Context; +use std::sync::Arc; + +pub struct HackbanAdd; +impl Command for HackbanAdd { + fn options(&self) -> Arc<CommandOptions> { + let default = CommandOptions::default(); + let options = CommandOptions { + // desc: Some("Adds a user to the hackban list. Users on this list will be banned on joining.".to_string()), + desc: Some("This ? It'll add someone to the \"hackban\" list, basically, they'll be banned upon joining.".to_string()), + usage: Some("<user_id> [reason]".to_string()), + example: Some("217348698294714370 spamming images in general".to_string()), + required_permissions: Permissions::BAN_MEMBERS, + ..default + }; + Arc::new(options) + } + + fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { + let guild_id = message.guild_id.unwrap(); + let hackbans = db.get_hackbans(guild_id.0 as i64)?; + let user_id = UserId(args.single::<u64>()?); + match hackbans.iter().find(|e| e.id as u64 == user_id.0) { + Some(_) => { message.channel_id.say("User is already hackbanned.")?; }, + None => { + let reason = args.single::<String>().ok(); + db.new_hackban(user_id.0 as i64, guild_id.0 as i64, reason.clone())?; + message.channel_id.say(format!( + "Added {} to the hackban list{}", + user_id.0, + match reason { + Some(r) => format!(" with reason `{}`", r), + None => String::new(), + } + ))?; + } + } + Ok(()) + } +} + +pub struct HackbanRemove; +impl Command for HackbanRemove { + fn options(&self) -> Arc<CommandOptions> { + let default = CommandOptions::default(); + let options = CommandOptions { + desc: Some("Feeling forgiveful ? Take someone off the \"hackban\" list !".to_string()), + usage: Some("<user_id>".to_string()), + example: Some("217348698294714370".to_string()), + required_permissions: Permissions::BAN_MEMBERS, + ..default + }; + Arc::new(options) + } + + fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { + let guild_id = message.guild_id.unwrap(); + let hackbans = db.get_hackbans(guild_id.0 as i64)?; + let user_id = UserId(args.single::<u64>()?); + match hackbans.iter().find(|e| e.id as u64 == user_id.0) { + None => { message.channel_id.say("User isn't hackbanned.")?; }, + Some(_) => { + db.del_hackban(user_id.0 as i64, guild_id.0 as i64)?; + message.channel_id.say(format!( + "Removed {} from the hackban list", + user_id.0 + ))?; + } + } + Ok(()) + } +} + +pub struct HackbanList; +impl Command for HackbanList { + fn options(&self) -> Arc<CommandOptions> { + let default = CommandOptions::default(); + let options = CommandOptions { + // desc: Some("Lets users on the hackban list along with their reasons, if provided.".to_string()), + desc: Some("Checking up ? See who's on the \"hackban\" list.".to_string()), + required_permissions: Permissions::BAN_MEMBERS, + ..default + }; + Arc::new(options) + } + + fn execute(&self, _: &mut Context, message: &Message, _: Args) -> Result<(), CommandError> { + let guild_id = message.guild_id.unwrap(); + let hackbans = db.get_hackbans(guild_id.0 as i64)?; + message.channel_id.send_message(|m| m + .embed(|e| e + .title("Hackbans") + .description( + hackbans.iter().cloned().map(|e| format!( + "{}{}", + e.id, + format!(": `{}`", e.reason.unwrap_or(String::new())) + )) + .collect::<Vec<String>>() + .join("\n") + ) + .colour(*colours::MAIN) + ))?; + Ok(()) + } +} |