mirror of
https://github.com/revanced/revanced-discord-bot.git
synced 2025-04-30 14:34:29 +02:00
feat: reply command
This commit is contained in:
parent
df52b24b8d
commit
e36df0e9f7
46
src/commands/misc.rs
Normal file
46
src/commands/misc.rs
Normal 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
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
pub mod configuration;
|
||||
pub mod moderation;
|
||||
pub mod utils;
|
||||
pub mod misc;
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user