Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions src/event_handler.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
28 changes: 27 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()
};

Expand Down