feat: tested out command and gt rid of the last few kinks

This commit is contained in:
silver 2024-09-29 23:47:33 +01:00
parent ffce78a10d
commit 32292a3c0b
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D
3 changed files with 93 additions and 27 deletions

View file

@ -6,7 +6,6 @@ use serenity::{
model::{
application::{command::Command, interaction::Interaction},
gateway::{GatewayIntents, Ready},
guild,
prelude::Activity,
user::OnlineStatus,
},
@ -16,13 +15,14 @@ use std::sync::Arc;
use serenity::model::guild::Member;
use skynet_discord_bot::{db_init, get_config, get_server_config, get_server_member, Config, DataBase};
use tokio::sync::RwLock;
use crate::commands::role_adder::tools::on_role_change;
struct Handler;
#[async_trait]
impl EventHandler for Handler {
// handles previously linked accounts joining the server
async fn guild_member_addition(&self, ctx: Context, mut new_member: guild::Member) {
async fn guild_member_addition(&self, ctx: Context, mut new_member: Member) {
let db_lock = {
let data_read = ctx.data.read().await;
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
@ -76,6 +76,7 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
match Command::set_global_application_commands(&ctx.http, |commands| {
commands
.create_application_command(|command| commands::add_server::register(command))
.create_application_command(|command| commands::role_adder::edit::register(command))
.create_application_command(|command| commands::link_email::link::register(command))
.create_application_command(|command| commands::link_email::verify::register(command))
.create_application_command(|command| commands::minecraft::server::add::register(command))
@ -107,6 +108,7 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
"link_minecraft" => commands::minecraft::user::add::run(&command, &ctx).await,
// admin commands
"add" => commands::add_server::run(&command, &ctx).await,
"roles_adder" => commands::role_adder::edit::run(&command, &ctx).await,
"minecraft_add" => commands::minecraft::server::add::run(&command, &ctx).await,
"minecraft_list" => commands::minecraft::server::list::run(&command, &ctx).await,
"minecraft_delete" => commands::minecraft::server::delete::run(&command, &ctx).await,
@ -123,22 +125,18 @@ Sign up on [UL Wolves]({}) and go to https://discord.com/channels/{}/{} and use
}
// handles role updates
async fn guild_member_update(&self, _ctx: Context, _old_if_available: Option<Member>, _new: Member){
if let Some(x) = _old_if_available {
if x.roles.len() != _new.roles.len() {
return;
}
//do we need to do more comparison here?
}
async fn guild_member_update(&self, ctx: Context, _old_data: Option<Member>, new_data: Member){
// get config/db
let db_lock = {
let data_read = ctx.data.read().await;
data_read.get::<DataBase>().expect("Expected Config in TypeMap.").clone()
};
let db = db_lock.read().await;
// check if the role changed is part of the oens for this server
// if so add or remove the resultant one
// TODO: Finish
on_role_change(&db, &ctx, new_data).await;
}
}