From 8d1c6b1bd15abd371f658e5907b2fae877af63c3 Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Tue, 17 Sep 2024 21:19:44 +0100 Subject: [PATCH] feat: updated command to get the extra information on signup --- src/commands/add_server.rs | 75 +++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 2 deletions(-) diff --git a/src/commands/add_server.rs b/src/commands/add_server.rs index e1e7ca4..150d74c 100644 --- a/src/commands/add_server.rs +++ b/src/commands/add_server.rs @@ -51,6 +51,50 @@ pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> Stri } }; + + let bot_channel_id = if let CommandDataOptionValue::Channel(channel) = command + .data + .options + .get(3) + .expect("Expected channel option") + .resolved + .as_ref() + .expect("Expected channel object") + { + channel.id.to_owned() + } else { + return "Please provide a valid channel for ``Bot Channel``".to_string(); + }; + + + let server_name = if let CommandDataOptionValue::String(name) = command + .data + .options + .get(4) + .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(5) + .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::().expect("Expected Databse in TypeMap.").clone() @@ -64,6 +108,9 @@ pub async fn run(command: &ApplicationCommandInteraction, ctx: &Context) -> Stri role_current, member_past: 0, member_current: 0, + bot_channel_id, + server_name: server_name.to_owned(), + wolves_link: wolves_link.to_string(), }; match add_server(&db, ctx, &server_data).await { @@ -102,6 +149,27 @@ pub fn register(command: &mut CreateApplicationCommand) -> &mut CreateApplicatio .kind(CommandOptionType::Role) .required(false) }) + .create_option(|option| { + option + .name("bot_channel") + .description("Safe space for folks to use the bot commands.") + .kind(CommandOptionType::Channel) + .required(true) + }) + .create_option(|option| { + option + .name("server_name") + .description("Name of the Discord Server.") + .kind(CommandOptionType::String) + .required(false) + }) + .create_option(|option| { + option + .name("wolves_link") + .description("Link to the Club/Society on UL Wolves.") + .kind(CommandOptionType::String) + .required(false) + }) } async fn add_server(db: &Pool, ctx: &Context, server: &Servers) -> Result, Error> { @@ -111,14 +179,17 @@ async fn add_server(db: &Pool, ctx: &Context, server: &Servers) -> Resul let insert = sqlx::query_as::<_, Servers>( " - INSERT OR REPLACE INTO servers (server, wolves_api, role_past, role_current) - VALUES (?1, ?2, ?3, ?4) + 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) ", ) .bind(*server.server.as_u64() as i64) .bind(&server.wolves_api) .bind(role_past) .bind(role_current) + .bind(*server.bot_channel_id.as_u64() as i64) + .bind(&server.server_name) + .bind(&server.wolves_link) .fetch_optional(db) .await;