JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q29776F
  • License MIT

Web QQ client using es7 syntax

Package Exports

  • qq-bot-rebown

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (qq-bot-rebown) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

qq-bot-rebown

npm version dependencies status

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

Features

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

RouteMap

  • 获取好友的 QQ 号码
  • 发送图片或文件 (WIP)
  • 在群中 @ 群成员 (WIP)

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' ]