feat: updated the core committee commands
This commit is contained in:
parent
0e6a5d3455
commit
df032f2d7b
7 changed files with 95 additions and 74 deletions
|
@ -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>(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue