feat: make the admin hable to init the config

This commit is contained in:
Max batleforc 2024-06-28 10:26:50 +02:00
parent 12ae78d934
commit dd67020b3e
No known key found for this signature in database
GPG Key ID: 25D243AB4B6AC9E7

View File

@ -1,8 +1,5 @@
use crate::botv2::{
domain::server_config::{
change_enable_server::change_enable_server,
check_if_server_enable_and_admin::check_if_server_enable_and_user_admin,
},
domain::server_config::change_enable_server::change_enable_server,
init::{Context, Error},
};
use poise::{
@ -17,7 +14,8 @@ use tracing::instrument;
slash_command,
prefix_command,
category = "server_config",
guild_only = true
guild_only = true,
owners_only = true
)]
pub async fn init(
ctx: Context<'_>,
@ -29,38 +27,7 @@ pub async fn init(
};
let entity_name = ctx.data().entity_name.clone();
let footer = CreateEmbedFooter::new(entity_name.clone());
match check_if_server_enable_and_user_admin(guild.get(), ctx.author().id.get(), ctx.http())
.await
{
Ok((ok, _)) => {
if !ok {
let embed = CreateEmbed::new()
.title("You are not an admin")
.color(colour::Color::RED)
.footer(footer);
if let Err(why) = ctx
.send(CreateReply::default().embed(embed).ephemeral(true))
.await
{
tracing::error!("Error sending message: {:?}", why);
}
return Ok(());
}
}
Err(_) => {
let embed = CreateEmbed::new()
.title("You are not an admin")
.color(colour::Color::RED)
.footer(footer);
if let Err(why) = ctx
.send(CreateReply::default().embed(embed).ephemeral(true))
.await
{
tracing::error!("Error sending message: {:?}", why);
}
return Ok(());
}
};
let answer = match change_enable_server(guild.get(), enable).await {
Ok(_) => CreateEmbed::new()
.title("Server config initialized")