fix component id issue

This commit is contained in:
Stachelbeere1248 2025-07-02 19:31:05 +02:00
parent f06ef056c0
commit 5e81e07b05
Signed by: Stachelbeere1248
SSH key fingerprint: SHA256:IozEKdw2dB8TZxkpPdMxcWSoWTIMwoLaCcZJ1AJnY2o
3 changed files with 117 additions and 97 deletions

View file

@ -1,7 +1,8 @@
use poise::{ChoiceParameter, CreateReply}; use poise::{ChoiceParameter, CreateReply};
use reqwest::Client; use reqwest::Client;
use serenity::all::{ use serenity::all::{
ButtonStyle, ChannelId, CreateActionRow, CreateAllowedMentions, CreateButton, CreateEmbed, CreateMessage, ReactionType, User ButtonStyle, ChannelId, CreateActionRow, CreateAllowedMentions, CreateButton, CreateEmbed,
CreateMessage, ReactionType, User,
}; };
use sqlx::{Pool, Sqlite}; use sqlx::{Pool, Sqlite};
@ -55,7 +56,8 @@ pub(crate) async fn add(
} else { } else {
return Err(Error::Other( return Err(Error::Other(
"Force mode cannot be ran without specifying a different Discord account other than \ "Force mode cannot be ran without specifying a different Discord account other than \
your own.".to_string(), your own."
.to_string(),
)); ));
}); });
let uuid: Uuid = Uuid::for_ign( let uuid: Uuid = Uuid::for_ign(
@ -74,7 +76,11 @@ pub(crate) async fn add(
ChannelId::new(1257776992497959075_u64) ChannelId::new(1257776992497959075_u64)
.send_message( .send_message(
ctx, ctx,
create_verification_message(profile.arcade_stats().copied().unwrap_or_default(), &user, ign) create_verification_message(
profile.arcade_stats().copied().unwrap_or_default(),
&user,
ign,
),
) )
.await?; .await?;
done done
@ -87,7 +93,11 @@ pub(crate) async fn add(
ChannelId::new(1257776992497959075_u64) ChannelId::new(1257776992497959075_u64)
.send_message( .send_message(
ctx, ctx,
create_verification_message(profile.arcade_stats().copied().unwrap_or_default(), &user, ign) create_verification_message(
profile.arcade_stats().copied().unwrap_or_default(),
&user,
ign,
),
) )
.await?; .await?;
done done
@ -112,13 +122,13 @@ fn create_verification_message(stats: Arcade, user: &User, ign: String) -> Creat
.embed(embed) .embed(embed)
.allowed_mentions(CreateAllowedMentions::new().empty_roles().all_users(true)) .allowed_mentions(CreateAllowedMentions::new().empty_roles().all_users(true))
.components(vec![CreateActionRow::Buttons(vec![ .components(vec![CreateActionRow::Buttons(vec![
CreateButton::new("accept_verification") CreateButton::new(format!("acceptverification_{}", user.id.get()))
.emoji(ReactionType::from('✅')) .emoji(ReactionType::from('✅'))
.style(ButtonStyle::Secondary), .style(ButtonStyle::Secondary),
CreateButton::new("deny_verification") CreateButton::new(format!("denyverification_{}", user.id.get()))
.emoji(ReactionType::from('❌')) .emoji(ReactionType::from('❌'))
.style(ButtonStyle::Secondary), .style(ButtonStyle::Secondary),
CreateButton::new("list_accounts") CreateButton::new(format!("listaccounts_{}", user.id.get()))
.emoji(ReactionType::from('📜')) .emoji(ReactionType::from('📜'))
.style(ButtonStyle::Primary), .style(ButtonStyle::Primary),
])]) ])])

View file

@ -1,5 +1,5 @@
use poise::{CreateReply, FrameworkError}; use poise::{CreateReply, FrameworkError};
use std::fmt::{Display, Formatter, Result as FmtResult}; use std::{fmt::{Display, Formatter, Result as FmtResult}, num::ParseIntError};
use crate::Data; use crate::Data;
@ -42,6 +42,7 @@ pub enum Error {
OnCooldown(std::time::Duration), OnCooldown(std::time::Duration),
LinkingError(LinkingError), LinkingError(LinkingError),
Other(String), Other(String),
ParseInt(ParseIntError),
} }
impl Display for Error { impl Display for Error {
@ -57,6 +58,7 @@ impl Display for Error {
), ),
Self::LinkingError(l) => write!(f, "{l}"), Self::LinkingError(l) => write!(f, "{l}"),
Self::Other(s) => write!(f, "{s}"), Self::Other(s) => write!(f, "{s}"),
Self::ParseInt(e) => write!(f, "{e}"),
} }
} }
} }
@ -85,6 +87,12 @@ impl From<LinkingError> for Error {
} }
} }
impl From<ParseIntError> for Error {
fn from(value: ParseIntError) -> Self {
Self::ParseInt(value)
}
}
pub(crate) async fn handle_error(error: FrameworkError<'_, Data, Error>) { pub(crate) async fn handle_error(error: FrameworkError<'_, Data, Error>) {
match error { match error {
FrameworkError::Command { error, ctx, .. } => { FrameworkError::Command { error, ctx, .. } => {

View file

@ -10,6 +10,7 @@ use serenity::all::GuildId;
use serenity::all::Interaction; use serenity::all::Interaction;
use serenity::all::ReactionType; use serenity::all::ReactionType;
use serenity::all::RoleId; use serenity::all::RoleId;
use serenity::all::UserId;
use serenity::all::{ButtonStyle, ComponentInteraction}; use serenity::all::{ButtonStyle, ComponentInteraction};
use serenity::all::{ComponentInteractionDataKind, CreateInteractionResponse}; use serenity::all::{ComponentInteractionDataKind, CreateInteractionResponse};
@ -33,98 +34,99 @@ async fn button(
mut interaction: ComponentInteraction, mut interaction: ComponentInteraction,
data: &Data, data: &Data,
) -> Result<(), Error> { ) -> Result<(), Error> {
let u = interaction if let Some((id, uid)) = interaction.data.custom_id.as_str().split_once('_') {
.message let parsed_uid: u64 = uid.parse()?;
.mentions let u = UserId::new(parsed_uid);
.first() match id {
.expect("Message did not mention a user.") "acceptverification" => {
.id; let member = interaction
match interaction.data.custom_id.as_str() { .message
"accept_verification" => { .guild_id
let member = interaction .unwrap_or(GuildId::new(1256217633959841853_u64))
.message .member(ctx, u)
.guild_id .await?;
.unwrap_or(GuildId::new(1256217633959841853_u64)) let (_, _, _dm, _) = futures::try_join!(
.member(ctx, u) member.add_role(ctx, RoleId::new(1256218805911425066_u64)),
.await?; member.remove_role(ctx, RoleId::new(1256253358701023232_u64)),
let (_, _, _dm, _) = futures::try_join!( u.direct_message(
member.add_role(ctx, RoleId::new(1256218805911425066_u64)), ctx,
member.remove_role(ctx, RoleId::new(1256253358701023232_u64)), CreateMessage::new()
u.direct_message( .content("Your verified minecraft account was approved.")
ctx,
CreateMessage::new().content("Your verified minecraft account was approved.")
),
interaction.message.edit(
ctx,
EditMessage::new().components(vec![CreateActionRow::Buttons(vec![
CreateButton::new("accept_verification")
.emoji(ReactionType::from('✅'))
.style(Success)
.disabled(true),
CreateButton::new("deny_verification")
.emoji(ReactionType::from('❌'))
.style(ButtonStyle::Secondary)
.disabled(true),
CreateButton::new("list_accounts")
.emoji(ReactionType::from('📜'))
.style(ButtonStyle::Primary),
])]),
)
)?;
interaction
.create_response(ctx, CreateInteractionResponse::Acknowledge)
.await?;
Ok(())
}
"deny_verification" => {
let (_dm, _) = futures::try_join!(
u.direct_message(
ctx,
CreateMessage::new().content("Your verified minecraft account was denied.")
),
interaction.message.edit(
ctx,
EditMessage::new().components(vec![CreateActionRow::Buttons(vec![
CreateButton::new("accept_verification")
.emoji(ReactionType::from('✅'))
.style(ButtonStyle::Secondary)
.disabled(true),
CreateButton::new("deny_verification")
.emoji(ReactionType::from('❌'))
.style(ButtonStyle::Danger)
.disabled(true),
CreateButton::new("list_accounts")
.emoji(ReactionType::from('📜'))
.style(ButtonStyle::Primary),
])]),
)
)?;
interaction
.create_response(ctx, CreateInteractionResponse::Acknowledge)
.await?;
Ok(())
}
"list_accounts" => {
let user = interaction.message.mentions.first().unwrap();
let s: String = crate::commands::accountv2::list_string(
&data.sqlite_pool,
user,
&data.caches,
&data.clients.general,
)
.await?;
interaction
.create_response(
ctx,
Message(
CreateInteractionResponseMessage::new()
.content(s)
.ephemeral(true),
), ),
interaction.message.edit(
ctx,
EditMessage::new().components(vec![CreateActionRow::Buttons(vec![
CreateButton::new(format!("accepted_{uid}"))
.emoji(ReactionType::from('✅'))
.style(Success)
.disabled(true),
CreateButton::new(format!("undenied_{uid}"))
.emoji(ReactionType::from('❌'))
.style(ButtonStyle::Secondary)
.disabled(true),
CreateButton::new(format!("listaccounts_{uid}"))
.emoji(ReactionType::from('📜'))
.style(ButtonStyle::Primary),
])]),
)
)?;
interaction
.create_response(ctx, CreateInteractionResponse::Acknowledge)
.await?;
Ok(())
}
"denyverification" => {
let (_dm, _) = futures::try_join!(
u.direct_message(
ctx,
CreateMessage::new().content("Your verified minecraft account was denied.")
),
interaction.message.edit(
ctx,
EditMessage::new().components(vec![CreateActionRow::Buttons(vec![
CreateButton::new(format!("unaccepted_{uid}"))
.emoji(ReactionType::from('✅'))
.style(ButtonStyle::Secondary)
.disabled(true),
CreateButton::new(format!("denied_{uid}"))
.emoji(ReactionType::from('❌'))
.style(ButtonStyle::Danger)
.disabled(true),
CreateButton::new(format!("listaccounts_{uid}"))
.emoji(ReactionType::from('📜'))
.style(ButtonStyle::Primary),
])]),
)
)?;
interaction
.create_response(ctx, CreateInteractionResponse::Acknowledge)
.await?;
Ok(())
}
"listaccounts" => {
let user = interaction.message.mentions.first().unwrap();
let s: String = crate::commands::accountv2::list_string(
&data.sqlite_pool,
user,
&data.caches,
&data.clients.general,
) )
.await?; .await?;
Ok(()) interaction
.create_response(
ctx,
Message(
CreateInteractionResponseMessage::new()
.content(s)
.ephemeral(true),
),
)
.await?;
Ok(())
}
_ => Ok(()),
} }
_ => Ok(()), } else {
Ok(())
} }
} }