Add setAnnouncementRole command

late-submissions
Elnu 3 years ago
parent be78e7c88c
commit c825731814

@ -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::model::prelude::*;
use serenity::prelude::*; use serenity::prelude::*;
@ -93,3 +93,33 @@ async fn setSubmissionChannel(ctx: &Context, msg: &Message) -> CommandResult {
.await?; .await?;
Ok(()) Ok(())
} }
#[command]
#[owners_only]
#[allow(non_snake_case)]
async fn setAnnouncementRole(ctx: &Context, msg: &Message, mut args: Args) -> CommandResult {
let role;
match args.single::<u64>() {
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(())
}

@ -56,7 +56,8 @@ impl EventHandler for Handler {
imageDelete, imageDelete,
help, help,
sleep, sleep,
setSubmissionChannel setSubmissionChannel,
setAnnouncementRole
)] )]
struct General; struct General;

Loading…
Cancel
Save