You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2b-rs/src/utils/mod.rs

28 lines
729 B
Rust

use serenity::client::Context;
use serenity::model::channel::Message;
use crate::utils::error::BotResult;
pub(crate) mod context_data;
pub(crate) mod error;
pub(crate) mod logging;
pub(crate) mod messages;
/// Returns the message the given message is a reply to or the message sent before that
pub async fn get_previous_message_or_reply(
ctx: &Context,
msg: &Message,
) -> BotResult<Option<Message>> {
let referenced = if let Some(reference) = &msg.referenced_message {
Some(*reference.clone())
} else {
let messages = msg
.channel_id
.messages(ctx, |ret| ret.before(&msg.id).limit(1))
.await?;
messages.first().cloned()
};
Ok(referenced)
}