forked from ReVanced/revanced-discord-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod configuration; | ||
pub mod moderation; | ||
pub mod utils; | ||
pub mod misc; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters