feat: reply command

This commit is contained in:
oSumAtrIX 2022-08-22 03:36:58 +02:00
parent df52b24b8d
commit e36df0e9f7
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
3 changed files with 49 additions and 1 deletions

46
src/commands/misc.rs Normal file
View File

@ -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<String>,
#[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::<u64>() {
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<ReplyHandle<'a>, serenity::Error> {
ctx.send(|f| f.ephemeral(true).content(content)).await
}

View File

@ -1,3 +1,4 @@
pub mod configuration;
pub mod moderation;
pub mod utils;
pub mod misc;

View File

@ -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);