feat: now properly sets and removes roles for committee members

This commit is contained in:
silver 2025-02-18 21:14:05 +00:00
parent 4eeb7f2135
commit 1aef86ad01
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D
9 changed files with 137 additions and 89 deletions

View file

@ -67,34 +67,6 @@ pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> Stri
return "Please provide a valid channel for ``Bot Channel``".to_string();
};
let server_name = if let CommandDataOptionValue::String(name) = command
.data
.options
.get(3)
.expect("Expected Server Name option")
.resolved
.as_ref()
.expect("Expected Server Name object")
{
name
} else {
&"UL Computer Society".to_string()
};
let wolves_link = if let CommandDataOptionValue::String(wolves) = command
.data
.options
.get(4)
.expect("Expected Wolves Link option")
.resolved
.as_ref()
.expect("Expected Server Name object")
{
wolves
} else {
&"https://ulwolves.ie/society/computer".to_string()
};
let db_lock = {
let data_read = ctx.data.read().await;
data_read.get::<DataBase>().expect("Expected Databse in TypeMap.").clone()
@ -109,8 +81,7 @@ pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> Stri
member_past: 0,
member_current: 0,
bot_channel_id,
server_name: server_name.to_owned(),
wolves_link: wolves_link.to_string(),
server_name: "".to_string(),
};
match add_server(&db, ctx, &server_data).await {
@ -149,20 +120,6 @@ pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicatio
.kind(CommandOptionType::Channel)
.required(true)
})
.create_option(|option| {
option
.name("server_name")
.description("Name of the Discord Server.")
.kind(CommandOptionType::String)
.required(true)
})
.create_option(|option| {
option
.name("wolves_link")
.description("Link to the Club/Society on UL Wolves.")
.kind(CommandOptionType::String)
.required(true)
})
.create_option(|option| {
option
.name("role_past")
@ -178,8 +135,8 @@ async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Resul
let insert = sqlx::query_as::<_, Servers>(
"
INSERT OR REPLACE INTO servers (server, wolves_api, role_past, role_current, bot_channel_id, server_name, wolves_link)
VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7)
INSERT OR REPLACE INTO servers (server, wolves_api, role_past, role_current, bot_channel_id)
VALUES (?1, ?2, ?3, ?4, ?5)
",
)
.bind(*server.server.as_u64() as i64)
@ -187,8 +144,6 @@ async fn add_server(db: &Pool<Sqlite>, ctx: &Context, server: &Servers) -> Resul
.bind(role_past)
.bind(*server.role_current.as_u64() as i64)
.bind(*server.bot_channel_id.as_u64() as i64)
.bind(&server.server_name)
.bind(&server.wolves_link)
.fetch_optional(db)
.await;