feat: unlink is now a subcommand of wolves

This commit is contained in:
silver 2025-03-06 19:21:17 +00:00
parent 058f8a7a7d
commit 3a39084f40
Signed by untrusted user: silver
GPG key ID: 36F93D61BAD3FD7D
2 changed files with 69 additions and 0 deletions

View file

@ -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::<DataBase>().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<Sqlite>, 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",
))
}
}

View file

@ -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