A Twitch chat bot written in Rust
- lordbornebot_core crate - a library that contains all types, macros, utilities and definitions that are shared between the bot and modules
- lordbornebot create - a binary that runs the actual IRC Client, loads and unloads the modules, initializes middleware etc. (basically glues everything together)
IRC Client (lordbornebot::twitch::client) ⇒ decoding (lordbornebot::twitch::parser) ⇒ lordbornebot_core::Message ⇒ middleware ⇒ modules ⇒ encoding (lordbornebot::twitch::parser) ⇒ lordbornebot_core::Message ⇒ IRC Client Message Queue (lordbornebot::twitch::client)
- Create a Cargo library project:
cargo new <module name> --lib
- Set the library type to cdylib by editing your Cargo.toml like this:
[package]
...
[lib]
crate-type = ["cdylib"]
[dependencies]
lordbornebot_core = {version = "*", git = "https://github.com/matijakevic/lordbornebot"}
...
- In your lib.rs implement lordbornebot_core::Module trait for some type (struct for example).
- Create an export function for your dynamic module (there might be a macro in the future to do this automatically):
#[no_mangle]
pub extern "C" fn _create_module(config: &Config) -> *mut Module {
let obj = <construction of your object>;
Box::into_raw(Box::new(obj))
}
- Compile your module and copy the <module name> dynamic library into your modules directory.
See modules/ folder for examples.
You still need to build them and copy the <module name> dynamic libraries into your modules directory!
- AFK module - utility module for notifying other chatters that some chatter is AFK.
- Points - a module for querying user's points.
- Gamble - a module for points gambling.
- Shape module - a module for receiving points on a successfully created shape in chat.
- RPG module (WIP, stalled) - a large game module for MMORPGish dungeon experience.
- Implement middleware::Middleware trait for some type (struct for example).
- Construct and add your type (Boxed) to middleware list inside init_middleware function in main.rs.
Middleware system is currently not dynamic. If it does become dynamic, it will use the same mechanism as dynamic modules.
- Filter - for filtering messages that may violate Twitch ToS / chat rules.
- Create a modules folder where you will put your module dynamic libraries.
- Fill out example_config.json with your data.
- command_prefx - a prefix that will be used to differentiate plain messages from commands (like "!", ">"...)
- database_path - a path to the SQLite database, you can create one using migrations/create_tables.sql which contains all tables required for pre-made modules to work
- banphrases_path - a path to json file containing a list of phrases which will indicate the filter system to ignore the messages containing those phrases, for example, this banphrases.json file
will ignore all messages that contain word abc (in any case)["abc"]
- message_interval - the minimum time that needs to pass for IRC client to be able to send a message again (see Twitch IRC docs for rate limiting)
- modules_path - a path to modules folder containing dynamic libraries of modules
- modules - a list of dynamic modules that will be loaded automatically on startup
- channels - a list of channels which will be joined automatically on startup
- Path of the config.
- Set BOT_CONFIG_PATH environment variable to point to your config JSON file.
- Leaving it unset marks that configuration file is config.json in the directory where you run the bot.
cargo run
to run the bot.