aboutsummaryrefslogtreecommitdiff
path: root/src/modules/commands/mods/info.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2020-10-26 19:03:53 -0700
committerFuwn <[email protected]>2020-10-26 19:03:53 -0700
commit9742614a1dc4699c1f2c69d923d402237672335d (patch)
treea49f7d834372f37cef06b30a28ff1b40bdfaa079 /src/modules/commands/mods/info.rs
parentCreate README.md (diff)
downloaddep-core-next-9742614a1dc4699c1f2c69d923d402237672335d.tar.xz
dep-core-next-9742614a1dc4699c1f2c69d923d402237672335d.zip
repo: push main from local to remote
Diffstat (limited to 'src/modules/commands/mods/info.rs')
-rw-r--r--src/modules/commands/mods/info.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/modules/commands/mods/info.rs b/src/modules/commands/mods/info.rs
new file mode 100644
index 0000000..11c2119
--- /dev/null
+++ b/src/modules/commands/mods/info.rs
@@ -0,0 +1,49 @@
+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 ModInfo;
+impl Command for ModInfo {
+ fn options(&self) -> Arc<CommandOptions> {
+ let default = CommandOptions::default();
+ let options = CommandOptions {
+ desc: Some("Someone acting up ? Look em' up.".to_string()),
+ usage: Some("<user_resolvable>".to_string()),
+ example: Some("@fun".to_string()),
+ aliases: vec!["mi", "minfo"].iter().map(|e| e.to_string()).collect(),
+ required_permissions: Permissions::MANAGE_MESSAGES,
+ ..default
+ };
+ Arc::new(options)
+ }
+
+ fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> {
+ if let Some(guild_id) = message.guild_id {
+ match parse_user(args.single::<String>().unwrap_or(String::new()), guild_id) {
+ Some((user_id, _)) => {
+ let user = db.get_user(user_id.0 as i64, guild_id.0 as i64)?;
+ let cases = db.get_cases(user_id.0 as i64, guild_id.0 as i64)?;
+ let case_fmt = cases.iter().map(|c| format!("Type: {}\nModerator: {}\nTimestamp: {}", c.casetype, c.moderator, c.timestamp)).collect::<Vec<String>>().join("\n");
+ message.channel_id.send_message(|m| m
+ .embed(|e| e
+ .title("Moderator info")
+ .field("Watchlist", { if user.watchlist { "Yes" } else { "No" } }, false)
+ .field("Cases", if case_fmt.is_empty() { "None" } else { case_fmt.as_str() }, false)
+ ))?;
+ },
+ None => { message.channel_id.say("I couldn't find that user.")?; }
+ }
+ } else { failed!(GUILDID_FAIL); }
+ Ok(())
+ }
+}