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 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),
|
||||||
])])
|
])])
|
||||||
|
|
10
src/error.rs
10
src/error.rs
|
@ -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, .. } => {
|
||||||
|
|
|
@ -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,14 +34,11 @@ 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;
|
|
||||||
match interaction.data.custom_id.as_str() {
|
|
||||||
"accept_verification" => {
|
|
||||||
let member = interaction
|
let member = interaction
|
||||||
.message
|
.message
|
||||||
.guild_id
|
.guild_id
|
||||||
|
@ -52,20 +50,21 @@ async fn button(
|
||||||
member.remove_role(ctx, RoleId::new(1256253358701023232_u64)),
|
member.remove_role(ctx, RoleId::new(1256253358701023232_u64)),
|
||||||
u.direct_message(
|
u.direct_message(
|
||||||
ctx,
|
ctx,
|
||||||
CreateMessage::new().content("Your verified minecraft account was approved.")
|
CreateMessage::new()
|
||||||
|
.content("Your verified minecraft account was approved.")
|
||||||
),
|
),
|
||||||
interaction.message.edit(
|
interaction.message.edit(
|
||||||
ctx,
|
ctx,
|
||||||
EditMessage::new().components(vec![CreateActionRow::Buttons(vec![
|
EditMessage::new().components(vec![CreateActionRow::Buttons(vec![
|
||||||
CreateButton::new("accept_verification")
|
CreateButton::new(format!("accepted_{uid}"))
|
||||||
.emoji(ReactionType::from('✅'))
|
.emoji(ReactionType::from('✅'))
|
||||||
.style(Success)
|
.style(Success)
|
||||||
.disabled(true),
|
.disabled(true),
|
||||||
CreateButton::new("deny_verification")
|
CreateButton::new(format!("undenied_{uid}"))
|
||||||
.emoji(ReactionType::from('❌'))
|
.emoji(ReactionType::from('❌'))
|
||||||
.style(ButtonStyle::Secondary)
|
.style(ButtonStyle::Secondary)
|
||||||
.disabled(true),
|
.disabled(true),
|
||||||
CreateButton::new("list_accounts")
|
CreateButton::new(format!("listaccounts_{uid}"))
|
||||||
.emoji(ReactionType::from('📜'))
|
.emoji(ReactionType::from('📜'))
|
||||||
.style(ButtonStyle::Primary),
|
.style(ButtonStyle::Primary),
|
||||||
])]),
|
])]),
|
||||||
|
@ -76,7 +75,7 @@ async fn button(
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
"deny_verification" => {
|
"denyverification" => {
|
||||||
let (_dm, _) = futures::try_join!(
|
let (_dm, _) = futures::try_join!(
|
||||||
u.direct_message(
|
u.direct_message(
|
||||||
ctx,
|
ctx,
|
||||||
|
@ -85,15 +84,15 @@ async fn button(
|
||||||
interaction.message.edit(
|
interaction.message.edit(
|
||||||
ctx,
|
ctx,
|
||||||
EditMessage::new().components(vec![CreateActionRow::Buttons(vec![
|
EditMessage::new().components(vec![CreateActionRow::Buttons(vec![
|
||||||
CreateButton::new("accept_verification")
|
CreateButton::new(format!("unaccepted_{uid}"))
|
||||||
.emoji(ReactionType::from('✅'))
|
.emoji(ReactionType::from('✅'))
|
||||||
.style(ButtonStyle::Secondary)
|
.style(ButtonStyle::Secondary)
|
||||||
.disabled(true),
|
.disabled(true),
|
||||||
CreateButton::new("deny_verification")
|
CreateButton::new(format!("denied_{uid}"))
|
||||||
.emoji(ReactionType::from('❌'))
|
.emoji(ReactionType::from('❌'))
|
||||||
.style(ButtonStyle::Danger)
|
.style(ButtonStyle::Danger)
|
||||||
.disabled(true),
|
.disabled(true),
|
||||||
CreateButton::new("list_accounts")
|
CreateButton::new(format!("listaccounts_{uid}"))
|
||||||
.emoji(ReactionType::from('📜'))
|
.emoji(ReactionType::from('📜'))
|
||||||
.style(ButtonStyle::Primary),
|
.style(ButtonStyle::Primary),
|
||||||
])]),
|
])]),
|
||||||
|
@ -104,7 +103,7 @@ async fn button(
|
||||||
.await?;
|
.await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
"list_accounts" => {
|
"listaccounts" => {
|
||||||
let user = interaction.message.mentions.first().unwrap();
|
let user = interaction.message.mentions.first().unwrap();
|
||||||
let s: String = crate::commands::accountv2::list_string(
|
let s: String = crate::commands::accountv2::list_string(
|
||||||
&data.sqlite_pool,
|
&data.sqlite_pool,
|
||||||
|
@ -127,4 +126,7 @@ async fn button(
|
||||||
}
|
}
|
||||||
_ => Ok(()),
|
_ => Ok(()),
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue