feat: correction array

This commit is contained in:
Max batleforc 2024-06-20 15:07:23 +02:00
parent 5a6fdd74fc
commit 7524fe07e2
No known key found for this signature in database
GPG Key ID: 25D243AB4B6AC9E7
4 changed files with 20 additions and 12 deletions

View File

@ -71,7 +71,9 @@ async fn server_info(ctx: Context<'_>, ephemeral: Option<bool>) -> Result<(), Er
}
Err(_) => {
let embed = CreateEmbed::new()
.title("You are not an admin")
.title("Error while fetching server config")
.field("Please contact your administrator", "", false)
.field("Your config is possibly not initied", "", false)
.color(colour::Color::RED)
.footer(footer);
if let Err(why) = ctx

View File

@ -25,7 +25,9 @@ pub async fn check_if_server_enable(
match server_config {
None => {
tracing::info!("Server config not found");
return Ok((false, None));
return Err(CheckIfServerEnableError::UnknownError(
"Server config not found".to_string(),
));
}
Some(server_config) => Ok((server_config.enable, Some(server_config))),
}

View File

@ -1,7 +1,7 @@
use super::check_if_server_enable::{check_if_server_enable, CheckIfServerEnableError};
use crate::db::server_config::ServerConfig;
use poise::serenity_prelude::{self, RoleId, UserId};
use tracing::instrument;
use tracing::{info, instrument};
#[instrument(level = "info", skip(http))]
pub async fn check_if_server_enable_and_user_admin(
@ -28,17 +28,21 @@ pub async fn check_if_server_enable_and_user_admin(
}
};
if guild.owner_id.get() == user_id {
info!("User is owner of the server");
return Ok((true, Some(server_config)));
}
match guild.member(http, UserId::new(user_id)).await {
Ok(member) => Ok((
server_config
.clone()
.admin_role
.into_iter()
.any(|role_id| member.roles.contains(&RoleId::new(role_id))),
Some(server_config),
)),
Ok(member) => {
info!("Checking if user is admin");
Ok((
server_config
.clone()
.admin_role
.into_iter()
.any(|role_id| member.roles.contains(&RoleId::new(role_id))),
Some(server_config),
))
}
Err(err) => {
tracing::error!(error = err.to_string(), "Error getting member");
return Err(CheckIfServerEnableError::UnknownError(

View File

@ -48,7 +48,7 @@ impl ServerConfig {
}
pub async fn update(&self) -> Result<(), surrealdb::Error> {
let sql = format!(
"UPDATE {} SET enable = {}, auto_meme = {}, auto_concour = {}, admin_role = '{:?}' WHERE server_id = {}",
"UPDATE {} SET enable = {}, auto_meme = {}, auto_concour = {}, admin_role = {:?} WHERE server_id = {}",
SERVER_CONFIG,
self.enable,
self.auto_meme,