@alemonjs/kook 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -0
- package/lib/index.d.ts +2 -8
- package/lib/index.js +37 -42
- package/package.json +15 -5
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# [https://alemonjs.com/](https://alemonjs.com/)
|
|
2
|
+
|
|
3
|
+
跨平台开发的事件驱动机器人
|
|
4
|
+
|
|
5
|
+
## USE
|
|
6
|
+
|
|
7
|
+
- kook
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
yarn add @alemonjs/kook
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- alemon.config.yaml
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
kook:
|
|
17
|
+
# 令牌
|
|
18
|
+
token: ''
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
> 完整的
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
kook:
|
|
25
|
+
# 令牌
|
|
26
|
+
token: ''
|
|
27
|
+
# 主人
|
|
28
|
+
master_id:
|
|
29
|
+
- ''
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Community
|
|
33
|
+
|
|
34
|
+
QQ Group 806943302
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Text, At, OnProcessor, useParse } from 'alemonjs';
|
|
1
|
+
import { defineBot, getConfig, Text, At, OnProcessor, useParse } from 'alemonjs';
|
|
2
2
|
import { KOOKClient } from 'chat-space';
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
var index = defineBot(() => {
|
|
5
|
+
const cfg = getConfig();
|
|
6
|
+
const config = cfg.value?.kook;
|
|
7
|
+
if (!config)
|
|
8
|
+
return;
|
|
9
9
|
// 创建客户端
|
|
10
10
|
const client = new KOOKClient({
|
|
11
11
|
token: config.token
|
|
@@ -98,45 +98,40 @@ const login = (config) => {
|
|
|
98
98
|
client.on('ERROR', msg => {
|
|
99
99
|
console.error(msg);
|
|
100
100
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
101
|
+
return {
|
|
102
|
+
api: {
|
|
103
|
+
use: {
|
|
104
|
+
send: (event, val) => {
|
|
105
|
+
if (val.length < 0)
|
|
106
|
+
return Promise.all([]);
|
|
107
|
+
const content = useParse(val, 'Text');
|
|
108
|
+
if (content) {
|
|
109
|
+
return Promise.all([content].map(item => client.createMessage({
|
|
110
|
+
type: 9,
|
|
111
|
+
target_id: event.ChannelId,
|
|
112
|
+
content: item
|
|
113
|
+
})));
|
|
114
|
+
}
|
|
115
|
+
const images = useParse(val, 'Image');
|
|
116
|
+
if (images) {
|
|
117
|
+
return Promise.all(images.map(async (item) => {
|
|
118
|
+
// 上传图片
|
|
119
|
+
const res = await client.postImage(item);
|
|
120
|
+
if (!res)
|
|
121
|
+
return Promise.resolve();
|
|
122
|
+
// 发送消息
|
|
123
|
+
return await client.createMessage({
|
|
124
|
+
type: 2,
|
|
115
125
|
target_id: event.ChannelId,
|
|
116
|
-
content:
|
|
126
|
+
content: res.data.url
|
|
117
127
|
});
|
|
118
|
-
}
|
|
119
|
-
const images = useParse(val, 'Image');
|
|
120
|
-
if (images) {
|
|
121
|
-
return Promise.all(images.map(async (item) => {
|
|
122
|
-
// 上传图片
|
|
123
|
-
const res = await client.postImage(item);
|
|
124
|
-
if (!res)
|
|
125
|
-
return Promise.resolve();
|
|
126
|
-
// 发送消息
|
|
127
|
-
return await client.createMessage({
|
|
128
|
-
type: 2,
|
|
129
|
-
target_id: event.ChannelId,
|
|
130
|
-
content: res.data.url
|
|
131
|
-
});
|
|
132
|
-
}));
|
|
133
|
-
}
|
|
134
|
-
return Promise.resolve();
|
|
128
|
+
}));
|
|
135
129
|
}
|
|
130
|
+
return Promise.all([]);
|
|
136
131
|
}
|
|
137
132
|
}
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
};
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
});
|
|
141
136
|
|
|
142
|
-
export {
|
|
137
|
+
export { index as default };
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alemonjs/kook",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
5
|
-
"author": "
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "kook-bot",
|
|
5
|
+
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"chat-space": "^0.0.
|
|
10
|
+
"chat-space": "^0.0.6"
|
|
11
11
|
},
|
|
12
12
|
"types": "lib",
|
|
13
13
|
"exports": {
|
|
@@ -16,8 +16,18 @@
|
|
|
16
16
|
"types": "./lib/index.d.ts"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"alemonjs",
|
|
21
|
+
"kook",
|
|
22
|
+
"bot",
|
|
23
|
+
"chat-bot"
|
|
24
|
+
],
|
|
19
25
|
"publishConfig": {
|
|
20
|
-
"access": "public",
|
|
21
26
|
"registry": "https://registry.npmjs.org"
|
|
27
|
+
},
|
|
28
|
+
"bugs": "https://github.com/ningmengchongshui/alemonjs/issues",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "https://github.com/ningmengchongshui/alemonjs.git"
|
|
22
32
|
}
|
|
23
33
|
}
|