Skip to content

Commit

Permalink
feat: reply command
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Aug 22, 2022
1 parent df52b24 commit e36df0e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/commands/misc.rs
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
}
1 change: 1 addition & 0 deletions src/commands/mod.rs
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;
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -49,6 +49,7 @@ async fn main() {
moderation::unmute(),
moderation::purge(),
moderation::ban(),
misc::reply(),
];
poise::set_qualified_names(&mut commands);

Expand Down

0 comments on commit e36df0e

Please sign in to comment.