el-bot Documentation
website·Indexed 32 days ago
https://docs.bot.elpsy.cn/A bot framework based on mirai-ts and mirai-api-http that allows users to implement bot functionality through simple configuration or custom plugins. It includes a built-in data system using MongoDB and mongoose, a logging system implemented with winston, and a command system based on commander.js.
What's inside el-bot
- el-bot is a configurable QQ bot framework written in TypeScript and running on Node.js, based on mirai-ts. It provides built-in features such as automatic responses, forwarding, command-line interfaces, and RSS. It supports dynamic plugin loading and functional programming patterns. Note: Users must be able to install and start mirai independently, as the project no longer provides installation scripts for mirai.
Overview of the el-bot framework
el-bot is a configuration-based QQ robot framework implemented based on mirai-ts. It is designed to allow users to implement most of their requirements through simple configuration.Overview of the el-bot framework
el-bot is a configuration-based QQ robot framework implemented based on mirai-ts. It is designed to allow users to implement most of their requirements through simple configuration.Verify mirai-api-http connectivity for el-bot
Before using el-bot, you must ensure that the
mirai-api-httpplugin is successfully loaded and running.To verify connectivity, visit the
/aboutendpoint of the API. By default,mirai-api-httpuses port8080, butel-bot-templatedefaults to port4859to avoid common port conflicts.# Example check using curl (replace 4859 with your configured port) curl http://localhost:4859/aboutManage el-bot via the el-bot-web control panel
el-bot-web provides a website console for observing and controlling your QQ robot. It is implemented based on mirai-api-http.Understand the el-bot and mirai ecosystem relationship
el-bot is a cross-platform, configurable robot framework based on Node.js. It relies on the following stack to function:
- mirai: The core Kotlin-based library providing the QQ protocol.
- mirai-console: The server-side console used to start mirai and load plugins.
- mirai-api-http: A mirai-console plugin that exposes an HTTP API, allowing external languages to interact with mirai.
- mirai-ts: A TypeScript SDK that wraps mirai-api-http requests and provides type definitions/intellisense for editors like VS Code.
- el-bot: The framework built on top of mirai-ts.
Users must be able to start mirai independently using tools like
mirai-console-loader,miraiOK, ormirua.Develop a custom plugin for el-bot
el-bot plugins are functions that receive a bot context (
ctx). You can usectx.mirai.apito access mirai-ts APIs without handling login or plugin loading manually.Plugin Structure:
- Create a file (e.g.,
plugins/custom/test.js) or a folder with anindex.js(e.g.,plugins/custom/test/index.js). - The filename (or folder name) becomes the plugin name.
- The plugin must export a function (default export).
Context Object (
ctx) Properties:ctx.el.config: Access bot-related configurations from the config file.ctx.mirai: Access the mirai-ts instance for event listening and API calls.
// Example: plugins/custom/test.js const { default: Bot } = require("el-bot"); /** * @param {Bot} ctx */ module.exports = async function (ctx) { const mirai = ctx.mirai; // Listen for messages (covers Friend, Group, and Temp messages) mirai.on("message", (msg) => { console.log("Received message:", msg); }); // Send a command via mirai-api-http const data = await mirai.api.command.send("help", []); console.log("Help info:" + data); // Listen for specific events (e.g., GroupRecallEvent) mirai.on("GroupRecallEvent", ({ operator }) => { const text = `${operator.memberName} recalled a message.`; mirai.api.sendGroupMessage(text, operator.group.id); }); };- Create a file (e.g.,
Manage plugin session isolation using InnerMode
Theutils.InnerModeclass allows developers to implement an 'internal mode' for plugins. This prevents state leakage between different chat groups or users. Without InnerMode, a plugin might trigger a response in Group B based on a command sent in Group A. By usingInnerMode, the plugin tracks the state specifically for the current message context, ensuring that operations (like a search mode) are isolated to the group where they were initiated.import { utils } from "el-bot"; const innerMode = new utils.InnerMode(); export default async function() { mirai.on("message", (msg) => { // Associate the current message with the inner mode instance innerMode.setMsg(msg); // Example: Enter 'Image Search' mode if the user sends "搜图" if (msg.plain === "搜图") { innerMode.enter(); msg.reply("I'm ready!"); } // Check if the current context is in internal mode if (innerMode.getStatus()) { // Perform the specific action (e.g., fakeSearchImage()) fakeSearchImage(); // Exit internal mode to reset state for this context innerMode.exit(); } }); }Quickly start a robot using el-bot-template
Use the el-bot-template repository to quickly generate a new robot instance based on the el-bot framework.Use the RSS subscription plugin
The
rssplugin allows the bot to track and notify users of updates from RSS feeds usingrss-parser.- Commands: Send
rssin a private chat to see all subscriptions and trigger an immediate fetch. Sendrssin a group to see subscriptions specific to that group. - Storage: RSS data is stored in
el-bot/tmp/rss.json. Deleting this file forces a fresh fetch of all feeds. - Recommendation: Use RSSHub for generating feeds for sites that do not natively support RSS.
- Commands: Send
Install and use el-bot CLI globally
You can install theel-botpackage globally to access its command-line interface for managing the bot and its dependencies like mirai.# Install el-bot globally npm install -g el-bot # or yarn global add el-bot # Install mirai el install mirai # Start mirai el start mirai # Start the bot el botInstall el-bot
To use el-bot, you must have Java and Node.js installed. It is recommended to use the official mirai-console-loader to start mirai and the mirai-api-http plugin.npm install el-bot # or yarn add el-bot