feat(emergency-report): add emergency report
This commit is contained in:
parent
4ef46faae4
commit
162a1420db
3 changed files with 80 additions and 1 deletions
|
|
@ -10,7 +10,6 @@ debug = "none"
|
||||||
debug-assertions = false
|
debug-assertions = false
|
||||||
strip = true
|
strip = true
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
lto="fat"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
78
src/emergency_report.rs
Normal file
78
src/emergency_report.rs
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
use serenity::all::{ChannelId, Colour, Command, CommandId, Context, CreateCommand, CreateEmbed, CreateEmbedAuthor, CreateInputText, CreateInteractionResponse, CreateInteractionResponseFollowup, CreateInteractionResponseMessage, CreateMessage, CreateQuickModal, EventHandler, InputTextStyle, Interaction, Message, Ready, Timestamp};
|
||||||
|
use serenity::all::Change::Color;
|
||||||
|
use serenity::async_trait;
|
||||||
|
use tokio::sync::OnceCell;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
pub struct EmergencyReportHandler{
|
||||||
|
command_id: OnceCell<CommandId>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl EventHandler for EmergencyReportHandler {
|
||||||
|
async fn ready(&self, ctx: Context, data_about_bot: Ready) {
|
||||||
|
let command = CreateCommand::new("emergency-report")
|
||||||
|
.description("Report an emergency (e.g. server down) ONLY if its happening for everyone not if its just for you.");
|
||||||
|
|
||||||
|
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 main_field = CreateInputText::new(
|
||||||
|
InputTextStyle::Paragraph,
|
||||||
|
"What is happening",
|
||||||
|
"MAIN_CONTENT"
|
||||||
|
).required(true).min_length(10);
|
||||||
|
|
||||||
|
let modal = CreateQuickModal::new("Emergency Report Form")
|
||||||
|
.field(main_field);
|
||||||
|
|
||||||
|
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("report has been sent to the admins")
|
||||||
|
)).await.ok();
|
||||||
|
|
||||||
|
let text = &response.inputs[0];
|
||||||
|
|
||||||
|
let emergency_channel = ChannelId::new(1286724627413864562);
|
||||||
|
|
||||||
|
let mut author = CreateEmbedAuthor::from(response.interaction.user);
|
||||||
|
|
||||||
|
let embed = CreateEmbed::new()
|
||||||
|
.title("AN EMERGENCY HAS BEEN REPORTED")
|
||||||
|
.description(text)
|
||||||
|
.timestamp(Timestamp::now())
|
||||||
|
.author(author)
|
||||||
|
.color(Colour::RED);
|
||||||
|
|
||||||
|
let message = CreateMessage::new()
|
||||||
|
.content("@everyone")
|
||||||
|
.add_embed(embed);
|
||||||
|
|
||||||
|
emergency_channel.send_message(&ctx.http, message).await.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ mod cheeseburger;
|
||||||
mod ayy;
|
mod ayy;
|
||||||
mod miiverse_mod_application;
|
mod miiverse_mod_application;
|
||||||
mod too_fat;
|
mod too_fat;
|
||||||
|
mod emergency_report;
|
||||||
|
|
||||||
use std::env;
|
use std::env;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
@ -28,6 +29,7 @@ async fn main() {
|
||||||
.event_handler(ayy::AyyHandler)
|
.event_handler(ayy::AyyHandler)
|
||||||
.event_handler(cheeseburger::CheeseburgerHandler)
|
.event_handler(cheeseburger::CheeseburgerHandler)
|
||||||
.event_handler(too_fat::TooFatHandler)
|
.event_handler(too_fat::TooFatHandler)
|
||||||
|
.event_handler(emergency_report::EmergencyReportHandler::default())
|
||||||
//.event_handler(miiverse_mod_application::MiiverseModApplicationHandler::default())
|
//.event_handler(miiverse_mod_application::MiiverseModApplicationHandler::default())
|
||||||
.await.expect("unable to create client");
|
.await.expect("unable to create client");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue