Skip to main content

Bot Modules

Create custom bot modules for chat automation.

Overview

Bot modules are Rust structs implementing the BotModule trait. Each module can register commands, respond to events, and interact with the chat system.

Creating a Module

use lo_bot_modules::{BotModule, ModerationAction, ModuleConfig, ModuleResult};
use lo_chat::ChatMessageInput;

pub struct MyModule;

impl BotModule for MyModule {
fn name(&self) -> &str {
"my_module"
}

fn check_message(
&self,
msg: &ChatMessageInput,
_config: &ModuleConfig,
) -> Option<ModuleResult> {
if msg.message.contains("badword") {
Some(ModuleResult {
module_name: self.name().to_string(),
action: ModerationAction::Delete,
reason: "matched rule".into(),
})
} else {
None
}
}
}

Registration

Register your module with a ModuleRegistry (see crates/lo-bot-modules/src/registry.rs). The create_default_registry() helper pre-registers LinkProtection, WordFilter, SpamProtection, and TimedMessages. Modules are checked in the order they are registered — the first module to return Some(ModuleResult) wins. Modules are enabled/disabled per account via the bot_module_configs table (ModuleConfig.enabled).

Available Context

Modules have access to:

  • Message content and metadata
  • User information and roles
  • Channel configuration
  • Database queries via SQLx
  • Redis cache