# QQRobot **Repository Path**: frankiewen/qqrobot ## Basic Information - **Project Name**: QQRobot - **Description**: 一个简易QQ机器人程序 - **Primary Language**: Unknown - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: https://blog.dearxuan.com/2022/04/02/QQ%E6%9C%BA%E5%99%A8%E4%BA%BA%E5%BC%80%E5%8F%91/ - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-03-08 - **Last Updated**: 2023-03-08 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## What's this? 本项目是我自己基于 [oicq](https://gitdub.com/takayama-lily/oicq) ,为方便开发而编写的插件管理程序,功能比较简陋 ## 如何运行 *在运行项目之前,需要先安装node环境* 克隆项目到本地 ``` bash git clone https://gitee.com/dearxuan/qqrobot.git ``` 进入项目目录 ``` bash cd qqrobot ``` 安装npm包 ``` bash npm install ``` 接下来需要修改配置文件 复制项目根目录下的 "config.yml" 文件,到同目录下的 "config.custom.yml" 文件,新的配置文件的数据会将其覆盖,这样当配置文件更新时,你可以快速拉取更新而不需要额外修改任何内容. 或者你也可以直接在 "config.yml" 里修改(不推荐). 运行项目 ``` bash node app ``` ## 插件制作 所有插件均位于项目根目录的"plugins"文件夹内,该目录下的单一js文件都会被认为是插件而加载,而文件夹内只有"index.js"会被加载, 如下所示,其中```example/index.js```,```hello.js```,```app.js```会被加载,而```example/app.js```不会被加载 ``` plugins | +----example | | | +----app.js | └----index.js | +----hello.js └----app.js ``` 每个插件都要将自己注册的指令以字典的形式导出,下面是一个最简单的示例,当机器人收到"test"消息时触发```DoThis(msg)```函数 ``` js /** 导出插件,如果有多个指令就改为数组形式 */ module.exports = { /** 插件名称,在控制台显示 */ name: "示例插件", /** 匹配的关键字 */ word: "test", /** 匹配模式:strict(严格), prefix(前缀), suffix(后缀) */ method: "strict", /** 优先级,严格匹配永远比前缀和后缀优先,数字越小优先度越高 */ priority: 5000, /** 执行的函数 */ func: DoThis, } function DoThis(msg) { return true; } ``` 如果要一次性导出多个指令,可以改用字典 ```js module.exports = [ { name: "示例插件1", word: "test1", method: "strict", priority: 5000, func: DoThis1, }, { name: "示例插件2", word: "test2", method: "strict", priority: 5000, func: DoThis2, }] ```