From c825731814984a9ed21709234df43b686ca06176 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Thu, 17 Feb 2022 10:28:40 -0800 Subject: [PATCH] Add setAnnouncementRole command --- src/commands/owner.rs | 32 +++++++++++++++++++++++++++++++- src/main.rs | 3 ++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/commands/owner.rs b/src/commands/owner.rs index 9e1a53c..1624ef4 100644 --- a/src/commands/owner.rs +++ b/src/commands/owner.rs @@ -1,4 +1,4 @@ -use serenity::framework::standard::{macros::command, CommandResult}; +use serenity::framework::standard::{macros::command, Args, CommandResult}; use serenity::model::prelude::*; use serenity::prelude::*; @@ -93,3 +93,33 @@ async fn setSubmissionChannel(ctx: &Context, msg: &Message) -> CommandResult { .await?; Ok(()) } + +#[command] +#[owners_only] +#[allow(non_snake_case)] +async fn setAnnouncementRole(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult { + let role; + match args.single::() { + Ok(id) => role = id.to_string(), + Err(_) => { + msg.reply(&ctx.http, "Please provide an announcement role ID.").await?; + return Ok(()); + } + } + let mut guild_data = get_guild_data(); + let guild = msg.guild_id.unwrap().as_u64().to_string(); + if guild_data.contains_key(&guild) { + let mut current_guild_data = guild_data[&guild].as_object().unwrap().clone(); + if current_guild_data.contains_key("announcementRole") { + current_guild_data["announcementRole"] = role.into(); + } else { + current_guild_data.insert(String::from("announcementRole"), role.into()); + } + guild_data[&guild] = current_guild_data.into(); + } else { + guild_data.insert(guild, json!({ "announcementRole": role })); + } + set_guild_data(guild_data); + msg.reply(&ctx.http, "Announcement role set.").await?; + Ok(()) +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 3e8c62d..0d389aa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,8 @@ impl EventHandler for Handler { imageDelete, help, sleep, - setSubmissionChannel + setSubmissionChannel, + setAnnouncementRole )] struct General;