fix: use EMERGENCY_CHANNEL_ID instead of hardcoding channel IDs
All checks were successful
Build and Test / splatie (push) Successful in 10m14s
All checks were successful
Build and Test / splatie (push) Successful in 10m14s
This commit is contained in:
parent
c0f300a958
commit
189a36989d
1 changed files with 31 additions and 16 deletions
|
|
@ -1,20 +1,38 @@
|
||||||
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::{ChannelId, Colour, Command, CommandId, Context, CreateCommand, CreateEmbed, CreateEmbedAuthor, CreateInputText, CreateInteractionResponse, CreateInteractionResponseMessage, CreateMessage, CreateQuickModal, EventHandler, InputTextStyle, Interaction, Ready, Timestamp};
|
||||||
use serenity::all::Change::Color;
|
|
||||||
use serenity::async_trait;
|
use serenity::async_trait;
|
||||||
use tokio::sync::OnceCell;
|
use tokio::sync::OnceCell;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
pub struct EmergencyReportHandler {
|
pub struct EmergencyReportHandler {
|
||||||
command_id: OnceCell<CommandId>
|
command_id: OnceCell<CommandId>,
|
||||||
|
emergency_channel_id: ChannelId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for EmergencyReportHandler {
|
||||||
|
fn default() -> Self {
|
||||||
|
let channel_str = env::var("EMERGENCY_CHANNEL_ID")
|
||||||
|
.expect("EMERGENCY_CHANNEL_ID must be set in .env");
|
||||||
|
|
||||||
|
let id: u64 = channel_str
|
||||||
|
.parse()
|
||||||
|
.expect("EMERGENCY_CHANNEL_ID must be a valid u64");
|
||||||
|
|
||||||
|
Self {
|
||||||
|
command_id: OnceCell::new(),
|
||||||
|
emergency_channel_id: ChannelId::new(id),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for EmergencyReportHandler {
|
impl EventHandler for EmergencyReportHandler {
|
||||||
async fn ready(&self, ctx: Context, data_about_bot: Ready) {
|
async fn ready(&self, ctx: Context, _data_about_bot: Ready) {
|
||||||
let command = CreateCommand::new("emergency-report")
|
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.");
|
.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");
|
let cmd = Command::create_global_command(&ctx.http, command)
|
||||||
|
.await
|
||||||
|
.expect("unable to register command");
|
||||||
|
|
||||||
self.command_id.set(cmd.id).ok();
|
self.command_id.set(cmd.id).ok();
|
||||||
}
|
}
|
||||||
|
|
@ -43,11 +61,11 @@ impl EventHandler for EmergencyReportHandler {
|
||||||
|
|
||||||
let response = match cmd.quick_modal(&ctx, modal).await {
|
let response = match cmd.quick_modal(&ctx, modal).await {
|
||||||
Ok(v) => v,
|
Ok(v) => v,
|
||||||
Err(e) => { eprintln!("{}", e); return }
|
Err(e) => { eprintln!("Modal error: {}", e); return }
|
||||||
};
|
};
|
||||||
|
|
||||||
let Some(response) = response else {
|
let Some(response) = response else {
|
||||||
return
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
response.interaction.create_response(&ctx.http, CreateInteractionResponse::Message(
|
response.interaction.create_response(&ctx.http, CreateInteractionResponse::Message(
|
||||||
|
|
@ -57,10 +75,7 @@ impl EventHandler for EmergencyReportHandler {
|
||||||
)).await.ok();
|
)).await.ok();
|
||||||
|
|
||||||
let text = &response.inputs[0];
|
let text = &response.inputs[0];
|
||||||
|
let author = CreateEmbedAuthor::from(response.interaction.user.clone());
|
||||||
let emergency_channel = ChannelId::new(1379768148420591666);
|
|
||||||
|
|
||||||
let mut author = CreateEmbedAuthor::from(response.interaction.user);
|
|
||||||
|
|
||||||
let embed = CreateEmbed::new()
|
let embed = CreateEmbed::new()
|
||||||
.title("AN EMERGENCY HAS BEEN REPORTED")
|
.title("AN EMERGENCY HAS BEEN REPORTED")
|
||||||
|
|
@ -73,6 +88,6 @@ impl EventHandler for EmergencyReportHandler {
|
||||||
.content("@everyone")
|
.content("@everyone")
|
||||||
.add_embed(embed);
|
.add_embed(embed);
|
||||||
|
|
||||||
emergency_channel.send_message(&ctx.http, message).await.ok();
|
self.emergency_channel_id.send_message(&ctx.http, message).await.ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue