@alemonjs/kook 0.2.2 → 0.2.5
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/dist/assets/index.css +1 -0
- package/dist/assets/index.js +49 -0
- package/dist/index.html +15 -0
- package/lib/desktop.d.ts +3 -0
- package/lib/desktop.js +59 -0
- package/lib/index.d.ts +7 -7
- package/lib/index.js +289 -284
- package/lib/sdk/core/config.js +40 -39
- package/lib/sdk/core/utils/from.js +32 -25
- package/lib/sdk/platform/kook/sdk/api.d.ts +267 -279
- package/lib/sdk/platform/kook/sdk/api.js +265 -262
- package/lib/sdk/platform/kook/sdk/config.js +4 -4
- package/lib/sdk/platform/kook/sdk/conversation.js +116 -108
- package/lib/sdk/platform/kook/sdk/message/INTERACTION.d.ts +3 -3
- package/lib/sdk/platform/kook/sdk/message/MEMBER_ADD.d.ts +3 -3
- package/lib/sdk/platform/kook/sdk/message/MEMBER_REMOVE.d.ts +3 -3
- package/lib/sdk/platform/kook/sdk/message/MESSAGES_DIRECT.d.ts +3 -3
- package/lib/sdk/platform/kook/sdk/message/MESSAGES_PUBLIC.d.ts +3 -3
- package/lib/sdk/platform/kook/sdk/message/REACTIONS.d.ts +3 -3
- package/lib/sdk/platform/kook/sdk/message.d.ts +15 -15
- package/lib/sdk/platform/kook/sdk/message.js +16 -16
- package/lib/sdk/platform/kook/sdk/typings.d.ts +138 -167
- package/lib/sdk/platform/kook/sdk/typings.js +164 -164
- package/lib/sdk/platform/kook/sdk/wss.d.ts +22 -22
- package/lib/sdk/platform/kook/sdk/wss.js +145 -138
- package/lib/sdk/platform/kook/sdk/wss.types.d.ts +5 -5
- package/package.json +30 -6
package/lib/desktop.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { readFileSync } from 'fs';
|
|
2
|
+
import { dirname, join } from 'path';
|
|
3
|
+
import { fileURLToPath } from 'url';
|
|
4
|
+
import { getConfig, getConfigValue } from 'alemonjs';
|
|
5
|
+
|
|
6
|
+
// 当前目录
|
|
7
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
8
|
+
// 被激活的时候。
|
|
9
|
+
const activate = context => {
|
|
10
|
+
// 创建一个 webview。
|
|
11
|
+
const webView = context.createSidebarWebView(context);
|
|
12
|
+
// 当命令被触发的时候。
|
|
13
|
+
context.onCommand('open.kook', () => {
|
|
14
|
+
const dir = join(__dirname, '../', 'dist', 'index.html');
|
|
15
|
+
const scriptReg = /<script.*?src="(.+?)".*?>/;
|
|
16
|
+
const styleReg = /<link.*?href="(.+?)".*?>/;
|
|
17
|
+
// 创建 webview 路径
|
|
18
|
+
const styleUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.css'));
|
|
19
|
+
const scriptUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.js'));
|
|
20
|
+
// 确保路径存在
|
|
21
|
+
const html = readFileSync(dir, 'utf-8')
|
|
22
|
+
.replace(scriptReg, `<script type="module" crossorigin src="${scriptUri}"></script>`)
|
|
23
|
+
.replace(styleReg, `<link rel="stylesheet" crossorigin href="${styleUri}">`);
|
|
24
|
+
// 立即渲染 webview
|
|
25
|
+
webView.loadWebView(html);
|
|
26
|
+
});
|
|
27
|
+
// 监听 webview 的消息。
|
|
28
|
+
webView.onMessage(data => {
|
|
29
|
+
try {
|
|
30
|
+
if (data.type === 'kook.form.save') {
|
|
31
|
+
const CIG = data.data;
|
|
32
|
+
const config = getConfig();
|
|
33
|
+
const value = config.value ?? {};
|
|
34
|
+
value['kook'] = {
|
|
35
|
+
token: CIG.token ?? '',
|
|
36
|
+
// master_key 12121,1313,1313,13 转为数组
|
|
37
|
+
master_key: CIG.master_key.split(',')
|
|
38
|
+
};
|
|
39
|
+
config.saveValue(value);
|
|
40
|
+
context.notification('KOOK 配置保存成功~');
|
|
41
|
+
}
|
|
42
|
+
else if (data.type === 'kook.init') {
|
|
43
|
+
let config = getConfigValue();
|
|
44
|
+
if (!config)
|
|
45
|
+
config = {};
|
|
46
|
+
// 发送消息
|
|
47
|
+
webView.postMessage({
|
|
48
|
+
type: 'kook.init',
|
|
49
|
+
data: config.qq_bot ?? {}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
console.error(e);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export { activate };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as alemonjs from 'alemonjs'
|
|
2
|
-
import { KOOKClient } from './sdk/platform/kook/sdk/wss.js'
|
|
1
|
+
import * as alemonjs from 'alemonjs';
|
|
2
|
+
import { KOOKClient } from './sdk/platform/kook/sdk/wss.js';
|
|
3
3
|
|
|
4
|
-
type Client = typeof KOOKClient.prototype
|
|
5
|
-
declare const platform =
|
|
6
|
-
declare const client: Client
|
|
7
|
-
declare const _default: () => alemonjs.ClientAPI
|
|
4
|
+
type Client = typeof KOOKClient.prototype;
|
|
5
|
+
declare const platform = "kook";
|
|
6
|
+
declare const client: Client;
|
|
7
|
+
declare const _default: () => alemonjs.ClientAPI;
|
|
8
8
|
|
|
9
|
-
export { type Client, client, _default as default, platform }
|
|
9
|
+
export { type Client, client, _default as default, platform };
|
package/lib/index.js
CHANGED
|
@@ -1,291 +1,296 @@
|
|
|
1
|
-
import { defineBot, getConfigValue, useUserHashKey, OnProcessor } from 'alemonjs'
|
|
2
|
-
import 'fs'
|
|
3
|
-
import 'axios'
|
|
4
|
-
import 'path'
|
|
5
|
-
import 'qrcode'
|
|
6
|
-
import 'public-ip'
|
|
7
|
-
import 'stream'
|
|
8
|
-
import 'file-type'
|
|
9
|
-
import 'form-data'
|
|
10
|
-
import './sdk/platform/kook/sdk/typings.js'
|
|
11
|
-
import { KOOKClient } from './sdk/platform/kook/sdk/wss.js'
|
|
1
|
+
import { defineBot, getConfigValue, useUserHashKey, OnProcessor } from 'alemonjs';
|
|
2
|
+
import 'fs';
|
|
3
|
+
import 'axios';
|
|
4
|
+
import 'path';
|
|
5
|
+
import 'qrcode';
|
|
6
|
+
import 'public-ip';
|
|
7
|
+
import 'stream';
|
|
8
|
+
import 'file-type';
|
|
9
|
+
import 'form-data';
|
|
10
|
+
import './sdk/platform/kook/sdk/typings.js';
|
|
11
|
+
import { KOOKClient } from './sdk/platform/kook/sdk/wss.js';
|
|
12
12
|
|
|
13
|
-
const platform = 'kook'
|
|
14
|
-
const client = new Proxy(
|
|
15
|
-
{},
|
|
16
|
-
{
|
|
13
|
+
const platform = 'kook';
|
|
14
|
+
const client = new Proxy({}, {
|
|
17
15
|
get: (_, prop) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
if (prop in global.client) {
|
|
17
|
+
const original = global.client[prop];
|
|
18
|
+
// 防止函数内this丢失
|
|
19
|
+
return typeof original === 'function' ? original.bind(global.client) : original;
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
)
|
|
23
|
+
});
|
|
25
24
|
var index = defineBot(() => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
25
|
+
let value = getConfigValue();
|
|
26
|
+
if (!value)
|
|
27
|
+
value = {};
|
|
28
|
+
const config = value[platform];
|
|
29
|
+
// 创建客户端
|
|
30
|
+
const client = new KOOKClient({
|
|
31
|
+
token: config.token
|
|
32
|
+
});
|
|
33
|
+
// 连接
|
|
34
|
+
client.connect();
|
|
35
|
+
client.on('MESSAGES_DIRECT', async (event) => {
|
|
36
|
+
// 过滤机器人
|
|
37
|
+
if (event.extra?.author?.bot)
|
|
38
|
+
return false;
|
|
39
|
+
// 主人
|
|
40
|
+
const master_key = config?.master_key ?? [];
|
|
41
|
+
const isMaster = master_key.includes(event.author_id);
|
|
42
|
+
// 头像
|
|
43
|
+
const avatar = event.extra.author.avatar;
|
|
44
|
+
// 获取消息
|
|
45
|
+
let msg = event.content;
|
|
46
|
+
const url = avatar.substring(0, avatar.indexOf('?'));
|
|
47
|
+
const UserAvatar = {
|
|
48
|
+
toBuffer: async () => {
|
|
49
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
50
|
+
return Buffer.from(arrayBuffer);
|
|
51
|
+
},
|
|
52
|
+
toBase64: async () => {
|
|
53
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
54
|
+
return Buffer.from(arrayBuffer).toString('base64');
|
|
55
|
+
},
|
|
56
|
+
toURL: async () => {
|
|
57
|
+
return url;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const UserId = event.author_id;
|
|
61
|
+
const UserKey = useUserHashKey({
|
|
62
|
+
Platform: platform,
|
|
63
|
+
UserId
|
|
64
|
+
});
|
|
65
|
+
// 定义消
|
|
66
|
+
const e = {
|
|
67
|
+
name: 'private.message.create',
|
|
68
|
+
// 事件类型
|
|
69
|
+
Platform: platform,
|
|
70
|
+
// 用户Id
|
|
71
|
+
UserId: UserId,
|
|
72
|
+
UserKey,
|
|
73
|
+
UserName: event.extra.author.username,
|
|
74
|
+
UserAvatar: UserAvatar,
|
|
75
|
+
IsMaster: isMaster,
|
|
76
|
+
IsBot: false,
|
|
77
|
+
// message
|
|
78
|
+
MessageId: event.msg_id,
|
|
79
|
+
MessageText: msg,
|
|
80
|
+
OpenId: '',
|
|
81
|
+
CreateAt: Date.now(),
|
|
82
|
+
//
|
|
83
|
+
tag: 'MESSAGES_PUBLIC',
|
|
84
|
+
value: null
|
|
85
|
+
};
|
|
86
|
+
// 当访问的时候获取
|
|
87
|
+
Object.defineProperty(e, 'value', {
|
|
88
|
+
get() {
|
|
89
|
+
return event;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
// 处理消息
|
|
93
|
+
OnProcessor(e, 'private.message.create');
|
|
94
|
+
});
|
|
95
|
+
// 监听消息
|
|
96
|
+
client.on('MESSAGES_PUBLIC', async (event) => {
|
|
97
|
+
// 过滤机器人
|
|
98
|
+
if (event.extra?.author?.bot)
|
|
99
|
+
return false;
|
|
100
|
+
// 创建私聊标记
|
|
101
|
+
const data = await client.userChatCreate(event.extra.author.id).then(res => res?.data);
|
|
102
|
+
// 主人
|
|
103
|
+
const master_key = config?.master_key ?? [];
|
|
104
|
+
const isMaster = master_key.includes(event.author_id);
|
|
105
|
+
// 头像
|
|
106
|
+
const avatar = event.extra.author.avatar;
|
|
107
|
+
// 获取消息
|
|
108
|
+
let msg = event.content;
|
|
109
|
+
/**
|
|
110
|
+
* 艾特类型所得到的
|
|
111
|
+
* 包括机器人在内
|
|
112
|
+
*/
|
|
113
|
+
const mention_role_part = event.extra.kmarkdown?.mention_role_part ?? [];
|
|
114
|
+
for (const item of mention_role_part) {
|
|
115
|
+
msg = msg.replace(`(rol)${item.role_id}(rol)`, '').trim();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* 艾特用户所得到的
|
|
119
|
+
*/
|
|
120
|
+
const mention_part = event.extra.kmarkdown?.mention_part ?? [];
|
|
121
|
+
for (const item of mention_part) {
|
|
122
|
+
msg = msg.replace(`(met)${item.id}(met)`, '').trim();
|
|
123
|
+
}
|
|
124
|
+
const url = avatar.substring(0, avatar.indexOf('?'));
|
|
125
|
+
const UserAvatar = {
|
|
126
|
+
toBuffer: async () => {
|
|
127
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
128
|
+
return Buffer.from(arrayBuffer);
|
|
129
|
+
},
|
|
130
|
+
toBase64: async () => {
|
|
131
|
+
const arrayBuffer = await fetch(url).then(res => res.arrayBuffer());
|
|
132
|
+
return Buffer.from(arrayBuffer).toString('base64');
|
|
133
|
+
},
|
|
134
|
+
toURL: async () => {
|
|
135
|
+
return url;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const UserId = event.author_id;
|
|
139
|
+
const UserKey = useUserHashKey({
|
|
140
|
+
Platform: platform,
|
|
141
|
+
UserId
|
|
142
|
+
});
|
|
143
|
+
// 定义消
|
|
144
|
+
const e = {
|
|
145
|
+
name: 'message.create',
|
|
146
|
+
// 事件类型
|
|
147
|
+
Platform: platform,
|
|
148
|
+
//
|
|
149
|
+
GuildId: event.extra.guild_id,
|
|
150
|
+
ChannelId: event.target_id,
|
|
151
|
+
// 用户Id
|
|
152
|
+
UserId: UserId,
|
|
153
|
+
UserKey,
|
|
154
|
+
UserName: event.extra.author.username,
|
|
155
|
+
UserAvatar: UserAvatar,
|
|
156
|
+
IsMaster: isMaster,
|
|
157
|
+
IsBot: false,
|
|
158
|
+
// message
|
|
159
|
+
MessageId: event.msg_id,
|
|
160
|
+
MessageText: msg,
|
|
161
|
+
OpenId: data?.code,
|
|
162
|
+
CreateAt: Date.now(),
|
|
163
|
+
//
|
|
164
|
+
tag: 'MESSAGES_PUBLIC',
|
|
165
|
+
value: null
|
|
166
|
+
};
|
|
167
|
+
// 当访问的时候获取
|
|
168
|
+
Object.defineProperty(e, 'value', {
|
|
169
|
+
get() {
|
|
170
|
+
return event;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
// 处理消息
|
|
174
|
+
OnProcessor(e, 'message.create');
|
|
175
|
+
});
|
|
176
|
+
// 发送错误时
|
|
177
|
+
client.on('ERROR', msg => {
|
|
178
|
+
console.error(msg);
|
|
179
|
+
});
|
|
180
|
+
// 客户端全局化。
|
|
181
|
+
global.client = client;
|
|
182
|
+
return {
|
|
183
|
+
api: {
|
|
184
|
+
use: {
|
|
185
|
+
send: (event, val) => {
|
|
186
|
+
if (val.length < 0)
|
|
187
|
+
return Promise.all([]);
|
|
188
|
+
const content = val
|
|
189
|
+
.filter(item => item.type == 'Link' || item.type == 'Mention' || item.type == 'Text')
|
|
190
|
+
.map(item => {
|
|
191
|
+
if (item.type == 'Link') {
|
|
192
|
+
return `[${item.options?.title ?? item.value}](${item.value})`;
|
|
193
|
+
}
|
|
194
|
+
else if (item.type == 'Mention') {
|
|
195
|
+
if (item.value == 'everyone' ||
|
|
196
|
+
item.value == 'all' ||
|
|
197
|
+
item.value == '' ||
|
|
198
|
+
typeof item.value != 'string') {
|
|
199
|
+
return `(met)all(met)`;
|
|
200
|
+
}
|
|
201
|
+
if (item.options?.belong == 'user') {
|
|
202
|
+
return `(met)${item.value}(met)`;
|
|
203
|
+
}
|
|
204
|
+
else if (item.options?.belong == 'channel') {
|
|
205
|
+
return `(chn)${item.value}(chn)`;
|
|
206
|
+
}
|
|
207
|
+
return '';
|
|
208
|
+
}
|
|
209
|
+
else if (item.type == 'Text') {
|
|
210
|
+
if (item.options?.style == 'block') {
|
|
211
|
+
return `\`${item.value}\``;
|
|
212
|
+
}
|
|
213
|
+
else if (item.options?.style == 'italic') {
|
|
214
|
+
return `*${item.value}*`;
|
|
215
|
+
}
|
|
216
|
+
else if (item.options?.style == 'bold') {
|
|
217
|
+
return `**${item.value}**`;
|
|
218
|
+
}
|
|
219
|
+
else if (item.options?.style == 'strikethrough') {
|
|
220
|
+
return `~~${item.value}~~`;
|
|
221
|
+
}
|
|
222
|
+
else if (item.options?.style == 'boldItalic') {
|
|
223
|
+
return `***${item.value}***`;
|
|
224
|
+
}
|
|
225
|
+
return item.value;
|
|
226
|
+
}
|
|
227
|
+
})
|
|
228
|
+
.join('');
|
|
229
|
+
if (content) {
|
|
230
|
+
return Promise.all([content].map(item => client.createMessage({
|
|
231
|
+
type: 9,
|
|
232
|
+
target_id: event.ChannelId,
|
|
233
|
+
content: item
|
|
234
|
+
})));
|
|
235
|
+
}
|
|
236
|
+
const images = val.filter(item => item.type == 'Image').map(item => item.value);
|
|
237
|
+
if (images) {
|
|
238
|
+
return Promise.all(images.map(async (item) => {
|
|
239
|
+
// 上传图片
|
|
240
|
+
const res = await client.postImage(item);
|
|
241
|
+
if (!res)
|
|
242
|
+
return Promise.resolve();
|
|
243
|
+
// 发送消息
|
|
244
|
+
return await client.createMessage({
|
|
245
|
+
type: 2,
|
|
246
|
+
target_id: event.ChannelId,
|
|
247
|
+
content: res.data.url
|
|
248
|
+
});
|
|
249
|
+
}));
|
|
250
|
+
}
|
|
251
|
+
return Promise.all([]);
|
|
252
|
+
},
|
|
253
|
+
mention: async (e) => {
|
|
254
|
+
const event = e.value;
|
|
255
|
+
const MessageMention = [];
|
|
256
|
+
/**
|
|
257
|
+
* 艾特类型所得到的,包括机器人在内
|
|
258
|
+
*/
|
|
259
|
+
const mention_role_part = event.extra.kmarkdown?.mention_role_part ?? [];
|
|
260
|
+
for (const item of mention_role_part) {
|
|
261
|
+
MessageMention.push({
|
|
262
|
+
UserId: item.role_id,
|
|
263
|
+
UserName: item.name,
|
|
264
|
+
UserKey: useUserHashKey({
|
|
265
|
+
Platform: platform,
|
|
266
|
+
UserId: item.role_id
|
|
267
|
+
}),
|
|
268
|
+
IsMaster: false,
|
|
269
|
+
IsBot: true
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* 艾特用户所得到的
|
|
274
|
+
*/
|
|
275
|
+
const mention_part = event.extra.kmarkdown?.mention_part ?? [];
|
|
276
|
+
for (const item of mention_part) {
|
|
277
|
+
MessageMention.push({
|
|
278
|
+
// avatar: item.avatar,
|
|
279
|
+
UserId: item.id,
|
|
280
|
+
UserName: item.username,
|
|
281
|
+
UserKey: useUserHashKey({
|
|
282
|
+
Platform: platform,
|
|
283
|
+
UserId: item.role_id
|
|
284
|
+
}),
|
|
285
|
+
IsMaster: false,
|
|
286
|
+
IsBot: false
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
return MessageMention;
|
|
214
290
|
}
|
|
215
|
-
|
|
216
|
-
}
|
|
217
|
-
})
|
|
218
|
-
.join('')
|
|
219
|
-
if (content) {
|
|
220
|
-
return Promise.all(
|
|
221
|
-
[content].map(item =>
|
|
222
|
-
client.createMessage({
|
|
223
|
-
type: 9,
|
|
224
|
-
target_id: event.ChannelId,
|
|
225
|
-
content: item
|
|
226
|
-
})
|
|
227
|
-
)
|
|
228
|
-
)
|
|
229
|
-
}
|
|
230
|
-
const images = val.filter(item => item.type == 'Image').map(item => item.value)
|
|
231
|
-
if (images) {
|
|
232
|
-
return Promise.all(
|
|
233
|
-
images.map(async item => {
|
|
234
|
-
// 上传图片
|
|
235
|
-
const res = await client.postImage(item)
|
|
236
|
-
if (!res) return Promise.resolve()
|
|
237
|
-
// 发送消息
|
|
238
|
-
return await client.createMessage({
|
|
239
|
-
type: 2,
|
|
240
|
-
target_id: event.ChannelId,
|
|
241
|
-
content: res.data.url
|
|
242
|
-
})
|
|
243
|
-
})
|
|
244
|
-
)
|
|
245
|
-
}
|
|
246
|
-
return Promise.all([])
|
|
247
|
-
},
|
|
248
|
-
mention: async e => {
|
|
249
|
-
const event = e.value
|
|
250
|
-
const MessageMention = []
|
|
251
|
-
/**
|
|
252
|
-
* 艾特类型所得到的,包括机器人在内
|
|
253
|
-
*/
|
|
254
|
-
const mention_role_part = event.extra.kmarkdown?.mention_role_part ?? []
|
|
255
|
-
for (const item of mention_role_part) {
|
|
256
|
-
MessageMention.push({
|
|
257
|
-
UserId: item.role_id,
|
|
258
|
-
UserName: item.name,
|
|
259
|
-
UserKey: useUserHashKey({
|
|
260
|
-
Platform: platform,
|
|
261
|
-
UserId: item.role_id
|
|
262
|
-
}),
|
|
263
|
-
IsMaster: false,
|
|
264
|
-
IsBot: true
|
|
265
|
-
})
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* 艾特用户所得到的
|
|
269
|
-
*/
|
|
270
|
-
const mention_part = event.extra.kmarkdown?.mention_part ?? []
|
|
271
|
-
for (const item of mention_part) {
|
|
272
|
-
MessageMention.push({
|
|
273
|
-
// avatar: item.avatar,
|
|
274
|
-
UserId: item.id,
|
|
275
|
-
UserName: item.username,
|
|
276
|
-
UserKey: useUserHashKey({
|
|
277
|
-
Platform: platform,
|
|
278
|
-
UserId: item.role_id
|
|
279
|
-
}),
|
|
280
|
-
IsMaster: false,
|
|
281
|
-
IsBot: false
|
|
282
|
-
})
|
|
283
|
-
}
|
|
284
|
-
return MessageMention
|
|
291
|
+
}
|
|
285
292
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
})
|
|
293
|
+
};
|
|
294
|
+
});
|
|
290
295
|
|
|
291
|
-
export { client, index as default, platform }
|
|
296
|
+
export { client, index as default, platform };
|