use crate::core::colours; use crate::core::consts::*; use crate::core::consts::DB as db; use crate::core::utils::*; use serenity::framework::standard::{ Args, Command, CommandError, CommandOptions }; use serenity::model::channel::Message; use serenity::model::Permissions; use serenity::prelude::Context; use std::sync::Arc; pub struct IgnoreAdd; impl Command for IgnoreAdd { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Want me to ignore a channel? Don't worry, I ain't seen a thing.".to_string()), usage: Some("".to_string()), example: Some("#general".to_string()), min_args: Some(1), max_args: Some(1), required_permissions: Permissions::MANAGE_GUILD, ..default }; Arc::new(options) } fn execute(&self, _: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { if let Some(guild_id) = message.guild_id { let mut guild_data = db.get_guild(guild_id.0 as i64)?; if let Some((channel_id, channel)) = parse_channel(args.full().to_string(), guild_id) { if !guild_data.ignored_channels.contains(&(channel_id.0 as i64)) { guild_data.ignored_channels.push(channel_id.0 as i64); db.update_guild(guild_id.0 as i64, guild_data)?; message.channel_id.say(format!( "I will now ignore messages in {}", channel.name ))?; } else { message.channel_id.say("That channel is already being ignored.")?; } } else { message.channel_id.say("I couldn't find that channel.")?; } } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct IgnoreRemove; impl Command for IgnoreRemove { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Finally, I can see.".to_string()), aliases: vec!["rm", "delete", "del"].iter().map(|e| e.to_string()).collect(), usage: Some("".to_string()), example: Some("#general".to_string()), min_args: Some(1), max_args: Some(1), required_permissions: Permissions::MANAGE_GUILD, ..default }; Arc::new(options) } fn execute(&self, _: &mut Context, message: &Message, args: Args) -> Result<(), CommandError> { if let Some(guild_id) = message.guild_id { let mut guild_data = db.get_guild(guild_id.0 as i64)?; if let Some((channel_id, channel)) = parse_channel(args.full().to_string(), guild_id) { if guild_data.ignored_channels.contains(&(channel_id.0 as i64)) { guild_data.ignored_channels.retain(|e| *e != channel_id.0 as i64); db.update_guild(guild_id.0 as i64, guild_data)?; message.channel_id.say(format!( "I will no longer ignore messages in {}", channel.name ))?; } else { message.channel_id.say("That channel isn't being ignored.")?; } } else { message.channel_id.say("I couldn't find that channel.")?; } } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct IgnoreList; impl Command for IgnoreList { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("You want ME to tell YOU want channels I'm ignoring?.".to_string()), aliases: vec!["ls"].iter().map(|e| e.to_string()).collect(), required_permissions: Permissions::MANAGE_GUILD, max_args: Some(0), ..default }; Arc::new(options) } fn execute(&self, _: &mut Context, message: &Message, _: Args) -> Result<(), CommandError> { if let Some(guild_id) = message.guild_id { let guild_data = db.get_guild(guild_id.0 as i64)?; if !guild_data.ignored_channels.is_empty() { let channel_out = guild_data.ignored_channels.clone() .iter() .map(|c| format!("<#{}>", c)) .collect::>() .join("\n"); message.channel_id.send_message(|m| m .embed(|e| e .title("Ignored Channels") .description(channel_out) .colour(*colours::MAIN) ))?; } else { message.channel_id.say("I'm not ignoring any channels.")?; } } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct IgnoreLevel; impl Command for IgnoreLevel { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Change which ranks can bypass ignored channels, epic.\n\nValues:\n`4` = Bot Owner, `3` = Guild Owner, `2` = Guild Admin, `1` = Guild Mod, `0` = Everyone.".to_string()), usage: Some("<0..4>".to_string()), example: Some("2".to_string()), min_args: Some(1), max_args: Some(1), required_permissions: Permissions::MANAGE_GUILD, ..default }; Arc::new(options) } fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { if let Some(guild_id) = message.guild_id { let mut guild_data = db.get_guild(guild_id.0 as i64)?; match args.single::() { Ok(level) => { guild_data.ignore_level = level; db.update_guild(guild_id.0 as i64, guild_data)?; message.channel_id.say(format!("Successfully set ignore level to {}", level))?; }, Err(_) => { message.channel_id.say("Please enter an integer between 0 and 4.")?; }, } } else { failed!(GUILDID_FAIL); } Ok(()) } }