refactor: simplify code, better organize it, and comment it
This commit is contained in:
34
src/discord/events/mod.rs
Normal file
34
src/discord/events/mod.rs
Normal file
@@ -0,0 +1,34 @@
|
||||
use super::{utils::BotData, Error, Result};
|
||||
|
||||
use poise::{
|
||||
serenity_prelude::{self as serenity},
|
||||
Event,
|
||||
};
|
||||
use tracing::info;
|
||||
|
||||
mod everyone;
|
||||
use everyone::handle_everyone_mention;
|
||||
|
||||
/// Function handling events the bot can see.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function will return an error if one of the functions error
|
||||
/// themselves.
|
||||
pub async fn event_handler(
|
||||
ctx: &serenity::Context,
|
||||
event: &Event<'_>,
|
||||
_framework: poise::FrameworkContext<'_, BotData, Error>,
|
||||
data: &BotData,
|
||||
) -> Result {
|
||||
match event {
|
||||
Event::Ready { data_about_bot } => {
|
||||
info!("Logged in as {}", data_about_bot.user.name);
|
||||
}
|
||||
Event::Message { new_message } => {
|
||||
handle_everyone_mention(ctx, &data.database, new_message).await?;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user