Skip to content

Commit b3a8199

Browse files
committed
reexporting stuff
1 parent ff81c3f commit b3a8199

File tree

6 files changed

+140
-3
lines changed

6 files changed

+140
-3
lines changed

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# `mirai-api-http-ts` - Simple and Intuitive TypeScript Wrapper for `mira-api-http`
2+
3+
[简体中文](README.zh.md) | English
4+
5+
Note: This is an ongoing project. We will try our best to keep
6+
backward compatibility, but breaking changes can occur.
7+
The version number conforms to [SemVer](https://semver.org/) as
8+
compatibility reference.
9+
10+
## Motivation
11+
12+
I just need a good enough TypeScript library for my bot. I guess
13+
you might need it too.
14+
15+
## Usage
16+
17+
Get the library:
18+
19+
```
20+
$ yarn add @dousha99/mirai-api-http-ts
21+
- or -
22+
$ npm i --save @dousha99/mirai-api-http-ts
23+
```
24+
25+
Documentation in progress...
26+
27+
## Examples
28+
29+
See `examples/` for working examples. Here is a simple echo bot example:
30+
31+
```ts
32+
import { MiraiClient } from '../index';
33+
import { MessageType } from '../src/objects/Message';
34+
import { OutboundMessageChain } from '../src/objects/OutboundMessageChain';
35+
36+
const mirai = new MiraiClient({
37+
connection: {
38+
tls: false,
39+
host: 'localhost',
40+
httpPort: 8080,
41+
websocketPort: 8080,
42+
useWebsocket: true,
43+
pollPeriod: 5000,
44+
pollCount: 5,
45+
},
46+
account: {
47+
authKey: process.env['AUTH_KEY']!,
48+
account: Number(process.env['QQ']!),
49+
},
50+
});
51+
mirai.on('message', msg => {
52+
if (msg.message.type === MessageType.FRIEND_MESSAGE) {
53+
if (msg.isPlainTextMessage()) {
54+
const text = msg.getPlainText();
55+
msg.reply(OutboundMessageChain.ofText(text)).catch(e => console.error(e));
56+
if (text.trim() === 'stophammertime') {
57+
mirai.close();
58+
}
59+
}
60+
}
61+
});
62+
mirai.on('connect', () => {
63+
console.log('Ready');
64+
});
65+
```

README.zh.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# `mirai-api-http-ts` - 简单而符合直觉的 `mira-api-http` TypeScript 封装
2+
3+
简体中文 | [English](README.md)
4+
5+
注意:这个项目正在活跃开发。我们会尽力保持向下兼容性,但不兼容的更改可能随时被引入。我们使用[语义化版本号](https://semver.org/lang/zh-CN/)作为兼容性参考。
6+
7+
## 动机
8+
9+
我寻思着得有一个简单的 `mirai-api-http` 的 TypeScript 库。
10+
11+
## 用法
12+
13+
获取这个库:
14+
15+
```
16+
$ yarn add @dousha99/mirai-api-http-ts
17+
- 或者 -
18+
$ npm i --save @dousha99/mirai-api-http-ts
19+
```
20+
21+
文档啊,文档在写了(指新建文件夹)。
22+
23+
## 样例
24+
25+
简单的复读机:
26+
27+
```ts
28+
import { MiraiClient } from '@dousha99/mirai-api-http-ts';
29+
import { MessageType } from '@dousha99/mirai-api-http-ts/objects/Message';
30+
import { OutboundMessageChain } from '@dousha99/mirai-api-http-ts/objects/OutboundMessageChain';
31+
32+
const mirai = new MiraiClient({
33+
connection: {
34+
tls: false,
35+
host: 'localhost',
36+
httpPort: 8080,
37+
websocketPort: 8080,
38+
useWebsocket: true,
39+
pollPeriod: 5000,
40+
pollCount: 5,
41+
},
42+
account: {
43+
authKey: process.env['AUTH_KEY']!,
44+
account: Number(process.env['QQ']!),
45+
},
46+
});
47+
mirai.on('message', msg => {
48+
if (msg.message.type === MessageType.FRIEND_MESSAGE) {
49+
if (msg.isPlainTextMessage()) {
50+
const text = msg.getPlainText();
51+
msg.reply(OutboundMessageChain.ofText(text)).catch(e => console.error(e));
52+
if (text.trim() === 'stophammertime') {
53+
mirai.close();
54+
}
55+
}
56+
}
57+
});
58+
mirai.on('connect', () => {
59+
console.log('Ready');
60+
});
61+
```

examples/PingService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const mirai = new MiraiClient({
1818
},
1919
});
2020
mirai.on('message', msg => {
21-
if (msg.message.type === MessageType.FRIEND_MESSAGE) {
21+
if (msg.message.type === MessageType.FRIEND_MESSAGE || msg.message.type === MessageType.GROUP_MESSAGE) {
2222
if (msg.isPlainTextMessage()) {
2323
const text = msg.getPlainText();
2424
msg.reply(OutboundMessageChain.ofText(text)).catch(e => console.error(e));

index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,11 @@ export class MiraiClient extends EventEmitter {
4646
private ws?: WebSocketService;
4747
private inbound?: InboundMessagingService;
4848
}
49+
50+
/* Re-exporting necessary stuff */
51+
52+
export { Config };
53+
export { InboundMessage };
54+
export * as Message from './src/objects/Message';
55+
export { OutboundMessageChain } from './src/objects/OutboundMessageChain';
56+
export { StatusCode } from './src/objects/StatusCode';

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
"@types/node": "^14.14.6",
1515
"@types/ws": "^7.2.9",
1616
"typescript": "^4.0.5"
17-
}
17+
},
18+
"files": [
19+
"build"
20+
]
1821
}

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
// "allowJs": true, /* Allow javascript files to be compiled. */
88
// "checkJs": true, /* Report errors in .js files. */
99
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
10-
// "declaration": true, /* Generates corresponding '.d.ts' file. */
10+
"declaration": true, /* Generates corresponding '.d.ts' file. */
1111
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
1212
// "sourceMap": true, /* Generates corresponding '.map' file. */
1313
// "outFile": "./", /* Concatenate and emit output to single file. */

0 commit comments

Comments
 (0)