From d7b5cd36ea4007f155cd8b0a2286da85fa6d060c Mon Sep 17 00:00:00 2001 From: Brendan Golden Date: Mon, 2 Oct 2023 09:15:50 +0100 Subject: [PATCH] fix: last remaining uses of a username over ID --- src/commands/link_email.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/commands/link_email.rs b/src/commands/link_email.rs index 51fd628..23e6ac4 100644 --- a/src/commands/link_email.rs +++ b/src/commands/link_email.rs @@ -236,6 +236,7 @@ pub(crate) mod link { } pub(crate) mod verify { + use serenity::model::id::UserId; use super::*; use crate::commands::link_email::link::{db_pending_clear_expired, get_verify_from_db}; use serenity::model::user::User; @@ -277,9 +278,9 @@ pub(crate) mod verify { return "Invalid verification code".to_string(); } - match db_pending_clear_successful(&db, &command.user.name).await { + match db_pending_clear_successful(&db, &command.user.id).await { Ok(_) => { - return match set_discord(&db, &command.user.name, &details.email).await { + return match set_discord(&db, &command.user.id, &details.email).await { Ok(_) => { // get teh right roles for the user set_server_roles(&db, &command.user, ctx).await; @@ -307,7 +308,7 @@ pub(crate) mod verify { }) } - async fn db_pending_clear_successful(pool: &Pool, user: &str) -> Result, Error> { + async fn db_pending_clear_successful(pool: &Pool, user: &UserId) -> Result, Error> { sqlx::query_as::<_, WolvesVerify>( r#" DELETE @@ -315,12 +316,12 @@ pub(crate) mod verify { WHERE discord = ? "#, ) - .bind(user) + .bind(*user.as_u64() as i64) .fetch_optional(pool) .await } - async fn set_discord(db: &Pool, discord: &str, email: &str) -> Result, Error> { + async fn set_discord(db: &Pool, discord: &UserId, email: &str) -> Result, Error> { sqlx::query_as::<_, Wolves>( " UPDATE wolves @@ -328,14 +329,14 @@ pub(crate) mod verify { WHERE email = ? ", ) - .bind(discord) + .bind(*discord.as_u64() as i64) .bind(email) .fetch_optional(db) .await } async fn set_server_roles(db: &Pool, discord: &User, ctx: &Context) { - if let Ok(servers) = get_servers(db, &discord.name).await { + if let Ok(servers) = get_servers(db, &discord.id).await { for server in servers { if let Ok(mut member) = server.server.member(&ctx.http, &discord.id).await { if let Some(config) = get_server_config(db, &server.server).await { @@ -368,7 +369,7 @@ pub(crate) mod verify { } } - async fn get_servers(db: &Pool, discord: &str) -> Result, Error> { + async fn get_servers(db: &Pool, discord: &UserId) -> Result, Error> { sqlx::query_as::<_, ServerMembersWolves>( " SELECT * @@ -377,7 +378,7 @@ pub(crate) mod verify { WHERE discord = ? ", ) - .bind(discord) + .bind(*discord.as_u64() as i64) .fetch_all(db) .await }