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:
parent
09ce45f70f
commit
7406f0e620
4 changed files with 21 additions and 73 deletions
40
src/lib.rs
40
src/lib.rs
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue