feat: updated the core committee commands

This commit is contained in:
silver 2025-03-06 21:35:17 +00:00
parent 0e6a5d3455
commit df032f2d7b
Signed by untrusted user: silver
GPG key ID: 36F93D61BAD3FD7D
7 changed files with 95 additions and 74 deletions

View file

@ -40,7 +40,7 @@ This is where the bot is configured.
You will need the ``api_key`` from the start of the process.
You (personally) will need a role with ``Manage Server`` permission to be able to do this.
1. Use the command ``/add`` and a list of options will pop up.
1. Use the command ``/committee add`` and a list of options will pop up.
2. ``api_key`` is the key you got from Keith earlier.
3. ``role_current`` is the ``member-current`` that you created earlier.
4. ``role_past`` (optional) is the role for all current and past members.

View file

@ -1,47 +1,53 @@
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommandOption};
use serenity::{builder::CreateCommand, client::Context};
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction};
use serenity::client::Context;
use skynet_discord_bot::common::database::{get_server_config, DataBase, Servers};
use skynet_discord_bot::common::set_roles::normal::update_server;
use skynet_discord_bot::common::wolves::cns::get_wolves;
use sqlx::{Error, Pool, Sqlite};
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
let wolves_api = if let Some(CommandDataOption {
value: CommandDataOptionValue::String(key),
let sub_options = if let Some(CommandDataOption {
value: CommandDataOptionValue::SubCommand(options),
..
}) = command.data.options.first()
{
key.to_string()
options
} else {
return "Please provide sub options".to_string();
};
let wolves_api = if let Some(x) = sub_options.first() {
match &x.value {
CommandDataOptionValue::String(key) => key.to_string(),
_ => return "Please provide a wolves API key".to_string(),
}
} else {
return "Please provide a wolves API key".to_string();
};
let role_current = if let Some(CommandDataOption {
value: CommandDataOptionValue::Role(role),
..
}) = command.data.options.get(1)
{
role.to_owned()
let role_current = if let Some(x) = sub_options.get(1) {
match &x.value {
CommandDataOptionValue::Role(role) => role.to_owned(),
_ => return "Please provide a valid role for ``Role Current``".to_string(),
}
} else {
return "Please provide a valid role for ``Role Current``".to_string();
};
let role_past = if let Some(CommandDataOption {
value: CommandDataOptionValue::Role(role),
..
}) = command.data.options.get(5)
{
Some(role.to_owned())
let role_past = if let Some(x) = sub_options.get(5) {
match &x.value {
CommandDataOptionValue::Role(role) => Some(role.to_owned()),
_ => None,
}
} else {
None
};
let bot_channel_id = if let Some(CommandDataOption {
value: CommandDataOptionValue::Channel(channel),
..
}) = command.data.options.get(2)
{
channel.to_owned()
let bot_channel_id = if let Some(x) = sub_options.get(2) {
match &x.value {
CommandDataOptionValue::Channel(channel) => channel.to_owned(),
_ => return "Please provide a valid channel for ``Bot Channel``".to_string(),
}
} else {
return "Please provide a valid channel for ``Bot Channel``".to_string();
};
@ -74,16 +80,6 @@ pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
"Added/Updated server info".to_string()
}
pub fn register() -> CreateCommand {
CreateCommand::new("add")
.description("Enable the bot for this discord")
.default_member_permissions(serenity::model::Permissions::MANAGE_GUILD)
.add_option(CreateCommandOption::new(CommandOptionType::String, "api_key", "UL Wolves API Key").required(true))
.add_option(CreateCommandOption::new(CommandOptionType::Role, "role_current", "Role for Current members").required(true))
.add_option(CreateCommandOption::new(CommandOptionType::Channel, "bot_channel", "Safe space for folks to use the bot commands.").required(true))
.add_option(CreateCommandOption::new(CommandOptionType::Role, "role_past", "Role for Past members").required(false))
}
async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Result<Option<Servers>, Error> {
let existing = get_server_config(db, &server.server).await;
let role_past = server.role_past.map(|x| x.get() as i64);

23
src/commands/committee.rs Normal file
View file

@ -0,0 +1,23 @@
use serenity::all::{CommandOptionType, CreateCommand, CreateCommandOption};
pub fn register() -> CreateCommand {
CreateCommand::new("committee")
.description("Commands related to what committees can do")
.default_member_permissions(serenity::model::Permissions::MANAGE_GUILD)
.add_option(
CreateCommandOption::new(CommandOptionType::SubCommand, "add", "Enable the bot for this discord")
.add_sub_option(CreateCommandOption::new(CommandOptionType::String, "api_key", "UL Wolves API Key").required(true))
.add_sub_option(CreateCommandOption::new(CommandOptionType::Role, "role_current", "Role for Current members").required(true))
.add_sub_option(
CreateCommandOption::new(CommandOptionType::Channel, "bot_channel", "Safe space for folks to use the bot commands.").required(true),
)
.add_sub_option(CreateCommandOption::new(CommandOptionType::Role, "role_past", "Role for Past members").required(false)),
)
.add_option(
CreateCommandOption::new(CommandOptionType::SubCommand, "roles_adder", "Combine roles together to an new one")
.add_sub_option(CreateCommandOption::new(CommandOptionType::Role, "role_a", "A role you want to add to Role B").required(true))
.add_sub_option(CreateCommandOption::new(CommandOptionType::Role, "role_b", "A role you want to add to Role A").required(true))
.add_sub_option(CreateCommandOption::new(CommandOptionType::Role, "role_c", "Sum of A and B").required(true))
.add_sub_option(CreateCommandOption::new(CommandOptionType::Boolean, "delete", "Delete this entry.").required(false)),
)
}

View file

@ -1,4 +1,5 @@
pub mod add_server;
pub mod committee;
pub mod count;
pub mod minecraft;
pub mod role_adder;

View file

@ -5,37 +5,44 @@ use sqlx::{Error, Pool, Sqlite};
pub mod edit {
use super::*;
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommand, CreateCommandOption};
use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction};
pub async fn run(command: &CommandInteraction, ctx: &Context) -> String {
let role_a = if let Some(CommandDataOption {
value: CommandDataOptionValue::Role(role),
let sub_options = if let Some(CommandDataOption {
value: CommandDataOptionValue::SubCommand(options),
..
}) = command.data.options.first()
{
role.to_owned()
options
} else {
return "Please provide a valid role for ``Role Current``".to_string();
return "Please provide sub options".to_string();
};
let role_b = if let Some(CommandDataOption {
value: CommandDataOptionValue::Role(role),
..
}) = command.data.options.get(1)
{
role.to_owned()
let role_a = if let Some(x) = sub_options.first() {
match &x.value {
CommandDataOptionValue::Role(role) => role.to_owned(),
_ => return "Please provide a valid role for ``Role A``".to_string(),
}
} else {
return "Please provide a valid role for ``Role Current``".to_string();
return "Please provide a valid role for ``Role A``".to_string();
};
let role_c = if let Some(CommandDataOption {
value: CommandDataOptionValue::Role(role),
..
}) = command.data.options.get(2)
{
role.to_owned()
let role_b = if let Some(x) = sub_options.get(1) {
match &x.value {
CommandDataOptionValue::Role(role) => role.to_owned(),
_ => return "Please provide a valid role for ``Role B``".to_string(),
}
} else {
return "Please provide a valid role for ``Role Current``".to_string();
return "Please provide a valid role for ``Role B``".to_string();
};
let role_c = if let Some(x) = sub_options.get(2) {
match &x.value {
CommandDataOptionValue::Role(role) => role.to_owned(),
_ => return "Please provide a valid role for ``Role C``".to_string(),
}
} else {
return "Please provide a valid role for ``Role C``".to_string();
};
if role_a == role_b {
@ -46,12 +53,11 @@ pub mod edit {
return "Role C cannot be same as A or B".to_string();
}
let delete = if let Some(CommandDataOption {
value: CommandDataOptionValue::Boolean(z),
..
}) = command.data.options.get(3)
{
*z
let delete = if let Some(x) = sub_options.get(3) {
match &x.value {
CommandDataOptionValue::Boolean(z) => *z,
_ => false,
}
} else {
false
};
@ -101,16 +107,6 @@ pub mod edit {
}
}
pub fn register() -> CreateCommand {
CreateCommand::new("roles_adder")
.description("Combine roles together to an new one")
.default_member_permissions(serenity::model::Permissions::MANAGE_GUILD)
.add_option(CreateCommandOption::new(CommandOptionType::Role, "role_a", "A role you want to add to Role B").required(true))
.add_option(CreateCommandOption::new(CommandOptionType::Role, "role_b", "A role you want to add to Role A").required(true))
.add_option(CreateCommandOption::new(CommandOptionType::Role, "role_c", "Sum of A and B").required(true))
.add_option(CreateCommandOption::new(CommandOptionType::Boolean, "delete", "Delete this entry.").required(false))
}
async fn add_server(db: &Pool<Sqlite>, server: &RoleAdder, delete: bool) -> Result<Option<RoleAdder>, Error> {
if delete {
sqlx::query_as::<_, RoleAdder>(

View file

@ -1,4 +1,3 @@
use lettre::{
message::{header, MultiPart, SinglePart},
transport::smtp::{self, authentication::Credentials},

View file

@ -113,9 +113,8 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
match Command::set_global_commands(
&ctx.http,
vec![
commands::add_server::register(),
commands::role_adder::edit::register(),
commands::wolves::register(),
commands::committee::register(),
commands::minecraft::server::add::register(),
commands::minecraft::server::list::register(),
commands::minecraft::server::delete::register(),
@ -178,8 +177,15 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
"link_minecraft" => commands::minecraft::user::add::run(&command, &ctx).await,
// admin commands
"add" => commands::add_server::run(&command, &ctx).await,
"roles_adder" => commands::role_adder::edit::run(&command, &ctx).await,
"committee" => match command.data.options.first() {
None => "Invalid Command".to_string(),
Some(x) => match x.name.as_str() {
"add" => commands::add_server::run(&command, &ctx).await,
"roles_adder" => commands::role_adder::edit::run(&command, &ctx).await,
// "link" => commands::count::servers::run(&command, &ctx).await,
&_ => format!("not implemented :( committee {}", x.name.as_str()),
},
},
"minecraft_add" => commands::minecraft::server::add::run(&command, &ctx).await,
"minecraft_list" => commands::minecraft::server::list::run(&command, &ctx).await,
"minecraft_delete" => commands::minecraft::server::delete::run(&command, &ctx).await,