approval system
This commit is contained in:
parent
ae34622647
commit
c20fb2e827
4 changed files with 46 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
use poise::CreateReply;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serenity::all::{ChannelId, CreateMessage, User};
|
||||
use serenity::all::{ChannelId, CreateActionRow, CreateButton, CreateMessage, ReactionType, User};
|
||||
use serenity::builder::CreateAllowedMentions;
|
||||
use sqlx::{Pool, query_as, Sqlite};
|
||||
|
||||
|
@ -36,7 +36,11 @@ pub(crate) async fn add(ctx: Context<'_>, ign: String) -> Result<(), Error> {
|
|||
ChannelId::new(1257776992497959075).send_message(ctx,
|
||||
CreateMessage::new()
|
||||
.content(s)
|
||||
.allowed_mentions(CreateAllowedMentions::new().empty_roles().empty_users())
|
||||
.allowed_mentions(CreateAllowedMentions::new().empty_roles().all_users(true))
|
||||
.components(vec![CreateActionRow::Buttons(vec![
|
||||
CreateButton::new("accept_verification").emoji(ReactionType::from('✅')),
|
||||
CreateButton::new("deny_verification").emoji(ReactionType::from('❌')),
|
||||
])])
|
||||
).await?;
|
||||
ctx.send(CreateReply::default().content("Linked accounts.")).await?;
|
||||
}
|
||||
|
|
31
src/handlers/bot_interaction.rs
Normal file
31
src/handlers/bot_interaction.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
use serenity::all::{ComponentInteraction, ComponentInteractionDataKind, Context, CreateMessage, GuildId, Interaction, RoleId};
|
||||
use crate::Error;
|
||||
|
||||
pub(crate) async fn component(ctx: &Context, interaction: &Interaction) -> Result<(), Error>{
|
||||
let component = interaction.clone().message_component().unwrap();
|
||||
match component.data.kind {
|
||||
ComponentInteractionDataKind::Button => button(ctx, component, ).await,
|
||||
_ => Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
async fn button(ctx: &Context, component: ComponentInteraction) -> Result<(), Error>{
|
||||
let m = component.message;
|
||||
let u = m.mentions.first().expect("Message did not mention a user.");
|
||||
match component.data.custom_id.as_str() {
|
||||
"accept_verification" => {
|
||||
let _dm = u.direct_message(ctx, CreateMessage::new()
|
||||
.content("Your verified minecraft account was approved.")).await?;
|
||||
let member = m.guild_id.unwrap_or(GuildId::new(1256217633959841853_u64)).member(ctx, u.id).await?;
|
||||
member.add_role(ctx, RoleId::new(1256218805911425066_u64)).await?;
|
||||
member.remove_role(ctx, RoleId::new(1256253358701023232_u64)).await?;
|
||||
Ok(())
|
||||
},
|
||||
"deny_verification" => {
|
||||
let _dm = u.direct_message(ctx, CreateMessage::new()
|
||||
.content("Your verified minecraft account was denied.")).await?;
|
||||
Ok(())
|
||||
}
|
||||
_ => Ok(())
|
||||
}
|
||||
}
|
1
src/handlers/mod.rs
Normal file
1
src/handlers/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub(crate) mod bot_interaction;
|
|
@ -7,12 +7,13 @@ use std::time::Duration;
|
|||
|
||||
use poise::serenity_prelude as serenity;
|
||||
use serenity::{FullEvent, model::id::UserId};
|
||||
use serenity::all::{ActivityData, RoleId};
|
||||
use serenity::all::{ActivityData, InteractionType, RoleId};
|
||||
use serenity::prelude::GatewayIntents;
|
||||
use sqlx::{Sqlite};
|
||||
use tokio::sync::RwLock;
|
||||
|
||||
mod commands;
|
||||
mod handlers;
|
||||
|
||||
struct Data {
|
||||
bots: Arc<RwLock<u8>>,
|
||||
|
@ -109,6 +110,12 @@ async fn event_handler(
|
|||
println!("gave member role");
|
||||
}
|
||||
},
|
||||
FullEvent::InteractionCreate {interaction} => {
|
||||
if interaction.application_id().get() == 1165594074473037824
|
||||
&& interaction.kind() == InteractionType::Component {
|
||||
handlers::bot_interaction::component(ctx, interaction).await?;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
|
|
Loading…
Add table
Reference in a new issue