@alemonjs/discord 2.1.0-alpha.13 → 2.1.0-alpha.15
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/lib/desktop.js +3 -2
- package/lib/index.js +22 -19
- package/lib/sdk/api.d.ts +11 -4
- package/lib/sdk/api.js +301 -262
- package/lib/sdk/createPicFrom.js +8 -4
- package/lib/sdk/wss.js +140 -107
- package/lib/send.js +34 -33
- package/package.json +1 -1
package/lib/desktop.js
CHANGED
|
@@ -20,7 +20,7 @@ const activate = context => {
|
|
|
20
20
|
const scriptUri = context.createExtensionDir(join(__dirname, '../', 'dist', 'assets', 'index.js'));
|
|
21
21
|
// 确保路径存在
|
|
22
22
|
const html = readFileSync(dir, 'utf-8')
|
|
23
|
-
.replace(iconReg,
|
|
23
|
+
.replace(iconReg, '')
|
|
24
24
|
.replace(scriptReg, `<script type="module" crossorigin src="${scriptUri}"></script>`)
|
|
25
25
|
.replace(styleReg, `<link rel="stylesheet" crossorigin href="${styleUri}">`);
|
|
26
26
|
// 立即渲染 webview
|
|
@@ -42,8 +42,9 @@ const activate = context => {
|
|
|
42
42
|
}
|
|
43
43
|
else if (data.type === 'discord.init') {
|
|
44
44
|
let config = getConfigValue();
|
|
45
|
-
if (!config)
|
|
45
|
+
if (!config) {
|
|
46
46
|
config = {};
|
|
47
|
+
}
|
|
47
48
|
// 发送消息
|
|
48
49
|
webView.postMessage({
|
|
49
50
|
type: 'discord.init',
|
package/lib/index.js
CHANGED
|
@@ -17,7 +17,7 @@ var index = () => {
|
|
|
17
17
|
// 创建客户端
|
|
18
18
|
const client = new DCClient();
|
|
19
19
|
// 连接
|
|
20
|
-
client.connect();
|
|
20
|
+
void client.connect();
|
|
21
21
|
/**
|
|
22
22
|
* 创建用户头像
|
|
23
23
|
* @param UserId
|
|
@@ -28,10 +28,11 @@ var index = () => {
|
|
|
28
28
|
return client.userAvatar(UserId, avatar);
|
|
29
29
|
};
|
|
30
30
|
// 监听消息
|
|
31
|
-
client.on('MESSAGE_CREATE',
|
|
31
|
+
client.on('MESSAGE_CREATE', event => {
|
|
32
32
|
// 消除bot消息
|
|
33
|
-
if (event.author?.bot)
|
|
33
|
+
if (event.author?.bot) {
|
|
34
34
|
return;
|
|
35
|
+
}
|
|
35
36
|
// 艾特消息处理
|
|
36
37
|
const at_users = [];
|
|
37
38
|
// 获取艾特用户
|
|
@@ -42,13 +43,13 @@ var index = () => {
|
|
|
42
43
|
}
|
|
43
44
|
// 清除 @ 相关的消息
|
|
44
45
|
let msg = event.content;
|
|
45
|
-
for
|
|
46
|
+
for (const item of at_users) {
|
|
46
47
|
msg = msg.replace(`<@${item.id}>`, '').trim();
|
|
47
48
|
}
|
|
48
49
|
const UserId = event.author.id;
|
|
49
50
|
const [isMaster, UserKey] = getMaster(UserId);
|
|
50
51
|
const UserAvatar = createUserAvatar(UserId, event.author.avatar);
|
|
51
|
-
if (event.type
|
|
52
|
+
if (event.type === 0 && event.member) {
|
|
52
53
|
const e = {
|
|
53
54
|
name: 'message.create',
|
|
54
55
|
// 事件类型
|
|
@@ -75,7 +76,7 @@ var index = () => {
|
|
|
75
76
|
};
|
|
76
77
|
cbp.send(e);
|
|
77
78
|
}
|
|
78
|
-
else if (event.type
|
|
79
|
+
else if (event.type === 0 && !event.member) {
|
|
79
80
|
// 处理消息
|
|
80
81
|
const e = {
|
|
81
82
|
name: 'private.message.create',
|
|
@@ -160,10 +161,8 @@ var index = () => {
|
|
|
160
161
|
};
|
|
161
162
|
cbp.send(e);
|
|
162
163
|
}
|
|
163
|
-
client.interactionsCallback(event.id, event.token, MessageText);
|
|
164
|
+
void client.interactionsCallback(event.id, event.token, MessageText);
|
|
164
165
|
});
|
|
165
|
-
// 发送错误时
|
|
166
|
-
client.on('ERROR', console.error);
|
|
167
166
|
const api = {
|
|
168
167
|
active: {
|
|
169
168
|
send: {
|
|
@@ -183,12 +182,12 @@ var index = () => {
|
|
|
183
182
|
return [];
|
|
184
183
|
}
|
|
185
184
|
const tag = event.tag;
|
|
186
|
-
if (tag
|
|
185
|
+
if (tag === 'message.create') {
|
|
187
186
|
const ChannelId = event.value.channel_id;
|
|
188
187
|
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
189
188
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
190
189
|
}
|
|
191
|
-
else if (tag
|
|
190
|
+
else if (tag === 'private.message.create') {
|
|
192
191
|
const UserId = event.value.author.id;
|
|
193
192
|
const ChannelId = event.value.channel_id;
|
|
194
193
|
const res = await senduser(client, {
|
|
@@ -197,12 +196,12 @@ var index = () => {
|
|
|
197
196
|
}, val);
|
|
198
197
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
199
198
|
}
|
|
200
|
-
else if (tag
|
|
199
|
+
else if (tag === 'interaction.create') {
|
|
201
200
|
const ChannelId = event.value.channel_id;
|
|
202
201
|
const res = await sendchannel(client, { channel_id: ChannelId }, val);
|
|
203
202
|
return [createResult(ResultCode.Ok, '请求完成', res)];
|
|
204
203
|
}
|
|
205
|
-
else if (tag
|
|
204
|
+
else if (tag === 'private.interaction.create') {
|
|
206
205
|
const UserId = event.value.user.id;
|
|
207
206
|
const ChannelId = event.value.channel_id;
|
|
208
207
|
const res = await senduser(client, {
|
|
@@ -213,7 +212,7 @@ var index = () => {
|
|
|
213
212
|
}
|
|
214
213
|
return [];
|
|
215
214
|
},
|
|
216
|
-
mention:
|
|
215
|
+
mention: e => {
|
|
217
216
|
const event = e.value;
|
|
218
217
|
const MessageMention = event.mentions.map(item => {
|
|
219
218
|
const UserId = item.id;
|
|
@@ -228,11 +227,13 @@ var index = () => {
|
|
|
228
227
|
UserKey
|
|
229
228
|
};
|
|
230
229
|
});
|
|
231
|
-
return
|
|
230
|
+
return new Promise(resolve => {
|
|
231
|
+
resolve(MessageMention);
|
|
232
|
+
});
|
|
232
233
|
}
|
|
233
234
|
}
|
|
234
235
|
};
|
|
235
|
-
|
|
236
|
+
const onactions = async (data, consume) => {
|
|
236
237
|
if (data.action === 'message.send') {
|
|
237
238
|
const event = data.payload.event;
|
|
238
239
|
const paramFormat = data.payload.params.format;
|
|
@@ -256,8 +257,9 @@ var index = () => {
|
|
|
256
257
|
const res = await api.use.mention(event);
|
|
257
258
|
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
258
259
|
}
|
|
259
|
-
}
|
|
260
|
-
cbp.
|
|
260
|
+
};
|
|
261
|
+
cbp.onactions((data, consume) => void onactions(data, consume));
|
|
262
|
+
const onapis = async (data, consume) => {
|
|
261
263
|
const key = data.payload?.key;
|
|
262
264
|
if (client[key]) {
|
|
263
265
|
// 如果 client 上有对应的 key,直接调用。
|
|
@@ -265,7 +267,8 @@ var index = () => {
|
|
|
265
267
|
const res = await client[key](...params);
|
|
266
268
|
consume([createResult(ResultCode.Ok, '请求完成', res)]);
|
|
267
269
|
}
|
|
268
|
-
}
|
|
270
|
+
};
|
|
271
|
+
cbp.onapis((data, consume) => void onapis(data, consume));
|
|
269
272
|
};
|
|
270
273
|
|
|
271
274
|
export { index as default, platform };
|
package/lib/sdk/api.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import * as axios from 'axios';
|
|
2
|
-
import { AxiosRequestConfig } from 'axios';
|
|
3
1
|
import FormData from 'form-data';
|
|
2
|
+
import { AxiosRequestConfig } from 'axios';
|
|
4
3
|
import { Readable } from 'stream';
|
|
5
4
|
import { MessageData } from './typings.js';
|
|
6
5
|
|
|
@@ -13,13 +12,13 @@ declare class DCAPI {
|
|
|
13
12
|
* @param opstion
|
|
14
13
|
* @returns
|
|
15
14
|
*/
|
|
16
|
-
request(options: AxiosRequestConfig): Promise<
|
|
15
|
+
request(options: AxiosRequestConfig): Promise<any>;
|
|
17
16
|
/**
|
|
18
17
|
* cdn基础请求
|
|
19
18
|
* @param options
|
|
20
19
|
* @returns
|
|
21
20
|
*/
|
|
22
|
-
requestCDN(options: AxiosRequestConfig): Promise<
|
|
21
|
+
requestCDN(options: AxiosRequestConfig): Promise<any>;
|
|
23
22
|
/**
|
|
24
23
|
* 创建用户url地址
|
|
25
24
|
* @param user_id
|
|
@@ -42,6 +41,14 @@ declare class DCAPI {
|
|
|
42
41
|
* @returns
|
|
43
42
|
*/
|
|
44
43
|
channelsMessagesForm(channel_id: string, param?: MessageData, img?: string | Buffer | Readable): Promise<any>;
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param channel_id
|
|
47
|
+
* @param data
|
|
48
|
+
* @param headers
|
|
49
|
+
* @returns
|
|
50
|
+
*/
|
|
51
|
+
channelsMessages(channel_id: string, data?: MessageData): Promise<any>;
|
|
45
52
|
/**
|
|
46
53
|
* ************
|
|
47
54
|
* 消息-图片接口
|