fix: last remaining uses of a username over ID

This commit is contained in:
silver 2023-10-02 09:15:50 +01:00
parent 058fe2538a
commit d7b5cd36ea

View file

@ -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<Sqlite>, user: &str) -> Result<Option<WolvesVerify>, Error> {
async fn db_pending_clear_successful(pool: &Pool<Sqlite>, user: &UserId) -> Result<Option<WolvesVerify>, 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<Sqlite>, discord: &str, email: &str) -> Result<Option<Wolves>, Error> {
async fn set_discord(db: &Pool<Sqlite>, discord: &UserId, email: &str) -> Result<Option<Wolves>, 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<Sqlite>, 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<Sqlite>, discord: &str) -> Result<Vec<ServerMembersWolves>, Error> {
async fn get_servers(db: &Pool<Sqlite>, discord: &UserId) -> Result<Vec<ServerMembersWolves>, 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
}