fix force mode

This commit is contained in:
Stachelbeere1248 2025-07-21 16:21:01 +02:00
parent ca9f5fc542
commit 6ff6986b0d
Signed by: Stachelbeere1248
SSH key fingerprint: SHA256:IozEKdw2dB8TZxkpPdMxcWSoWTIMwoLaCcZJ1AJnY2o
2 changed files with 29 additions and 14 deletions

View file

@ -51,15 +51,27 @@ pub(crate) async fn add(
} else { } else {
Mode::Normal Mode::Normal
}; };
let user: User = target.unwrap_or(if mode == Mode::Normal {
ctx.author().clone() let user = if let Some(u) = target.as_ref() {
if !u.eq(ctx.author()) {
Ok(u)
} else {
Err(Error::Other(
"Force mode cannot be ran without specifying a different Discord account other \
than your own."
.to_string(),
))
}
} else { } else {
return Err(Error::Other( if mode != Mode::Normal {
"Force mode cannot be ran without specifying a different Discord account other than \ Err(Error::Other(
your own." "Force mode cannot be ran without specifying a target."
.to_string(), .to_string(),
)); ))
}); } else {
Ok(ctx.author())
}
}?;
let uuid: Uuid = Uuid::for_ign( let uuid: Uuid = Uuid::for_ign(
ign.as_str(), ign.as_str(),
&ctx.data().clients.general, &ctx.data().clients.general,
@ -72,13 +84,13 @@ pub(crate) async fn add(
.hypixel_player_data(&ctx.data().clients.hypixel_api_client) .hypixel_player_data(&ctx.data().clients.hypixel_api_client)
.await? .await?
.map_if_discord(user.name.as_str())?; .map_if_discord(user.name.as_str())?;
let done = link(&ctx.data().sqlite_pool, uuid, &user).await?; let done = link(&ctx.data().sqlite_pool, uuid, user).await?;
ChannelId::new(1257776992497959075_u64) ChannelId::new(1257776992497959075_u64)
.send_message( .send_message(
ctx, ctx,
create_verification_message( create_verification_message(
profile.arcade_stats().copied().unwrap_or_default(), profile.arcade_stats().copied().unwrap_or_default(),
&user, user,
ign, ign,
), ),
) )
@ -89,13 +101,13 @@ pub(crate) async fn add(
let profile = uuid let profile = uuid
.hypixel_player_data(&ctx.data().clients.hypixel_api_client) .hypixel_player_data(&ctx.data().clients.hypixel_api_client)
.await?; .await?;
let done = link(&ctx.data().sqlite_pool, uuid, &user).await?; let done = link(&ctx.data().sqlite_pool, uuid, user).await?;
ChannelId::new(1257776992497959075_u64) ChannelId::new(1257776992497959075_u64)
.send_message( .send_message(
ctx, ctx,
create_verification_message( create_verification_message(
profile.arcade_stats().copied().unwrap_or_default(), profile.arcade_stats().copied().unwrap_or_default(),
&user, user,
ign, ign,
), ),
) )
@ -103,7 +115,7 @@ pub(crate) async fn add(
done done
} }
Mode::NoApi => { Mode::NoApi => {
let done = link(&ctx.data().sqlite_pool, uuid, &user).await?; let done = link(&ctx.data().sqlite_pool, uuid, user).await?;
done done
} }
}; };

View file

@ -1,5 +1,8 @@
use poise::{CreateReply, FrameworkError}; use poise::{CreateReply, FrameworkError};
use std::{fmt::{Display, Formatter, Result as FmtResult}, num::ParseIntError}; use std::{
fmt::{Display, Formatter, Result as FmtResult},
num::ParseIntError,
};
use crate::Data; use crate::Data;