gusonyang / qq-bot-rebown

SmartQQ robot written in JavaScript, using ES7 async/await features

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

qq-bot-rebown

npm version dependencies status

使用 ES7 async/await 语法编写的 Web QQ 机器人。

Features

  • 扫码登录 目前唯一可用的登录方法
  • 使用最近一次登录过的 Cookie 自动登录
  • 记录每条收到的消息以及发送者
  • 可自定义的 MsgHandler
  • 缩短 URL (使用 t.cn 短链接服务)
  • 对所有数据提供 .d.ts 类型定义

Usage

  1. 安装为依赖
$ npm install qq-bot-rebown -S 
  1. 在脚本中引用
const { QQ } = require('qq-bot-rebown');

// do what you want then...

Docs

使用 MsgHandler

// 导入模块
const { QQ, MsgHandler } = require('qq-bot-rebown');

// 实例化 MsgHandler
const fooHandler = new MsgHandler(
    // 收到消息后的处理函数,可用 async function
    (msg, qq) => {
        qq.sendBuddyMsg(msg.id, `Hello ${msg.name}`);
    },
    // 该 handler 可处理的消息类型
    'buddy', 'discu'
);

// 使用自定义 handler 实例化 QQ 并运行
new QQ(fooHandler).run();

详细示例请参考 example.js

MsgHandler API Reference

interface ReceivedMsgType {
    id: Number
    name: String
    type: 'buddy' | 'discu' | 'group'
    content: String
    groupId?: String
    groupName?: String
    disucId?: String
    discuName?: String
}

class MsgHandler {
    constructor(
        handler: (msg: ReceivedMsgType, qq: QQ) => void,
        ...acceptTypes: Array<'buddy' | 'discu' | 'group'>
    );
}

短链接 API

const { ShortenUrl } = require('qq-bot-rebown');

ShortenUrl('https://github.com').then(console.log);
//http://t.cn/RxnlTYR

ShortenUrl(['https://gitlab.com', 'https://gist.github.com']).then(console.log);
// [ 'http://t.cn/RhJnX41', 'http://t.cn/amvA44' ]

About

SmartQQ robot written in JavaScript, using ES7 async/await features

License:MIT License


Languages

Language:JavaScript 100.0%