diff --git a/src/commands/misc.rs b/src/commands/misc.rs new file mode 100644 index 0000000..037450d --- /dev/null +++ b/src/commands/misc.rs @@ -0,0 +1,46 @@ +use poise::serenity_prelude::{self as serenity, MessageId}; +use poise::ReplyHandle; + +use crate::{Context, Error}; + +/// Make the Discord bot sentient. +#[poise::command(slash_command)] +pub async fn reply( + ctx: Context<'_>, + #[description = "The message id to reply to"] reply_message: Option, + #[description = "The message to send"] message: String, +) -> Result<(), Error> { + let http = &ctx.discord().http; + let channel = &ctx.channel_id(); + + if let Some(reply_message) = reply_message { + if let Ok(reply_message) = reply_message.parse::() { + match channel.message(http, MessageId(reply_message)).await { + Ok(reply_message) => { + reply_message.reply(http, &message).await?; + }, + Err(_) => { + send_ephermal( + &ctx, + "The message you are trying to reply to does not exist.", + ) + .await?; + }, + } + } else { + send_ephermal(&ctx, "Invalid message id.").await?; + } + } else { + channel.say(http, &message).await?; + } + + send_ephermal(&ctx, &format!("Response: {}", message)).await?; + Ok(()) +} + +async fn send_ephermal<'a>( + ctx: &Context<'a>, + content: &str, +) -> Result, serenity::Error> { + ctx.send(|f| f.ephemeral(true).content(content)).await +} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 4f527dc..105fd8b 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,3 +1,4 @@ pub mod configuration; pub mod moderation; pub mod utils; +pub mod misc; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 8113f52..45b6eaf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use std::env; use std::sync::Arc; -use commands::{configuration, moderation}; +use commands::{configuration, misc, moderation}; use db::database::Database; use events::Handler; use poise::serenity_prelude::{self as serenity, RwLock, UserId}; @@ -49,6 +49,7 @@ async fn main() { moderation::unmute(), moderation::purge(), moderation::ban(), + misc::reply(), ]; poise::set_qualified_names(&mut commands);