English | 简体中文
Kovi
Kovi is a simple and extensible chat bot development framework. If you want to develop Milky / OneBot V11 bots using Rust, Kovi is a great choice.
🎯 The goal is to create the simplest chat bot framework in Rust! Simplifying complex Rust syntax? Kovi has done its best.
🤔 Let me count — the quick start in the documentation only requires 10 lines of code to create the simplest plugin.
🥁 There's also a CLI tool to make project development easier.
🖥️ Just for fun? Or customized? Kovi is competent
🛍️ The plugin shop provides an excellent Kovi shopping experience, allowing you to easily access packages from plugin developers 📦.
😍 The project documentation is very simple and easy to understand. Follow it and you'll be good to go.
↓ Documentation is here
↓ The shop is here
Protocol Support
Kovi is an "event bus" plugin runner. It connects to chat services through driver crates that implement different protocols.
kovi-milky— Milky WebSocket protocolkovi-onebot— OneBot V11 forward WebSocket protocol
When creating a project, kovi-cli will ask you to choose a driver, or you can specify it with --driver milky / --driver onebot.
Getting Started
It's recommended to use kovi-cli to manage your Kovi bot project.
- Create a basic Rust project and add the framework.
During this step, you'll be prompted to choose a protocol driver and whether to add the command plugin.
✔ Which driver/protocol to use? · Milky
✔ Are you want to add message command plugins? · Yes
You can also skip the prompts by passing flags:
- A bot instance has been generated in src/main.rs.
use tokio;
async
On your first run, during driver::load_local_conf(), you'll be prompted to enter some information to create the kovi.conf.toml file, which is required for the driver to run.
✔ What is the type of the host of the OneBot server? · IPv4
✔ What is the IP of the OneBot server? · 127.0.0.1
(Default: 127.0.0.1)
✔ What is the port of the OneBot server? · 8081
(Default: 8081)
✔ What is the access_token of the OneBot server? (Optional) ·
(Default: empty)
✔ What is the ID of the main administrator? (Not used yet)
(Optional)
✔ Do you want to view more optional options? · No
Plugin Development
Creating a Plugin
Follow the steps below.
kovi-cli and cargo will take care of everything for you. The CLI will automatically detect which driver crates are in your workspace and add the corresponding use imports.
You will see that a new plugins/hi directory has been created. This is also the recommended way to develop plugins, as it's always good to manage them in a directory.
Writing a Plugin
Edit your newly created plugin in plugins/hi/src/lib.rs.
Here's a minimal example:
// Import the plugin builder structure
use PluginBuilder as plugin;
// Import the driver traits (kovi-milky / kovi-onebot)
use *;
// Build the plugin
async
The main function is written in lib.rs because it will be exported later to be mounted to the bot instance.
Plugins generally don't need a main.rs.
Mounting the Plugin
Alternatively, you can use cargo directly; both are the same. This will add a local dependency in the root project's Cargo.toml.
Then mount the plugin in src/main.rs:
use tokio;
async
More Plugin Examples
Bot Taking Initiative to Send Messages
use PluginBuilder as plugin;
use *;
async
The main() function runs only once when plugin starts.
The closure passed to plugin::on_msg() runs every time a message is received.
Kovi has encapsulated all available OneBot standard APIs. To extend the API, you can use RuntimeBot's send_api() to send APIs yourself. You can check out the API extension plugins available for your needs at Kovi Plugin Shop.
You can find more documentation in the Kovi Doc.