From 3a39084f407392ea7f7c6a797bd0b4567d2c5f1d Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Thu, 6 Mar 2025 19:21:17 +0000 Subject: [PATCH] feat: unlink is now a subcommand of wolves --- src/commands/link_email.rs | 59 ++++++++++++++++++++++++++++++++++++++ src/main.rs | 10 +++++++ 2 files changed, 69 insertions(+) diff --git a/src/commands/link_email.rs b/src/commands/link_email.rs index 71cfbb0..9120a6d 100644 --- a/src/commands/link_email.rs +++ b/src/commands/link_email.rs @@ -449,3 +449,62 @@ pub mod verify { .await } } + +pub mod wolves { + use serenity::all::{CommandOptionType, CreateCommand, CreateCommandOption}; + + pub mod unlink { + use serenity::all::{CommandInteraction, Context, UserId}; + use skynet_discord_bot::common::database::{DataBase, Wolves}; + use sqlx::{Pool, Sqlite}; + + pub async fn run(command: &CommandInteraction, ctx: &Context) -> String { + let db_lock = { + let data_read = ctx.data.read().await; + data_read.get::().expect("Expected Databse in TypeMap.").clone() + }; + let db = db_lock.read().await; + + // dosent matter if there is one or not, it will be removed regardless + delete_link(&db, &command.user.id).await; + + "Discord link removed".to_string() + } + + async fn delete_link(db: &Pool, user: &UserId) { + match sqlx::query_as::<_, Wolves>( + " + UPDATE wolves + SET discord = NULL + WHERE discord = ?1; + ", + ) + .bind(user.get() as i64) + .fetch_optional(db) + .await + { + Ok(_) => {} + Err(e) => { + dbg!(e); + } + } + } + } + + pub fn register() -> CreateCommand { + CreateCommand::new("wolves") + .description("Commands related to UL Wolves") + // All Committee members are able to add reactions to posts + .default_member_permissions(serenity::model::Permissions::ADD_REACTIONS) + .add_option(CreateCommandOption::new( + // link + + // verify + + // unlink + CommandOptionType::SubCommand, + "unlink", + "List out the Committee Roles Numbers", + )) + } +} diff --git a/src/main.rs b/src/main.rs index 1efaed7..cbfd311 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,6 +117,7 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use commands::role_adder::edit::register(), commands::link_email::link::register(), commands::link_email::verify::register(), + commands::link_email::wolves::register(), commands::minecraft::server::add::register(), commands::minecraft::server::list::register(), commands::minecraft::server::delete::register(), @@ -167,6 +168,15 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use let content = match command.data.name.as_str() { // user commands "link_wolves" => commands::link_email::link::run(&command, &ctx).await, + "wolves" => match command.data.options.first() { + None => "Invalid Command".to_string(), + Some(x) => match x.name.as_str() { + "unlink" => commands::link_email::wolves::unlink::run(&command, &ctx).await, + // "link" => commands::count::servers::run(&command, &ctx).await, + &_ => format!("not implemented :( wolves {}", x.name.as_str()), + }, + }, + "verify" => commands::link_email::verify::run(&command, &ctx).await, "link_minecraft" => commands::minecraft::user::add::run(&command, &ctx).await, // admin commands