Giter Club home page Giter Club logo

gubot's Introduction

Gubot

咕! bot,一个开源免费的用于提供剑网三相关功能的一个QQ群机器人。
注意,机器人通过响应来自go-cqhttp的请求来实现自动回复消息等
由于忙于学(mo)业(yu),缺乏时间写机器人,然后由于大部分够用了就有些懒得写了Orz 有兴趣的小伙伴可以自己写着玩噢。欢迎贡献源代码(

TODOLIST

  • 开服播报/奇遇播报
  • 全群广播
  • 斗图功能
  • 语音生成
  • 更聪明的对话
  • websocket自动重连
  • 各种命令回显的美化
  • 抄其他机器人的功能

快速开始 Quick Start

首先,你需要安装依赖,本项目使用纯node实现,同时使用了mysql、redis等服务,只需要保证运行的机器有node环境与mysql即可。 redis并不是必备的服务

cd /path/to/gubot
npm install

然后,你需要创建env.json作为机器人的配置文件,项目为您提供了配置模板env.example.json,您只需要将其复制一份进行自己的修改。 配置文件主要包括数据库信息,某些api的token,某些功能的开启、关闭与配置等。

cp env.example.json env.json
vi env.json
//进行机器人配置

然后你需要创建数据库结构,程序为您准备好了迁移文件,您只需要创建好对应的数据库执行下述脚本即可。

node src/database/db_sync.js

然后确保go-cqhttp处于运行状态,运行app.js即可

node app.js

项目结构 Project Structure

  • app.js 程序入口
  • env.example.json 项目配置模板
  • storage/ 储存程序运行期间生成的html模板以及图片
  • tests/ 编写测试用例,但是由于我懒得写,所以是空的
  • src
    • assets/ 资源文件夹,您并不需要关注
      • json/ 存放需要用到的一些json数据
      • images/ 存放可能需要用到的一些图片
    • commands/ 命令文件夹,需要添加新的功能的时候在这里添加,具体可以参考文档的“添加新功能”部分(还没写)
    • database/ 存放了一些数据库结构迁移相关的脚本
    • model/ 数据实体的定义,包括群,别名,用户等
    • service/ 服务
      • httpApi/ 提供http api调用
      • wsApi/ wsApi的抽象
      • iamgesGenerator.js 提供图片支持,支持从url抓取图片/从数组生成图片,使用html模板生产图片等
      • game.js 提供了游戏本身的一些功能(其实目前只有测试是否开服相关的内容)
      • cqhttp.js 是一个go-cqhttp实例的抽象,提供简单的api调用
      • bot.js 项目本身运行实例的抽象
      • websocket.js ws客户端的抽象,提供了不完善的请求-响应函数
    • templates 存放图片模板的位置,使用art-template模板引擎

项目配置项

咕咕咕

项目讲解

项目入口是app.js
基本上整个项目都被抽象进了Bot类里面,这个类在./src/service/bot.js里面,所以基本看这个文件的代码就可以明白项目结构了(
启动的时候bot会根据ENV内的内容初始化redis连接,如果ENV没有启动redis的话会生成一个代理,在项目内调用代理的get/set什么的函数统统返回null。
然后初始化Sequelize,也就是数据库ORM的连接,这个不能没有,所以一定要配置好数据库。
在之后初始化图片生成器,这个东西依赖的是puppeteer库,如果在ENV里没有启用的话也会生成一个代理,这个代理只会返回./src/assets/images/error/image_generator_disable.jpg
再然后会根据ENV里定义的cqhttp去分别生成cqhttp实例,然后由cqhttp实例自己负责生成自己的ws客户端和cqhttp程序连接。
然后就是初始化命令列表,其实就是载入commands下面的index文件(
后面就没啥好说的了(其实是不知道怎么解释屎山了

咕咕咕

懒得写文档了Orz 我好懒 为什么会有我这么懒的人

gubot's People

Contributors

huangarmagh avatar joakminx avatar x3zvawq avatar zhongshmx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gubot's Issues

求教

大佬请问env.json那里如何配置?

安装失败

monent 这个包名是不是写错了? 应该是moment吧

部署报错

/home/ubuntu/gubot/src/service/bot.js:208
            let [args, command] = await this.parseArgs(data) ?? [];
                                                              ^


SyntaxError: Unexpected token ?
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/ubuntu/gubot/app.js:3:13)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

尝试删掉,再报错

[2021-07-09 14:43:09][SUCCESS] Redis: init successed
[2021-07-09 14:43:09][SUCCESS] Sequelize: init successed
[2021-07-09 14:43:09][SUCCESS] ImageGenerator: init successed
(node:47874) UnhandledPromiseRejectionWarning: /home/ubuntu/gubot/src/service/cqhttp.js:4
    wsApi;
         ^

SyntaxError: Unexpected token ;
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Bot.initCqhttps (/home/ubuntu/gubot/src/service/bot.js:83:24)
    at /home/ubuntu/gubot/app.js:10:15
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:47874) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:47874) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
ubuntu@VM-8-13-ubuntu:~/gubot$ vim src/service/cqhttp.js

帮助或者/help错误

TypeError: Cannot read property 'newPage' of undefined
at Function.generateFromHtmlFile (/root/goubot/src/service/image.js:19:44)
at Function.generateFromHtml (/root/goubot/src/service/image.js:59:33)
at async Function.generateFromMarkdown (/root/goubot/src/service/image.js:96:16)
at async Function.generateFromMarkdownFile (/root/goubot/src/service/image.js:86:16)
at async HelpHandler.handle (/root/goubot/src/commands/help.js:11:21)
at async Bot.handleCommand (/root/goubot/src/service/bot.js:25:24)
at async Bot.handleMessage (/root/goubot/src/service/bot.js:122:24)
at async WebSocket. (/root/goubot/src/main.js:121:26)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.