项目作者: dousha

项目描述 :
TypeScript wrapper for interacting with mirai-api-http
高级语言: TypeScript
项目地址: git://github.com/dousha/mirai-api-http-ts.git
创建时间: 2020-11-01T04:34:58Z
项目社区:https://github.com/dousha/mirai-api-http-ts

开源协议:GNU Affero General Public License v3.0

下载


mirai-api-http-ts - Simple and Intuitive TypeScript Wrapper for mira-api-http

简体中文 | English

Note: This is an ongoing project. We will try our best to keep
backward compatibility, but breaking changes can occur.
The version number conforms to SemVer as
compatibility reference.

Motivation

I just need a good enough TypeScript library for my bot. I guess
you might need it too.

Usage

Get the library:

  1. $ yarn add @dousha99/mirai-api-http-ts
  2. - or -
  3. $ npm i --save @dousha99/mirai-api-http-ts

Documentation in progress…

Examples

See examples/ for working examples. Here is a simple echo bot example:

  1. import { MiraiClient, OutboundMessageChiain, MessageType } from '@dousha99/mirai-api-http-ts';
  2. const mirai = new MiraiClient({
  3. connection: {
  4. tls: false,
  5. host: 'localhost',
  6. httpPort: 8080,
  7. websocketPort: 8080,
  8. useWebsocket: true,
  9. pollPeriod: 5000,
  10. pollCount: 5,
  11. },
  12. account: {
  13. authKey: process.env['AUTH_KEY']!,
  14. account: Number(process.env['QQ']!),
  15. },
  16. });
  17. mirai.on(MessageType.FRIEND_MESSAGE, msg => {
  18. if (msg.isPlainTextMessage()) {
  19. const text = msg.extractPlainText();
  20. msg.reply(OutboundMessageChain.ofText(text)).catch(e => console.error(e));
  21. if (text.trim() === 'stophammertime') {
  22. mirai.close();
  23. }
  24. }
  25. });
  26. mirai.on('connect', () => {
  27. console.log('Ready');
  28. });