fix component id issue
This commit is contained in:
parent
f06ef056c0
commit
5e81e07b05
3 changed files with 117 additions and 97 deletions
|
@ -1,7 +1,8 @@
|
|||
use poise::{ChoiceParameter, CreateReply};
|
||||
use reqwest::Client;
|
||||
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};
|
||||
|
||||
|
@ -55,7 +56,8 @@ pub(crate) async fn add(
|
|||
} else {
|
||||
return Err(Error::Other(
|
||||
"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(
|
||||
|
@ -74,7 +76,11 @@ pub(crate) async fn add(
|
|||
ChannelId::new(1257776992497959075_u64)
|
||||
.send_message(
|
||||
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?;
|
||||
done
|
||||
|
@ -87,7 +93,11 @@ pub(crate) async fn add(
|
|||
ChannelId::new(1257776992497959075_u64)
|
||||
.send_message(
|
||||
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?;
|
||||
done
|
||||
|
@ -112,13 +122,13 @@ fn create_verification_message(stats: Arcade, user: &User, ign: String) -> Creat
|
|||
.embed(embed)
|
||||
.allowed_mentions(CreateAllowedMentions::new().empty_roles().all_users(true))
|
||||
.components(vec![CreateActionRow::Buttons(vec![
|
||||
CreateButton::new("accept_verification")
|
||||
CreateButton::new(format!("acceptverification_{}", user.id.get()))
|
||||
.emoji(ReactionType::from('✅'))
|
||||
.style(ButtonStyle::Secondary),
|
||||
CreateButton::new("deny_verification")
|
||||
CreateButton::new(format!("denyverification_{}", user.id.get()))
|
||||
.emoji(ReactionType::from('❌'))
|
||||
.style(ButtonStyle::Secondary),
|
||||
CreateButton::new("list_accounts")
|
||||
CreateButton::new(format!("listaccounts_{}", user.id.get()))
|
||||
.emoji(ReactionType::from('📜'))
|
||||
.style(ButtonStyle::Primary),
|
||||
])])
|
||||
|
|
10
src/error.rs
10
src/error.rs
|
@ -1,5 +1,5 @@
|
|||
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;
|
||||
|
||||
|
@ -42,6 +42,7 @@ pub enum Error {
|
|||
OnCooldown(std::time::Duration),
|
||||
LinkingError(LinkingError),
|
||||
Other(String),
|
||||
ParseInt(ParseIntError),
|
||||
}
|
||||
|
||||
impl Display for Error {
|
||||
|
@ -57,6 +58,7 @@ impl Display for Error {
|
|||
),
|
||||
Self::LinkingError(l) => write!(f, "{l}"),
|
||||
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>) {
|
||||
match error {
|
||||
FrameworkError::Command { error, ctx, .. } => {
|
||||
|
|
|
@ -10,6 +10,7 @@ use serenity::all::GuildId;
|
|||
use serenity::all::Interaction;
|
||||
use serenity::all::ReactionType;
|
||||
use serenity::all::RoleId;
|
||||
use serenity::all::UserId;
|
||||
use serenity::all::{ButtonStyle, ComponentInteraction};
|
||||
use serenity::all::{ComponentInteractionDataKind, CreateInteractionResponse};
|
||||
|
||||
|
@ -33,98 +34,99 @@ async fn button(
|
|||
mut interaction: ComponentInteraction,
|
||||
data: &Data,
|
||||
) -> Result<(), Error> {
|
||||
let u = interaction
|
||||
.message
|
||||
.mentions
|
||||
.first()
|
||||
.expect("Message did not mention a user.")
|
||||
.id;
|
||||
match interaction.data.custom_id.as_str() {
|
||||
"accept_verification" => {
|
||||
let member = interaction
|
||||
.message
|
||||
.guild_id
|
||||
.unwrap_or(GuildId::new(1256217633959841853_u64))
|
||||
.member(ctx, u)
|
||||
.await?;
|
||||
let (_, _, _dm, _) = futures::try_join!(
|
||||
member.add_role(ctx, RoleId::new(1256218805911425066_u64)),
|
||||
member.remove_role(ctx, RoleId::new(1256253358701023232_u64)),
|
||||
u.direct_message(
|
||||
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),
|
||||
if let Some((id, uid)) = interaction.data.custom_id.as_str().split_once('_') {
|
||||
let parsed_uid: u64 = uid.parse()?;
|
||||
let u = UserId::new(parsed_uid);
|
||||
match id {
|
||||
"acceptverification" => {
|
||||
let member = interaction
|
||||
.message
|
||||
.guild_id
|
||||
.unwrap_or(GuildId::new(1256217633959841853_u64))
|
||||
.member(ctx, u)
|
||||
.await?;
|
||||
let (_, _, _dm, _) = futures::try_join!(
|
||||
member.add_role(ctx, RoleId::new(1256218805911425066_u64)),
|
||||
member.remove_role(ctx, RoleId::new(1256253358701023232_u64)),
|
||||
u.direct_message(
|
||||
ctx,
|
||||
CreateMessage::new()
|
||||
.content("Your verified minecraft account was approved.")
|
||||
),
|
||||
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?;
|
||||
Ok(())
|
||||
interaction
|
||||
.create_response(
|
||||
ctx,
|
||||
Message(
|
||||
CreateInteractionResponseMessage::new()
|
||||
.content(s)
|
||||
.ephemeral(true),
|
||||
),
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
_ => Ok(()),
|
||||
}
|
||||
_ => Ok(()),
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue