feat: change commands to use the "Manage Server" permission instead of just admin.

This measn that the commands only show up if you can manage teh server
This commit is contained in:
silver 2025-02-26 15:55:42 +00:00
parent 09ce45f70f
commit 7406f0e620
Signed by untrusted user: silver
GPG key ID: 36F93D61BAD3FD7D
4 changed files with 21 additions and 73 deletions

View file

@ -3,8 +3,6 @@ pub mod common;
use chrono::{Datelike, SecondsFormat, Utc};
use dotenvy::dotenv;
use rand::{distr::Alphanumeric, rng, Rng};
use serenity::all::CommandInteraction;
use serenity::client::Context;
use serenity::model::id::{ChannelId, GuildId, RoleId};
use serenity::prelude::TypeMapKey;
use std::{env, sync::Arc};
@ -127,41 +125,3 @@ pub fn get_now_iso(short: bool) -> String {
pub fn random_string(len: usize) -> String {
rng().sample_iter(&Alphanumeric).take(len).map(char::from).collect()
}
/**
For any time ye need to check if a user who calls a command has admin privlages
*/
pub async fn is_admin(command: &CommandInteraction, ctx: &Context) -> Option<String> {
let mut admin = false;
let g_id = match command.guild_id {
None => return Some("Not in a server".to_string()),
Some(x) => x,
};
let roles_server = g_id.roles(&ctx.http).await.unwrap_or_default();
if let Ok(member) = g_id.member(&ctx.http, command.user.id).await {
if let Some(permissions) = member.permissions {
if permissions.administrator() {
admin = true;
}
}
for role_id in member.roles {
if admin {
break;
}
if let Some(role) = roles_server.get(&role_id) {
if role.permissions.administrator() {
admin = true;
}
}
}
}
if !admin {
Some("Administrator permission required".to_string())
} else {
None
}
}