@satorijs/adapter-discord 3.2.0 → 3.2.1
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/bot.d.ts +3 -4
- package/lib/index.js +59 -53
- package/lib/index.js.map +3 -3
- package/lib/sender.d.ts +7 -4
- package/package.json +2 -2
package/lib/bot.d.ts
CHANGED
|
@@ -7,13 +7,12 @@ export declare class DiscordBot<C extends Context = Context> extends Bot<C, Disc
|
|
|
7
7
|
internal: Internal;
|
|
8
8
|
constructor(ctx: C, config: DiscordBot.Config);
|
|
9
9
|
getSelf(): Promise<import("@satorijs/core").User>;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
sendPrivateMessage(channelId: string, content: string | segment): Promise<string[]>;
|
|
10
|
+
sendMessage(channelId: string, content: string | segment, guildId?: string): any;
|
|
11
|
+
sendPrivateMessage(channelId: string, content: string | segment): any;
|
|
13
12
|
deleteMessage(channelId: string, messageId: string): Promise<void>;
|
|
14
13
|
editMessage(channelId: string, messageId: string, content: string | segment): Promise<void>;
|
|
15
14
|
getMessage(channelId: string, messageId: string): Promise<Message>;
|
|
16
|
-
getMessageList(channelId: string, before?: string):
|
|
15
|
+
getMessageList(channelId: string, before?: string): Promise<Message[]>;
|
|
17
16
|
getUser(userId: string): Promise<import("@satorijs/core").User>;
|
|
18
17
|
getGuildMemberList(guildId: string): Promise<import("@satorijs/core").User[]>;
|
|
19
18
|
getChannel(channelId: string): Promise<import("@satorijs/core").Channel>;
|
package/lib/index.js
CHANGED
|
@@ -213,10 +213,8 @@ var Sender = class {
|
|
|
213
213
|
this.url = url;
|
|
214
214
|
this.results = [];
|
|
215
215
|
this.errors = [];
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
const sender = new Sender(bot, url);
|
|
219
|
-
return sender.sendMessage.bind(sender);
|
|
216
|
+
this.buffer = "";
|
|
217
|
+
this.addition = {};
|
|
220
218
|
}
|
|
221
219
|
async post(data, headers) {
|
|
222
220
|
try {
|
|
@@ -278,52 +276,70 @@ var Sender = class {
|
|
|
278
276
|
}
|
|
279
277
|
}, sendDownload);
|
|
280
278
|
}
|
|
281
|
-
async
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
for (const code of chain) {
|
|
293
|
-
const { type, data } = code;
|
|
279
|
+
async sendBuffer() {
|
|
280
|
+
const content = this.buffer.trim();
|
|
281
|
+
if (!content)
|
|
282
|
+
return;
|
|
283
|
+
await this.post({ ...this.addition, content });
|
|
284
|
+
this.buffer = "";
|
|
285
|
+
this.addition = {};
|
|
286
|
+
}
|
|
287
|
+
async sendMessage(elements) {
|
|
288
|
+
for (const code of elements) {
|
|
289
|
+
const { type, attrs, children } = code;
|
|
294
290
|
if (type === "text") {
|
|
295
|
-
|
|
296
|
-
} else if (type === "at"
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
} else if (type === "
|
|
305
|
-
|
|
306
|
-
} else if (
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
291
|
+
this.buffer += attrs.content.trim();
|
|
292
|
+
} else if (type === "at") {
|
|
293
|
+
if (attrs.id) {
|
|
294
|
+
this.buffer += `<@${attrs.id}>`;
|
|
295
|
+
} else if (attrs.type === "all") {
|
|
296
|
+
this.buffer += `@everyone`;
|
|
297
|
+
} else if (attrs.type === "here") {
|
|
298
|
+
this.buffer += `@here`;
|
|
299
|
+
}
|
|
300
|
+
} else if (type === "sharp" && attrs.id) {
|
|
301
|
+
this.buffer += `<#${attrs.id}>`;
|
|
302
|
+
} else if (type === "face" && attrs.name && attrs.id) {
|
|
303
|
+
this.buffer += `<:${attrs.name}:${attrs.id}>`;
|
|
304
|
+
} else if ((type === "image" || type === "video") && attrs.url) {
|
|
305
|
+
await this.sendAsset(type, attrs, {
|
|
306
|
+
...this.addition,
|
|
307
|
+
content: this.buffer.trim()
|
|
310
308
|
});
|
|
311
|
-
|
|
309
|
+
this.buffer = "";
|
|
312
310
|
} else if (type === "share") {
|
|
313
|
-
await sendBuffer();
|
|
311
|
+
await this.sendBuffer();
|
|
314
312
|
await this.post({
|
|
315
|
-
...addition,
|
|
316
|
-
embeds: [{ ...
|
|
313
|
+
...this.addition,
|
|
314
|
+
embeds: [{ ...attrs }]
|
|
317
315
|
});
|
|
318
316
|
} else if (type === "record") {
|
|
319
|
-
await this.sendAsset("file",
|
|
320
|
-
...addition,
|
|
321
|
-
content:
|
|
317
|
+
await this.sendAsset("file", attrs, {
|
|
318
|
+
...this.addition,
|
|
319
|
+
content: this.buffer.trim()
|
|
322
320
|
});
|
|
323
|
-
|
|
321
|
+
this.buffer = "";
|
|
322
|
+
} else if (type === "quote") {
|
|
323
|
+
await this.sendBuffer();
|
|
324
|
+
this.addition.message_reference = {
|
|
325
|
+
message_id: attrs.id
|
|
326
|
+
};
|
|
327
|
+
} else if (type === "message") {
|
|
328
|
+
await this.sendBuffer();
|
|
329
|
+
if ("quote" in attrs) {
|
|
330
|
+
this.addition.message_reference = {
|
|
331
|
+
message_id: attrs.id
|
|
332
|
+
};
|
|
333
|
+
} else {
|
|
334
|
+
await this.sendMessage(children);
|
|
335
|
+
}
|
|
324
336
|
}
|
|
325
337
|
}
|
|
326
|
-
await sendBuffer();
|
|
338
|
+
await this.sendBuffer();
|
|
339
|
+
}
|
|
340
|
+
async send(content) {
|
|
341
|
+
const elements = import_satori2.segment.parse(content);
|
|
342
|
+
await this.sendMessage(elements);
|
|
327
343
|
if (!this.errors.length)
|
|
328
344
|
return this.results;
|
|
329
345
|
throw new import_es_aggregate_error.default(this.errors);
|
|
@@ -1471,11 +1487,6 @@ var DiscordBot = class extends import_satori4.Bot {
|
|
|
1471
1487
|
const data = await this.internal.getCurrentUser();
|
|
1472
1488
|
return adaptUser(data);
|
|
1473
1489
|
}
|
|
1474
|
-
parseQuote(chain) {
|
|
1475
|
-
if (chain[0].type !== "quote")
|
|
1476
|
-
return;
|
|
1477
|
-
return chain.shift().attrs.id;
|
|
1478
|
-
}
|
|
1479
1490
|
async sendMessage(channelId, content, guildId) {
|
|
1480
1491
|
const fragment = import_satori4.segment.normalize(content);
|
|
1481
1492
|
const elements = fragment.children;
|
|
@@ -1493,13 +1504,8 @@ var DiscordBot = class extends import_satori4.Bot {
|
|
|
1493
1504
|
return;
|
|
1494
1505
|
if (!(session == null ? void 0 : session.content))
|
|
1495
1506
|
return [];
|
|
1496
|
-
const
|
|
1497
|
-
const
|
|
1498
|
-
const message_reference = quote ? {
|
|
1499
|
-
message_id: quote
|
|
1500
|
-
} : void 0;
|
|
1501
|
-
const send = Sender.from(this, `/channels/${channelId}/messages`);
|
|
1502
|
-
const results = await send(session.content, { message_reference });
|
|
1507
|
+
const sender = new Sender(this, `/channels/${channelId}/messages`);
|
|
1508
|
+
const results = await sender.send(session.content);
|
|
1503
1509
|
for (const id of results) {
|
|
1504
1510
|
session.messageId = id;
|
|
1505
1511
|
this.context.emit(session, "send", session);
|