1
0
Fork 0

Override default manifold handlers for message edits and deletions

This commit is contained in:
Lucy Bladen 2025-05-04 12:14:34 +01:00
parent 0c326fc89e
commit e20a327db1
4 changed files with 26 additions and 14 deletions

4
Cargo.lock generated
View File

@ -1405,8 +1405,8 @@ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]] [[package]]
name = "manifold" name = "manifold"
version = "6.1.1" version = "7.0.0"
source = "git+https://code.orbiter-radio.uk/discord/manifold.git#04cd52f7e494ab905ab9d9d03daeb3efe77ab392" source = "git+https://code.orbiter-radio.uk/discord/manifold.git#8602c883d3d3146b0ec8258f4986d33203e5e92a"
dependencies = [ dependencies = [
"built", "built",
"chrono", "chrono",

View File

@ -1,6 +1,6 @@
[package] [package]
name = "hal" name = "hal"
version = "0.1.0" version = "1.0.0"
edition = "2024" edition = "2024"
[build-dependencies] [build-dependencies]

View File

@ -15,7 +15,7 @@ enum ReminderCadence {
} }
#[poise::command(slash_command, prefix_command, aliases("r"))] #[poise::command(slash_command, prefix_command, aliases("r"))]
async fn reminder(ctx: ManifoldContext<'_>, target: RoleId, cadence: ReminderCadence, tod: u8) -> ManifoldResult<()> { async fn reminder(_ctx: ManifoldContext<'_>, _target: RoleId, _cadence: ReminderCadence, _tod: u8) -> ManifoldResult<()> {
Ok(()) Ok(())
} }

View File

@ -1,8 +1,8 @@
use manifold::error::{ManifoldError, ManifoldResult}; use manifold::error::{ManifoldError, ManifoldResult};
use manifold::events::{EventHandler, Handler}; use manifold::events::EventHandler;
use manifold::ManifoldData; use manifold::ManifoldData;
use poise::{async_trait, FrameworkContext, Event};
use poise::serenity_prelude::{Context, Ready}; use poise::serenity_prelude::{Context, Ready};
use poise::{async_trait, Event, FrameworkContext};
pub struct HalHandler { pub struct HalHandler {
@ -10,19 +10,31 @@ pub struct HalHandler {
#[async_trait] #[async_trait]
impl EventHandler for HalHandler { impl EventHandler for HalHandler {
async fn listen(ctx: &Context, framework_ctx: FrameworkContext<'_, ManifoldData, ManifoldError>, event: &Event<'_>) -> ManifoldResult<()> { async fn listen(ctx: &Context, framework_ctx: FrameworkContext<'_, ManifoldData, ManifoldError>, event: &Event<'_>) -> ManifoldResult<bool> {
match event { match event {
Event::Ready { data_about_bot } => Handler::standard_startup(&ctx, &framework_ctx, data_about_bot).await, Event::MessageDelete { channel_id: _channel_id, deleted_message_id: _deleted_message_id, guild_id: _guild_id } => HalHandler::message_deleted().await,
_ => Ok(()) Event::MessageUpdate { old_if_available: _old_if_available, new: _new, event: _event } => HalHandler::message_edited().await,
Event::Ready { data_about_bot } => HalHandler::standard_startup(&ctx, &framework_ctx, data_about_bot).await,
_ => Ok(false)
} }
} }
} }
impl HalHandler { impl HalHandler {
pub async fn standard_startup(ctx: &Context, framework_ctx: &FrameworkContext<'_, ManifoldData, ManifoldError>, data_about_bot: &Ready) -> ManifoldResult<()> { async fn standard_startup(_ctx: &Context, _framework_ctx: &FrameworkContext<'_, ManifoldData, ManifoldError>, _data_about_bot: &Ready) -> ManifoldResult<bool> {
Ok(false)
Ok(())
} }
async fn message_deleted() -> ManifoldResult<bool> {
// Return true here to override the default manifold handler
debug!("Default manifold handler overridden");
Ok(true)
}
async fn message_edited() -> ManifoldResult<bool> {
// Return true here to override the default manifold handler
debug!("Default manifold handler overridden");
Ok(true)
}
} }