@satorijs/adapter-discord 3.2.0 → 3.2.2
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 -54
- package/lib/index.js.map +3 -3
- package/lib/sender.d.ts +7 -4
- package/lib/types/internal.d.ts +1 -3
- 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,69 @@ var Sender = class {
|
|
|
278
276
|
}
|
|
279
277
|
}, sendDownload);
|
|
280
278
|
}
|
|
281
|
-
async
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
}, "sendBuffer");
|
|
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 { type, attrs, children } of elements) {
|
|
294
289
|
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
|
-
|
|
290
|
+
this.buffer += attrs.content;
|
|
291
|
+
} else if (type === "at") {
|
|
292
|
+
if (attrs.id) {
|
|
293
|
+
this.buffer += `<@${attrs.id}>`;
|
|
294
|
+
} else if (attrs.type === "all") {
|
|
295
|
+
this.buffer += `@everyone`;
|
|
296
|
+
} else if (attrs.type === "here") {
|
|
297
|
+
this.buffer += `@here`;
|
|
298
|
+
}
|
|
299
|
+
} else if (type === "sharp" && attrs.id) {
|
|
300
|
+
this.buffer += `<#${attrs.id}>`;
|
|
301
|
+
} else if (type === "face" && attrs.name && attrs.id) {
|
|
302
|
+
this.buffer += `<:${attrs.name}:${attrs.id}>`;
|
|
303
|
+
} else if ((type === "image" || type === "video") && attrs.url) {
|
|
304
|
+
await this.sendAsset(type, attrs, {
|
|
305
|
+
...this.addition,
|
|
306
|
+
content: this.buffer.trim()
|
|
310
307
|
});
|
|
311
|
-
|
|
308
|
+
this.buffer = "";
|
|
312
309
|
} else if (type === "share") {
|
|
313
|
-
await sendBuffer();
|
|
310
|
+
await this.sendBuffer();
|
|
314
311
|
await this.post({
|
|
315
|
-
...addition,
|
|
316
|
-
embeds: [{ ...
|
|
312
|
+
...this.addition,
|
|
313
|
+
embeds: [{ ...attrs }]
|
|
317
314
|
});
|
|
318
315
|
} else if (type === "record") {
|
|
319
|
-
await this.sendAsset("file",
|
|
320
|
-
...addition,
|
|
321
|
-
content:
|
|
316
|
+
await this.sendAsset("file", attrs, {
|
|
317
|
+
...this.addition,
|
|
318
|
+
content: this.buffer.trim()
|
|
322
319
|
});
|
|
323
|
-
|
|
320
|
+
this.buffer = "";
|
|
321
|
+
} else if (type === "quote") {
|
|
322
|
+
await this.sendBuffer();
|
|
323
|
+
this.addition.message_reference = {
|
|
324
|
+
message_id: attrs.id
|
|
325
|
+
};
|
|
326
|
+
} else if (type === "message") {
|
|
327
|
+
await this.sendBuffer();
|
|
328
|
+
if ("quote" in attrs) {
|
|
329
|
+
this.addition.message_reference = {
|
|
330
|
+
message_id: attrs.id
|
|
331
|
+
};
|
|
332
|
+
} else {
|
|
333
|
+
await this.sendMessage(children);
|
|
334
|
+
}
|
|
324
335
|
}
|
|
325
336
|
}
|
|
326
|
-
await sendBuffer();
|
|
337
|
+
await this.sendBuffer();
|
|
338
|
+
}
|
|
339
|
+
async send(content) {
|
|
340
|
+
const elements = import_satori2.segment.parse(content);
|
|
341
|
+
await this.sendMessage(elements);
|
|
327
342
|
if (!this.errors.length)
|
|
328
343
|
return this.results;
|
|
329
344
|
throw new import_es_aggregate_error.default(this.errors);
|
|
@@ -1471,11 +1486,6 @@ var DiscordBot = class extends import_satori4.Bot {
|
|
|
1471
1486
|
const data = await this.internal.getCurrentUser();
|
|
1472
1487
|
return adaptUser(data);
|
|
1473
1488
|
}
|
|
1474
|
-
parseQuote(chain) {
|
|
1475
|
-
if (chain[0].type !== "quote")
|
|
1476
|
-
return;
|
|
1477
|
-
return chain.shift().attrs.id;
|
|
1478
|
-
}
|
|
1479
1489
|
async sendMessage(channelId, content, guildId) {
|
|
1480
1490
|
const fragment = import_satori4.segment.normalize(content);
|
|
1481
1491
|
const elements = fragment.children;
|
|
@@ -1491,15 +1501,10 @@ var DiscordBot = class extends import_satori4.Bot {
|
|
|
1491
1501
|
});
|
|
1492
1502
|
if (await this.context.serial(session, "before-send", session))
|
|
1493
1503
|
return;
|
|
1494
|
-
if (!
|
|
1504
|
+
if (!session.content)
|
|
1495
1505
|
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 });
|
|
1506
|
+
const sender = new Sender(this, `/channels/${channelId}/messages`);
|
|
1507
|
+
const results = await sender.send(session.content);
|
|
1503
1508
|
for (const id of results) {
|
|
1504
1509
|
session.messageId = id;
|
|
1505
1510
|
this.context.emit(session, "send", session);
|