feat: new command to count the server info, available on the computer soc server

This commit is contained in:
silver 2025-02-27 23:56:48 +00:00
parent 934842cbc9
commit 7d7afcd00c
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D
5 changed files with 180 additions and 86 deletions

View file

@ -1,80 +0,0 @@
pub mod count {
// get the list of all the current clubs/socs members
use serenity::all::{
CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, Context, CreateCommand, CreateCommandOption,
};
use skynet_discord_bot::common::database::DataBase;
use skynet_discord_bot::common::set_roles::committee::db_roles_get;
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
let sub_options = if let Some(CommandDataOption {
value: CommandDataOptionValue::SubCommand(key),
..
}) = command.data.options.first()
{
key
} else {
return "Please provide a wolves API key".to_string();
};
let all = if let Some(x) = sub_options.first() {
match x.value {
CommandDataOptionValue::Boolean(y) => y,
_ => false,
}
} else {
false
};
let db_lock = {
let data_read = ctx.data.read().await;
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
};
let db = db_lock.read().await;
let mut cs = vec![];
// pull it from a DB
for committee in db_roles_get(&db).await {
if !all && committee.count == 0 {
continue;
}
cs.push((committee.count, committee.name_role.to_owned()));
}
cs.sort_by_key(|(count, _)| *count);
cs.reverse();
// msg can be a max 2000 chars long
let mut limit = 2000;
let mut response = vec![];
for (count, name) in cs {
let leading = if count < 10 { " " } else { "" };
let line = format!("{}{} {}", leading, count, name);
let length = line.len() + 1;
if length < limit {
response.push(line);
limit -= length;
} else {
break;
}
}
response.join("\n")
}
pub fn register() -> CreateCommand {
CreateCommand::new("committee")
.description("Commands related to teh committees")
//.default_member_permissions(serenity::model::Permissions::MANAGE_GUILD)
.add_option(
CreateCommandOption::new(CommandOptionType::SubCommand, "list", "List out the Committee Roles Numbers")
.add_sub_option(CreateCommandOption::new(CommandOptionType::Boolean, "all", "List out all the Committee Roles Numbers").required(false)),
)
}
}