p4bl0t/src/discord/commands.rs

51 lines
1.5 KiB
Rust
Raw Normal View History

2023-11-22 21:38:21 +01:00
use super::{Context, Error};
use super::utils::serenity;
#[poise::command(
slash_command,
subcommands("add_channel"),
required_permissions = "ADMINISTRATOR"
)]
pub async fn logging(_ctx: Context<'_>, _arg: String) -> Result<(), Error> {
Ok(())
}
#[poise::command(slash_command, aliases("add-channel"))]
pub async fn add_channel(
2023-11-22 21:38:21 +01:00
ctx: Context<'_>,
#[description = "New logging channel"] channel: serenity::Channel,
2023-11-22 21:38:21 +01:00
) -> Result<(), Error> {
let channel_id = channel.id();
let response = match ctx.guild_id() {
None => "Error: Could not determine the guild's ID.".to_owned(),
Some(guild_id) => {
match ctx
.data()
.database
.set_logging_channel(guild_id, channel_id)
.await
{
Ok(_) => format!(
"Added channel <#{channel_id}> as a logging channel"
),
Err(e) => {
if let Some(db_error) = e.as_database_error() {
if db_error.is_unique_violation() {
format!("Channel <#{channel_id}> is already a logging channel")
} else {
format!("Error: {:?}", e)
}
} else {
format!(
"Something bad happened with the database: {e:?}"
)
}
}
}
2023-11-22 21:38:21 +01:00
}
};
ctx.say(response).await?;
Ok(())
}