2023-11-22 21:38:21 +01:00
|
|
|
use super::{Context, Error};
|
|
|
|
|
|
|
|
use super::utils::serenity;
|
|
|
|
|
2023-11-23 02:09:45 +01:00
|
|
|
#[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<'_>,
|
2023-11-23 02:09:45 +01:00
|
|
|
#[description = "New logging channel"] channel: serenity::Channel,
|
2023-11-22 21:38:21 +01:00
|
|
|
) -> Result<(), Error> {
|
2023-11-23 02:09:45 +01:00
|
|
|
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(())
|
|
|
|
}
|