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