spacebot/src/miiverse_mod_application.rs
red binder c87562b36a
All checks were successful
Build and Test / splatie (push) Successful in 6m10s
fix the commands name
2026-05-13 10:00:35 +02:00

78 lines
2.8 KiB
Rust

use serenity::all::{ActivityData, ActivityType, ChannelId, Colour, Command, CommandId, Context, CreateCommand, CreateEmbed, CreateEmbedAuthor, CreateInputText, CreateInteractionResponse, CreateInteractionResponseMessage, CreateMessage, CreateQuickModal, EventHandler, Guild, GuildId, InputTextStyle, Interaction, Message, Ready, Timestamp};
use serenity::async_trait;
use tokio::sync::OnceCell;
#[derive(Default)]
pub struct MiiverseModApplicationHandler{
command_id: OnceCell<CommandId>
}
#[async_trait]
impl EventHandler for MiiverseModApplicationHandler {
async fn ready(&self, ctx: Context, data_about_bot: Ready) {
let command = CreateCommand::new("mod-application")
.description("Apply for moderator");
let cmd = Command::create_global_command(&ctx.http, command).await.expect("unable to register command");
self.command_id.set(cmd.id).ok();
}
async fn interaction_create(&self, ctx: Context, interaction: Interaction) {
let Interaction::Command(cmd) = interaction else {
return;
};
let Some(id) = self.command_id.get() else {
return;
};
if cmd.data.id != *id{
return;
}
let modal = CreateQuickModal::new("Moderator Application Form")
.short_field("What is your timezone?")
.short_field("How long are you usually availible every day?")
.paragraph_field("Why should we pick you?")
.paragraph_field("What could you contribute to the mod team?");
let response = match cmd.quick_modal(&ctx, modal).await{
Ok(v) => v,
Err(e) => { eprintln!("{}", e); return }
};
let Some(response) = response else {
return
};
response.interaction.create_response(&ctx.http, CreateInteractionResponse::Message(
CreateInteractionResponseMessage::new()
.ephemeral(true)
.content("Application has been sent!")
)).await.ok();
let emergency_channel = ChannelId::new(1504018819071610970);
let mut author = CreateEmbedAuthor::from(response.interaction.user);
let embed = CreateEmbed::new()
.title("Moderator Application")
.field("Whats your timezone?", &response.inputs[0], false)
.field("How long are you usually availible every day?", &response.inputs[1], false)
.field("Why should we pick you?", &response.inputs[2], false)
.field("What could you contribute to the mod team?", &response.inputs[3], false)
.timestamp(Timestamp::now())
.author(author)
.color(Colour::DARK_GREEN);
let message = CreateMessage::new()
.add_embed(embed);
emergency_channel.send_message(&ctx.http, message).await.ok();
}
}