From e20a327db1aa161675d917baed76453f3a08e085 Mon Sep 17 00:00:00 2001 From: Lucy Bladen Date: Sun, 4 May 2025 12:14:34 +0100 Subject: [PATCH] Override default manifold handlers for message edits and deletions --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/hal/commands/utility.rs | 2 +- src/hal/events.rs | 32 ++++++++++++++++++++++---------- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ed11b1..68d9f99 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1405,8 +1405,8 @@ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" [[package]] name = "manifold" -version = "6.1.1" -source = "git+https://code.orbiter-radio.uk/discord/manifold.git#04cd52f7e494ab905ab9d9d03daeb3efe77ab392" +version = "7.0.0" +source = "git+https://code.orbiter-radio.uk/discord/manifold.git#8602c883d3d3146b0ec8258f4986d33203e5e92a" dependencies = [ "built", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 06b8b49..de422ef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hal" -version = "0.1.0" +version = "1.0.0" edition = "2024" [build-dependencies] diff --git a/src/hal/commands/utility.rs b/src/hal/commands/utility.rs index f579213..2da22de 100644 --- a/src/hal/commands/utility.rs +++ b/src/hal/commands/utility.rs @@ -15,7 +15,7 @@ enum ReminderCadence { } #[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(()) } diff --git a/src/hal/events.rs b/src/hal/events.rs index 3861a9b..56fcec4 100644 --- a/src/hal/events.rs +++ b/src/hal/events.rs @@ -1,8 +1,8 @@ use manifold::error::{ManifoldError, ManifoldResult}; -use manifold::events::{EventHandler, Handler}; +use manifold::events::EventHandler; use manifold::ManifoldData; -use poise::{async_trait, FrameworkContext, Event}; use poise::serenity_prelude::{Context, Ready}; +use poise::{async_trait, Event, FrameworkContext}; pub struct HalHandler { @@ -10,19 +10,31 @@ pub struct HalHandler { #[async_trait] 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 { match event { - Event::Ready { data_about_bot } => Handler::standard_startup(&ctx, &framework_ctx, data_about_bot).await, - _ => Ok(()) + Event::MessageDelete { channel_id: _channel_id, deleted_message_id: _deleted_message_id, guild_id: _guild_id } => HalHandler::message_deleted().await, + 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 { - pub async fn standard_startup(ctx: &Context, framework_ctx: &FrameworkContext<'_, ManifoldData, ManifoldError>, data_about_bot: &Ready) -> ManifoldResult<()> { - - Ok(()) + async fn standard_startup(_ctx: &Context, _framework_ctx: &FrameworkContext<'_, ManifoldData, ManifoldError>, _data_about_bot: &Ready) -> ManifoldResult { + Ok(false) } - -} \ No newline at end of file + + async fn message_deleted() -> ManifoldResult { + // Return true here to override the default manifold handler + debug!("Default manifold handler overridden"); + Ok(true) + } + + async fn message_edited() -> ManifoldResult { + // Return true here to override the default manifold handler + debug!("Default manifold handler overridden"); + Ok(true) + } +}