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 ConfigRaw; impl Command for ConfigRaw { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Oh, you want it, raw...".to_string()), required_permissions: Permissions::MANAGE_GUILD, ..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)?; message.channel_id.say(format!("```{:?}```", guild_data))?; } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct ConfigList; impl Command for ConfigList { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Yeah, sure, here's my config.".to_string()), required_permissions: Permissions::MANAGE_GUILD, ..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)?; message.channel_id.send_message(|m| m .embed(|e| e .colour(*colours::MAIN) .description(format!("{}", guild_data)) ))?; } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct ConfigPrefix; impl Command for ConfigPrefix { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Change it, go ahead.".to_string()), usage: Some("".to_string()), example: Some("!!".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 check_mentions(message) { message.channel_id.say(MENTION_FAIL)?; 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::()?; guild_data.prefix = pre; match db.update_guild(guild_id.0 as i64, guild_data) { Ok(guild) => { message.channel_id.say(format!("Set guild prefix to `{}`.", guild.prefix))?; }, Err(_) => { message.channel_id.say("Unexpected error while changing prefix.")?; }, } } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct ConfigAutorole; impl Command for ConfigAutorole { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Want to mess with my auto-role settings? (A role must be provided for `add` or `remove`.)".to_string()), usage: Some(" ".to_string()), example: Some("add member".to_string()), min_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)?; let op = args.single::().unwrap_or(String::new()); let mut val = args.rest().to_string(); match op.to_lowercase().as_str() { "add" => { match parse_role(val.to_string(), guild_id) { Some((role_id, role)) => { guild_data.autoroles.push(role_id.0 as i64); val = format!("{} ({})", role.name, role_id.0); }, None => { message.channel_id.say("I couldn't find that role.")?; return Ok(()) }, } }, "remove" => { match parse_role(val.to_string(), guild_id) { Some((role_id, role)) => { guild_data.autoroles.retain(|e| *e != role_id.0 as i64); val = format!("{} ({})", role.name, role_id.0); }, None => { message.channel_id.say("I couldn't find that role.")?; return Ok(()) }, } }, "enable" => { guild_data.autorole = true; }, "disable" => { guild_data.autorole = false; }, _ => { message.channel_id.say("I didn't understand that option. Valid options are: `add`, `remove`, `enable`, `disable`. For more information see `help config autorole`")?; return Ok(()) }, } let guild = db.update_guild(guild_id.0 as i64, guild_data)?; message.channel_id.send_message(|m| m .embed(|e| e .title("Config Autorole Summary") .colour(*colours::MAIN) .description(format!("**Operation:** {}\n**Value:** {}", op, if val.is_empty() { guild.autorole.to_string() } else { val } , )) ))?; } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct ConfigAdmin; impl Command for ConfigAdmin { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Who do you want me to consider an admin?".to_string()), usage: Some(" ".to_string()), example: Some("add admin".to_string()), min_args: Some(2), 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)?; let op = args.single::().unwrap_or(String::new()); let mut val = args.rest().to_string(); match op.to_lowercase().as_str() { "add" => { match parse_role(val.to_string(), guild_id) { Some((role_id, role)) => { guild_data.admin_roles.push(role_id.0 as i64); val = format!("{} ({})", role.name, role_id.0); }, None => { message.channel_id.say("I couldn't find that role.")?; return Ok(()) }, } }, "remove" => { match parse_role(val.to_string(), guild_id) { Some((role_id, role)) => { guild_data.admin_roles.retain(|e| *e != role_id.0 as i64); val = format!("{} ({})", role.name, role_id.0); }, None => { message.channel_id.say("I couldn't find that role.")?; return Ok(()) }, } }, _ => { message.channel_id.say("I didn't understand that option. Valid options are: `add`, `remove`. For more information see `help config admin`")?; return Ok(()) }, } db.update_guild(guild_id.0 as i64, guild_data)?; message.channel_id.send_message(|m| m .embed(|e| e .title("Config Admin Summary") .colour(*colours::MAIN) .description(format!("**Operation:** {}\n**Value:** {}", op, val, )) ))?; } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct ConfigMod; impl Command for ConfigMod { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Configure the moderation log, superstitious much.".to_string()), usage: Some(" ".to_string()), example: Some("add staff".to_string()), min_args: Some(2), 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)?; let op = args.single::().unwrap_or(String::new()); let mut val = args.rest().to_string(); match op.to_lowercase().as_str() { "add" => { match parse_role(val.to_string(), guild_id) { Some((role_id, role)) => { guild_data.mod_roles.push(role_id.0 as i64); val = format!("{} ({})", role.name, role_id.0); }, None => { message.channel_id.say("I couldn't find that role.")?; return Ok(()) }, } }, "remove" => { match parse_role(val.to_string(), guild_id) { Some((role_id, role)) => { guild_data.mod_roles.retain(|e| *e != role_id.0 as i64); val = format!("{} ({})", role.name, role_id.0); }, None => { message.channel_id.say("I couldn't find that role.")?; return Ok(()) }, } }, _ => { message.channel_id.say("I didn't understand that option. Valid options are: `add`, `remove`. For more information see `help config mod`")?; return Ok(()) }, } db.update_guild(guild_id.0 as i64, guild_data)?; message.channel_id.send_message(|m| m .embed(|e| e .title("Config Mod Summary") .colour(*colours::MAIN) .description(format!("**Operation:** {}\n**Value:** {}", op, val, )) ))?; } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct ConfigAudit; impl Command for ConfigAudit { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Amping up security around here? Change audit log settings. (A channel must be provided for `channel`.)".to_string()), usage: Some(" ".to_string()), example: Some("channel #audit-logs".to_string()), min_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)?; let op = args.single::().unwrap_or(String::new()); let mut val = args.rest().to_string(); match op.to_lowercase().as_str() { "enable" => { guild_data.audit = true; }, "disable" => { guild_data.audit = false; }, "channel" => { match parse_channel(val.to_string(), guild_id) { Some((channel_id, channel)) => { guild_data.audit_channel = channel_id.0 as i64; val = format!("{} ({})", channel.name, channel_id.0); }, None => { message.channel_id.say("I couldn't find that channel.")?; return Ok(()) }, } }, "threshold" => { match val.parse::() { Ok(th) => { guild_data.audit_threshold = th; val = th.to_string(); }, Err(_) => { message.channel_id.say("Please input a number as the threshold")?; } } }, _ => { message.channel_id.say("I didn't understand that option. Valid options are: `enable`, `disable`, `channel`, `threshold`. For more information see `help config audit`")?; return Ok(()) }, } let guild = db.update_guild(guild_id.0 as i64, guild_data)?; message.channel_id.send_message(|m| m .embed(|e| e .title("Config Audit Summary") .colour(*colours::MAIN) .description(format!("**Operation:** {}\n**Value:** {}", op, if val.is_empty() { format!("{}", guild.audit) } else { val }, )) ))?; } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct ConfigModlog; impl Command for ConfigModlog { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Moderation log settings, move along. (A channel must be provided for `channel`.)".to_string()), usage: Some(" ".to_string()), example: Some("channel #mod-logs".to_string()), min_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)?; let op = args.single::().unwrap_or(String::new()); let mut val = args.rest().to_string(); match op.to_lowercase().as_str() { "enable" => { guild_data.modlog = true; }, "disable" => { guild_data.modlog = false; }, "channel" => { match parse_channel(val.to_string(), guild_id) { Some((channel_id, channel)) => { guild_data.modlog_channel = channel_id.0 as i64; val = format!("{} ({})", channel.name, channel_id.0); }, None => { message.channel_id.say("I couldn't find that channel.")?; return Ok(()) }, } }, _ => { message.channel_id.say("I didn't understand that option. Valid options are: `enable`, `disable`, `channel`. For more information see `help config modlog`")?; return Ok(()) }, } let guild = db.update_guild(guild_id.0 as i64, guild_data)?; message.channel_id.send_message(|m| m .embed(|e| e .title("Config Modlog Summary") .colour(*colours::MAIN) .description(format!("**Operation:** {}\n**Value:** {}", op, if val.is_empty() { guild.modlog.to_string() } else { val }, )) ))?; } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct ConfigWelcome; impl Command for ConfigWelcome { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { // desc: Some("Change welcome message settings.\nOption is one of enable, disable, channel, message, type and the respective values should be none, none, channel_resolvable, desired message.\nType designates if the message is plain or embed. Anything other than embed will result in plain.".to_string()), desc: Some("Want a sick, custom welcome message!?\n\nOptions:\n`enable` - none.\n`disable` - none.\n`channel` - `channel_resolvable` (Mentionable).\n`message` - Your desired welcome message.\n`type` - `plain` or `embed`.".to_string()), usage: Some("