Skip to content

Abstract plugins from main codebase#4

Open
motorlatitude wants to merge 16 commits into
developfrom
feature/plugin-abstraction
Open

Abstract plugins from main codebase#4
motorlatitude wants to merge 16 commits into
developfrom
feature/plugin-abstraction

Conversation

@motorlatitude

Copy link
Copy Markdown
Owner
  • Abstracted plugin logic to tidy up codebase
  • Add error handling in a new error module

- Abstracted plugin logic to tidy up codebase
- Add error handling in a new error module

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the bot into a plugin-based architecture, moving most command/event logic out of main.rs into discrete plugins, and introduces centralized error types for storage and plugins.

Changes:

  • Introduces a MotorbotPlugin trait + PluginContext, and updates the runtime to dispatch Discord events to loaded plugins.
  • Adds new plugins (ping/time/dice/coin-toss/debug/points/jokes/patches) and reworks the patches logic to fit the plugin system.
  • Replaces the storage error module and wires storage errors into the crate-wide error type.

Reviewed changes

Copilot reviewed 23 out of 24 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/storage/errors.rs Removed legacy storage error module.
src/storage/error.rs New storage error type (StorageError) with Display and conversions.
src/storage/database.rs Updates DB layer to wrap/propagate the new crate-wide error + expands guild config keys/values.
src/storage.rs Exposes storage::error module and re-exports StorageError.
src/plugins/time.rs Adds TimePlugin slash command implementation.
src/plugins/points.rs Adds points/voting plugin, including channel configuration and reaction handlers.
src/plugins/ping.rs Adds PingPlugin slash command implementation.
src/plugins/patches/platforms/platform.rs Adds Default derive for Platform (using Unknown).
src/plugins/patches/patches_plugin.rs Removes old patches plugin implementation (pre-plugin-architecture).
src/plugins/patches/mod.rs Removes old patches module root in favor of patches.rs.
src/plugins/patches.rs New patches plugin implementation + scheduled update loop and slash commands.
src/plugins/mod.rs Registers all plugin modules.
src/plugins/jokes.rs Adds daily jokes plugin + channel configuration and scheduled posting.
src/plugins/dice.rs Adds dice roll slash command plugin.
src/plugins/debug.rs Adds debug plugin (whoami/version/plugins/events config).
src/plugins/coin_toss.rs Adds coin toss slash command plugin.
src/plugin/plugin_info.rs Adds PluginInfo struct used by the plugin system.
src/plugin/plugin_context.rs Adds plugin context + event reporting to configured channels.
src/plugin/error.rs Adds plugin-specific error enum (PluginError).
src/plugin.rs Adds core plugin trait and the option! helper macro.
src/main.rs Refactors main event handler to dispatch to plugins and emit startup/error events via PluginContext.
src/error.rs Adds crate-wide Error + Result types and conversions.
Cargo.toml Adds async-trait and derive_more; removes unused OpenAI dependency.
Cargo.lock Dependency updates aligned with Cargo.toml changes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/plugins/jokes.rs Outdated
Comment thread src/plugins/jokes.rs
Comment thread src/plugins/jokes.rs Outdated
Comment thread src/plugins/points.rs
Comment thread src/plugins/points.rs
Comment thread src/plugins/patches.rs Outdated
@motorlatitude motorlatitude added this to the v0.3.0 milestone Apr 22, 2026
@motorlatitude motorlatitude marked this pull request as draft April 22, 2026 09:29
@motorlatitude motorlatitude added refactor This issue or pull request relates to refactoring of code labels Apr 22, 2026
motorlatitude and others added 5 commits April 22, 2026 19:43
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
…downvote to avoid potential panics

Co-authored-by: Copilot <copilot@github.com>
…improve error handling in update method for patches plugin

Co-authored-by: Copilot <copilot@github.com>
…er-compose for plugin abstraction

AI command has been deprecated during this abstraction as it wasn't being used any way.
@motorlatitude motorlatitude marked this pull request as ready for review April 22, 2026 20:45
@motorlatitude motorlatitude requested a review from Copilot April 22, 2026 20:45

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 25 out of 26 changed files in this pull request and generated 7 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/plugins/dice.rs Outdated
Comment thread src/plugins/jokes.rs Outdated
Comment thread src/plugins/patches.rs Outdated
Comment thread src/plugins/patches.rs Outdated
Comment thread src/plugin/plugin_context.rs Outdated
Comment thread src/plugins/points.rs Outdated
Comment thread src/storage/database.rs Outdated
@motorlatitude motorlatitude marked this pull request as draft April 23, 2026 10:56
@motorlatitude motorlatitude marked this pull request as ready for review April 23, 2026 10:56
@motorlatitude motorlatitude reopened this Apr 23, 2026
motorlatitude and others added 7 commits April 23, 2026 12:04
Co-authored-by: Copilot <copilot@github.com>
Carries out input sanitisation to ensure dice side is between 2 and 100 inclusive
…array case

Co-authored-by: Copilot <copilot@github.com>
…red all open database instances are closed

Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
@motorlatitude motorlatitude added the core Issues and PRs relating to the MotorBot’s core functionality label Apr 24, 2026
…plugin; replace PluginError usage with custom error variants

Co-authored-by: Copilot <copilot@github.com>

@motorlatitude motorlatitude left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some improvements

Comment thread src/plugins/time.rs
Comment on lines +8 to +11
use crate::plugin::PluginError;
use crate::{Error, Result};

use crate::plugin::{MotorbotPlugin, PluginContext, PluginInfo};

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider combining these

Comment thread src/plugins/time.rs
CreateInteractionResponse::Message(
CreateInteractionResponseMessage::new().content(
format!(
":alarm_clock: The current time is: {}",

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using one of the custom pixel emojis instead of the standard alarm clock. Maybe the moon emoji?

Comment thread src/plugins/time.rs
Comment on lines +58 to +73
command
.create_response(
&p_ctx.ctx.http,
CreateInteractionResponse::Message(
CreateInteractionResponseMessage::new().content(
format!(
":alarm_clock: The current time is: {}",
current_time
),
),
),
)
.await
.map_err(|err| {
Error::Plugin(PluginError::FailedToRespond { err })
})?;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create a macro for this to standardise the response process for most plugins

Comment thread src/plugins/ping.rs
Comment on lines +8 to +11
use crate::plugin::PluginError;
use crate::{Error, Result};

use crate::plugin::{MotorbotPlugin, PluginContext, PluginInfo};

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider combining these

Comment thread src/plugins/ping.rs
async fn on_ready(&self, p_ctx: &PluginContext) -> Result<()> {
info!("Ping Plugin is ready!");

let _ = Command::create_global_command(

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for let _ here, prefer using question mark notation

Comment thread src/storage/database.rs
}
}

pub struct GuildConfig {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring

Comment thread src/storage/database.rs
/// not found, it returns None.
/// * `Err(Error)` - If there is an error during the database query, it
/// returns a [Error] variant with details about the failure.
pub async fn get_guild_config(

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to match other methods, remove "get". Should be guild_config

Comment thread src/main.rs

mod plugin;
use plugin::MotorbotPlugin;
struct Handler {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docstring

Comment thread src/main.rs
Comment on lines +187 to +189
let subscriber = FmtSubscriber::builder().with_max_level(level).finish();
tracing::subscriber::set_global_default(subscriber)
.expect("setting default subscriber failed");

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if something other than local can used here to separate MotorBot logging from Serenity logging

Comment thread src/plugin.rs
Comment on lines +5 to +6
pub mod plugin_context;
pub mod plugin_info;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename to context and info respectively.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issues and PRs relating to the MotorBot’s core functionality refactor This issue or pull request relates to refactoring of code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants