feat: new command to see how many of each club/soc are on teh server
This commit is contained in:
parent
0bedf96da5
commit
143483d3b3
4 changed files with 110 additions and 9 deletions
80
src/commands/committee.rs
Normal file
80
src/commands/committee.rs
Normal file
|
@ -0,0 +1,80 @@
|
|||
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)),
|
||||
)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue