diff --git a/README.md b/README.md index 2c00731..5531822 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Shows a help message, either for all commands or for a specific command. Add one or more candidate IDs to the candidates database from a text file. -**Permissions:** `MANAGE_MESSAGES` or `MANAGE_THREADS` +**Permissions:** `Moderator` **Parameters:** * `id`: A text file with candidate IDs (one per line, UTF-8). @@ -74,7 +74,7 @@ Add one or more candidate IDs to the candidates database from a text file. Delete a candidate by ID from the candidates database. -**Permissions:** `MANAGE_MESSAGES` or `MANAGE_THREADS` +**Permissions:** `Moderator` **Parameters:** * `id`: The ID of the candidate to delete. diff --git a/src/event_handler.rs b/src/event_handler.rs new file mode 100644 index 0000000..684d413 --- /dev/null +++ b/src/event_handler.rs @@ -0,0 +1,17 @@ +use anyhow::{Error, Result}; +use poise::serenity_prelude as serenity; + +use crate::State; + +pub async fn event_handler( + _: &serenity::Context, + event: &serenity::FullEvent, + _framework: poise::FrameworkContext<'_, State, Error>, + _: &State, +) -> Result<()> { + if let serenity::FullEvent::Ready { data_about_bot, .. } = event { + tracing::info!("Logged in as {}", data_about_bot.user.name); + } + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs index 03e0faf..edb42a1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ pub mod check; pub mod command; pub mod config; pub mod database; +pub mod event_handler; pub mod message; pub mod state; pub mod util; @@ -10,7 +11,7 @@ use std::sync::Arc; use std::time::Duration; use poise::serenity_prelude::{Client, GatewayIntents}; -use poise::{Framework, FrameworkOptions}; +use poise::{CreateReply, Framework, FrameworkOptions}; pub use crate::config::Config; pub use crate::message::Message; @@ -38,6 +39,31 @@ pub async fn build_bot() -> anyhow::Result<()> { ))), ..Default::default() }, + event_handler: |ctx, event, framework, data| { + Box::pin(event_handler::event_handler(ctx, event, framework, data)) + }, + on_error: |error| { + Box::pin(async move { + if let poise::FrameworkError::Command { ctx, .. } = error { + let _ = ctx + .send( + CreateReply::default() + .content(Message::Error) + .ephemeral(true), + ) + .await; + + return; + } + + if let poise::FrameworkError::Setup { error, .. } = error { + tracing::error!("Framework setup error: {:?}", error); + return; + } + + tracing::error!("Other framework error (no user context to reply to)."); + }) + }, ..Default::default() };