diff --git a/src/command/util.rs b/src/command/util.rs index d044e39..1c3a238 100644 --- a/src/command/util.rs +++ b/src/command/util.rs @@ -53,6 +53,32 @@ pub async fn add_channel( Ok(()) } +/// Remove information from the shared settings +#[poise::command(slash_command)] +pub async fn remove_channel( + ctx: Context<'_>, + #[description = "Selected channel"] channel: Option, +) -> Result<(), Error> { + ctx.defer_ephemeral().await?; + if let Some(channel_ok) = channel { + let config = &mut ctx.data().config_manager.lock().await; + let channel_id = { u64::from(channel_ok.id()) }; + //let found = config.channels.iter().find(|c| c.id() == channel_ok.id()); + config.channels.retain(|c| c.id() != channel_ok.id()); + config.store().unwrap(); + ctx.say(format!( + "Successfully removed <#{}> from the channel registry.", + channel_id + )) + .await?; + info!("Executed command `remove_channel` successfully"); + } else { + ctx.say("Channel with supplied ID was not found.").await?; + error!("Failed to execute command `remove_channel`."); + } + Ok(()) +} + #[poise::command(slash_command)] pub async fn list_channels(ctx: Context<'_>) -> Result<(), Error> { ctx.defer_ephemeral().await?; diff --git a/src/main.rs b/src/main.rs index 81dfc22..f663f94 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,7 +74,7 @@ async fn main() { // +---------------------------------------------------------+ // | ADD COMMANDS HERE | // +---------------------------------------------------------+ - commands: vec![age(), info(), add_channel(), list_channels(), shutdown(), restart()], + commands: vec![age(), info(), add_channel(), remove_channel(), list_channels(), shutdown(), restart()], initialize_owners: true, ..Default::default() })