Make more args reqd

This commit is contained in:
shibedrill 2024-04-25 15:18:14 -04:00
parent 23d84511c9
commit b6d6581301

View File

@ -43,7 +43,7 @@ pub async fn info(ctx: Context<'_>) -> Result<(), Error> {
Github: <https://github.com/shibedrill/shibe-bot>\n\ Github: <https://github.com/shibedrill/shibe-bot>\n\
Poise: <https://docs.rs/poise/latest/poise/>\n\ Poise: <https://docs.rs/poise/latest/poise/>\n\
Rust: <https://www.rust-lang.org/>", Rust: <https://www.rust-lang.org/>",
env!("CARGO_PKG_VERSION") env!("CARGO_PKG_VERSION")
)) ))
.await?; .await?;
info!("Executed command `info` successfully"); info!("Executed command `info` successfully");
@ -54,24 +54,18 @@ pub async fn info(ctx: Context<'_>) -> Result<(), Error> {
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub async fn add_channel( pub async fn add_channel(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Selected channel"] channel: Option<serenity::Channel>, #[description = "Selected channel"] channel: serenity::Channel,
) -> Result<(), Error> { ) -> Result<(), Error> {
ctx.defer_ephemeral().await?; let config = &mut ctx.data().config_manager.lock().await;
if let Some(channel_ok) = channel { let channel_id = { u64::from(channel.id()) };
let config = &mut ctx.data().config_manager.lock().await; config.channels.push(channel);
let channel_id = { u64::from(channel_ok.id()) }; config.store().unwrap();
config.channels.push(channel_ok); ctx.say(format!(
config.store().unwrap(); "Successfully added <#{}> to the channel registry.",
ctx.say(format!( channel_id
"Successfully added <#{}> to the channel registry.", ))
channel_id .await?;
)) info!("Executed command `add_channel` successfully");
.await?;
info!("Executed command `add_channel` successfully");
} else {
ctx.say("Channel with supplied ID was not found.").await?;
error!("Failed to execute command `add_channel`");
}
Ok(()) Ok(())
} }
@ -79,24 +73,19 @@ pub async fn add_channel(
#[poise::command(slash_command)] #[poise::command(slash_command)]
pub async fn remove_channel( pub async fn remove_channel(
ctx: Context<'_>, ctx: Context<'_>,
#[description = "Selected channel"] channel: Option<serenity::Channel>, #[description = "Selected channel"] channel: serenity::Channel,
) -> Result<(), Error> { ) -> Result<(), Error> {
ctx.defer_ephemeral().await?; ctx.defer_ephemeral().await?;
if let Some(channel_ok) = channel { let config = &mut ctx.data().config_manager.lock().await;
let config = &mut ctx.data().config_manager.lock().await; let channel_id = { u64::from(channel.id()) };
let channel_id = { u64::from(channel_ok.id()) }; config.channels.retain(|c| c.id() != channel.id());
config.channels.retain(|c| c.id() != channel_ok.id()); config.store().unwrap();
config.store().unwrap(); ctx.say(format!(
ctx.say(format!( "Successfully removed <#{}> from the channel registry.",
"Successfully removed <#{}> from the channel registry.", channel_id
channel_id ))
)) .await?;
.await?; info!("Executed command `remove_channel` successfully");
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(()) Ok(())
} }
@ -107,9 +96,9 @@ pub async fn list_channels(ctx: Context<'_>) -> Result<(), Error> {
let config = &mut ctx.data().config_manager.lock().await; let config = &mut ctx.data().config_manager.lock().await;
let mut channel_ids: Vec<u64> = vec![]; let mut channel_ids: Vec<u64> = vec![];
config config
.channels .channels
.iter() .iter()
.for_each(|c| channel_ids.push(u64::from(c.id()))); .for_each(|c| channel_ids.push(u64::from(c.id())));
ctx.say(format!( ctx.say(format!(
"Current channel IDs in registry: \n{:#?}", "Current channel IDs in registry: \n{:#?}",
channel_ids channel_ids