diff --git a/doc/User.md b/doc/User.md index f2f050e..570877c 100644 --- a/doc/User.md +++ b/doc/User.md @@ -23,4 +23,4 @@ You will get member roles on any Discord that is using the bot that you are a me ### Minecraft You can link your Minecraft username to grant you access to any Minecraft server run by UL Computer Society. -``/link_minecraft MINECRAFT_USERNAME`` +``/wolves link_minecraft MINECRAFT_USERNAME`` diff --git a/src/commands/minecraft.rs b/src/commands/minecraft.rs index 124179c..3b71632 100644 --- a/src/commands/minecraft.rs +++ b/src/commands/minecraft.rs @@ -1,4 +1,4 @@ -use serenity::{builder::CreateCommand, client::Context}; +use serenity::client::Context; use skynet_discord_bot::common::database::DataBase; use sqlx::{Pool, Sqlite}; @@ -9,20 +9,13 @@ pub(crate) mod user { use super::*; use crate::commands::wolves::link::get_server_member_discord; use serde::{Deserialize, Serialize}; - use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction, CommandOptionType, CreateCommandOption}; + use serenity::all::{CommandDataOption, CommandDataOptionValue, CommandInteraction}; use serenity::model::id::UserId; use skynet_discord_bot::common::database::Wolves; use skynet_discord_bot::common::minecraft::{whitelist_update, Minecraft}; use skynet_discord_bot::Config; use sqlx::Error; - pub fn register() -> CreateCommand { - CreateCommand::new("link_minecraft") - .description("Link your minecraft account") - .add_option(CreateCommandOption::new(CommandOptionType::String, "minecraft_username", "Your Minecraft username").required(true)) - .add_option(CreateCommandOption::new(CommandOptionType::Boolean, "bedrock_account", "Is this a Bedrock account?").required(false)) - } - pub async fn run(command: &CommandInteraction, ctx: &Context) -> String { let db_lock = { let data_read = ctx.data.read().await; @@ -41,23 +34,30 @@ pub(crate) mod user { return "Not linked with wolves, please use ``/link_wolves`` with your wolves email.".to_string(); } - let username = if let Some(CommandDataOption { - value: CommandDataOptionValue::String(username), + let sub_options = if let Some(CommandDataOption { + value: CommandDataOptionValue::SubCommand(options), .. }) = command.data.options.first() { - username.trim() + options + } else { + return "Please provide sub options".to_string(); + }; + + let username = if let Some(x) = sub_options.first() { + match &x.value { + CommandDataOptionValue::String(username) => username.trim(), + _ => return "Please provide a valid username".to_string(), + } } else { return "Please provide a valid username".to_string(); }; - // this is always true unless they state its not - let java = if let Some(CommandDataOption { - value: CommandDataOptionValue::Boolean(z), - .. - }) = command.data.options.get(1) - { - !z + let java = if let Some(x) = sub_options.get(1) { + match &x.value { + CommandDataOptionValue::Boolean(z) => !z, + _ => true, + } } else { true }; diff --git a/src/commands/wolves.rs b/src/commands/wolves.rs index 3d8b120..92c6ec0 100644 --- a/src/commands/wolves.rs +++ b/src/commands/wolves.rs @@ -511,4 +511,9 @@ pub fn register() -> CreateCommand { ) // unlink .add_option(CreateCommandOption::new(CommandOptionType::SubCommand, "unlink", "Unlink your Wolves account from your Discord")) + .add_option( + CreateCommandOption::new(CommandOptionType::SubCommand, "link_minecraft", "Link your minecraft account") + .add_sub_option(CreateCommandOption::new(CommandOptionType::String, "minecraft_username", "Your Minecraft username").required(true)) + .add_sub_option(CreateCommandOption::new(CommandOptionType::Boolean, "bedrock_account", "Is this a Bedrock account?").required(false)), + ) } diff --git a/src/main.rs b/src/main.rs index 7a47e87..dc15840 100644 --- a/src/main.rs +++ b/src/main.rs @@ -118,7 +118,6 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use commands::minecraft::server::add::register(), commands::minecraft::server::list::register(), commands::minecraft::server::delete::register(), - commands::minecraft::user::add::register(), ], ) .await @@ -170,12 +169,12 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use "link" => commands::wolves::link::run(&command, &ctx).await, "verify" => commands::wolves::verify::run(&command, &ctx).await, "unlink" => commands::wolves::unlink::run(&command, &ctx).await, + "link_minecraft" => commands::minecraft::user::add::run(&command, &ctx).await, // "link" => commands::count::servers::run(&command, &ctx).await, &_ => format!("not implemented :( wolves {}", x.name.as_str()), }, }, - "link_minecraft" => commands::minecraft::user::add::run(&command, &ctx).await, // admin commands "committee" => match command.data.options.first() { None => "Invalid Command".to_string(),