@satorijs/adapter-discord 3.2.7 → 3.3.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/index.js CHANGED
@@ -23,12 +23,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
23
23
  ));
24
24
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
25
 
26
- // satori/adapters/discord/src/index.ts
26
+ // adapters/discord/src/index.ts
27
27
  var src_exports = {};
28
28
  __export(src_exports, {
29
29
  Discord: () => types_exports,
30
30
  DiscordBot: () => DiscordBot,
31
- Sender: () => Sender,
31
+ DiscordMessenger: () => DiscordMessenger,
32
32
  WsClient: () => WsClient,
33
33
  adaptAuthor: () => adaptAuthor,
34
34
  adaptChannel: () => adaptChannel,
@@ -41,10 +41,10 @@ __export(src_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(src_exports);
43
43
 
44
- // satori/adapters/discord/src/bot.ts
44
+ // adapters/discord/src/bot.ts
45
45
  var import_satori4 = require("@satorijs/satori");
46
46
 
47
- // satori/adapters/discord/src/utils.ts
47
+ // adapters/discord/src/utils.ts
48
48
  var import_satori = require("@satorijs/satori");
49
49
  var adaptUser = /* @__PURE__ */ __name((user) => ({
50
50
  userId: user.id,
@@ -94,7 +94,9 @@ async function adaptMessage(bot, meta, session = {}) {
94
94
  });
95
95
  }
96
96
  if ((_c = meta.attachments) == null ? void 0 : _c.length) {
97
- session.content += " " + meta.attachments.map((v) => {
97
+ if (session.content)
98
+ session.content += " ";
99
+ session.content += meta.attachments.map((v) => {
98
100
  var _a2, _b2, _c2;
99
101
  if (v.height && v.width && ((_a2 = v.content_type) == null ? void 0 : _a2.startsWith("image/"))) {
100
102
  return (0, import_satori.segment)("image", {
@@ -200,23 +202,13 @@ async function adaptSession(bot, input) {
200
202
  }
201
203
  __name(adaptSession, "adaptSession");
202
204
 
203
- // satori/adapters/discord/src/sender.ts
205
+ // adapters/discord/src/message.ts
204
206
  var import_satori2 = require("@satorijs/satori");
205
207
  var import_file_type = require("file-type");
206
208
  var import_form_data = __toESM(require("form-data"));
207
- var AggregateError = class extends Error {
208
- constructor(errors, message = "") {
209
- super(message);
210
- this.errors = errors;
211
- }
212
- };
213
- __name(AggregateError, "AggregateError");
214
- var Sender = class {
215
- constructor(bot, url) {
216
- this.bot = bot;
217
- this.url = url;
218
- this.results = [];
219
- this.errors = [];
209
+ var DiscordMessenger = class extends import_satori2.Messenger {
210
+ constructor() {
211
+ super(...arguments);
220
212
  this.buffer = "";
221
213
  this.addition = {};
222
214
  this.figure = null;
@@ -224,8 +216,11 @@ var Sender = class {
224
216
  }
225
217
  async post(data, headers) {
226
218
  try {
227
- const result = await this.bot.http.post(this.url, data, { headers });
228
- this.results.push(result.id);
219
+ const result = await this.bot.http.post(`/channels/${this.channelId}/messages`, data, { headers });
220
+ const session = this.bot.session();
221
+ await adaptMessage(this.bot, result, session);
222
+ session.app.emit(session, "send", session);
223
+ this.results.push(session);
229
224
  } catch (e) {
230
225
  this.errors.push(e);
231
226
  }
@@ -279,7 +274,7 @@ var Sender = class {
279
274
  }
280
275
  }, sendDownload);
281
276
  }
282
- async sendBuffer() {
277
+ async flush() {
283
278
  const content = this.buffer.trim();
284
279
  if (!content)
285
280
  return;
@@ -287,97 +282,105 @@ var Sender = class {
287
282
  this.buffer = "";
288
283
  this.addition = {};
289
284
  }
290
- async render(elements) {
291
- for (const element of elements) {
292
- const { type, attrs, children } = element;
293
- if (type === "text") {
294
- this.buffer += attrs.content;
295
- } else if (type === "p") {
296
- await this.render(children);
297
- this.buffer += "\n";
298
- } else if (type === "at") {
299
- if (attrs.id) {
300
- this.buffer += `<@${attrs.id}>`;
301
- } else if (attrs.type === "all") {
302
- this.buffer += `@everyone`;
303
- } else if (attrs.type === "here") {
304
- this.buffer += `@here`;
305
- }
306
- } else if (type === "sharp" && attrs.id) {
307
- this.buffer += `<#${attrs.id}>`;
308
- } else if (type === "face" && attrs.name && attrs.id) {
309
- this.buffer += `<:${attrs.name}:${attrs.id}>`;
310
- } else if ((type === "image" || type === "video") && attrs.url) {
311
- if (this.mode === "figure") {
312
- this.figure = element;
313
- } else {
314
- await this.sendAsset(type, attrs, {
315
- ...this.addition,
316
- content: this.buffer.trim()
317
- });
318
- this.buffer = "";
319
- }
320
- } else if (type === "share") {
321
- await this.sendBuffer();
322
- await this.post({
323
- ...this.addition,
324
- embeds: [{ ...attrs }]
325
- });
326
- } else if (type === "record") {
327
- await this.sendAsset("file", attrs, {
285
+ async visit(element) {
286
+ const { type, attrs, children } = element;
287
+ if (type === "text") {
288
+ this.buffer += attrs.content.replace(/[\\*_`~|()]/g, "\\$&");
289
+ } else if (type === "b" || type === "strong") {
290
+ this.buffer += "**";
291
+ await this.render(children);
292
+ this.buffer += "**";
293
+ } else if (type === "i" || type === "em") {
294
+ this.buffer += "*";
295
+ await this.render(children);
296
+ this.buffer += "*";
297
+ } else if (type === "u" || type === "ins") {
298
+ this.buffer += "__";
299
+ await this.render(children);
300
+ this.buffer += "__";
301
+ } else if (type === "s" || type === "del") {
302
+ this.buffer += "~~";
303
+ await this.render(children);
304
+ this.buffer += "~~";
305
+ } else if (type === "spl") {
306
+ this.buffer += "||";
307
+ await this.render(children);
308
+ this.buffer += "||";
309
+ } else if (type === "code") {
310
+ this.buffer += "`";
311
+ await this.render(children);
312
+ this.buffer += "`";
313
+ } else if (type === "a") {
314
+ await this.render(children);
315
+ this.buffer += ` (${attrs.href}) `;
316
+ } else if (type === "p") {
317
+ await this.render(children);
318
+ this.buffer += "\n";
319
+ } else if (type === "at") {
320
+ if (attrs.id) {
321
+ this.buffer += `<@${attrs.id}>`;
322
+ } else if (attrs.type === "all") {
323
+ this.buffer += `@everyone`;
324
+ } else if (attrs.type === "here") {
325
+ this.buffer += `@here`;
326
+ }
327
+ } else if (type === "sharp" && attrs.id) {
328
+ this.buffer += `<#${attrs.id}>`;
329
+ } else if (type === "face" && attrs.name && attrs.id) {
330
+ this.buffer += `<:${attrs.name}:${attrs.id}>`;
331
+ } else if ((type === "image" || type === "video") && attrs.url) {
332
+ if (this.mode === "figure") {
333
+ this.figure = element;
334
+ } else {
335
+ await this.sendAsset(type, attrs, {
328
336
  ...this.addition,
329
337
  content: this.buffer.trim()
330
338
  });
331
339
  this.buffer = "";
332
- } else if (type === "figure") {
333
- await this.sendBuffer();
334
- this.mode = "figure";
340
+ }
341
+ } else if (type === "share") {
342
+ await this.flush();
343
+ await this.post({
344
+ ...this.addition,
345
+ embeds: [{ ...attrs }]
346
+ });
347
+ } else if (type === "record") {
348
+ await this.sendAsset("file", attrs, {
349
+ ...this.addition,
350
+ content: this.buffer.trim()
351
+ });
352
+ this.buffer = "";
353
+ } else if (type === "figure") {
354
+ await this.flush();
355
+ this.mode = "figure";
356
+ await this.render(children);
357
+ await this.sendAsset(this.figure.type, this.figure.attrs, {
358
+ ...this.addition,
359
+ content: this.buffer.trim()
360
+ });
361
+ this.buffer = "";
362
+ this.mode = "default";
363
+ } else if (type === "quote") {
364
+ await this.flush();
365
+ this.addition.message_reference = {
366
+ message_id: attrs.id
367
+ };
368
+ } else if (type === "message") {
369
+ if (this.mode === "figure") {
335
370
  await this.render(children);
336
- await this.sendAsset(this.figure.type, this.figure.attrs, {
337
- ...this.addition,
338
- content: this.buffer.trim()
339
- });
340
- this.buffer = "";
341
- this.mode = "default";
342
- } else if (type === "quote") {
343
- await this.sendBuffer();
344
- this.addition.message_reference = {
345
- message_id: attrs.id
346
- };
347
- } else if (type === "message") {
348
- if (this.mode === "figure") {
349
- await this.render(children);
350
- this.buffer += "\n";
351
- } else {
352
- await this.sendBuffer();
353
- if ("quote" in attrs) {
354
- this.addition.message_reference = {
355
- message_id: attrs.id
356
- };
357
- } else {
358
- await this.sendMessage(children);
359
- }
360
- }
371
+ this.buffer += "\n";
361
372
  } else {
362
- await this.render(children);
373
+ await this.flush();
374
+ await this.render(children, true);
363
375
  }
376
+ } else {
377
+ await this.render(children);
364
378
  }
365
379
  }
366
- async sendMessage(elements) {
367
- await this.render(elements);
368
- await this.sendBuffer();
369
- }
370
- async send(content) {
371
- const elements = import_satori2.segment.parse(content);
372
- await this.sendMessage(elements);
373
- if (!this.errors.length)
374
- return this.results;
375
- throw new AggregateError(this.errors);
376
- }
377
380
  };
378
- __name(Sender, "Sender");
379
- ((Sender2) => {
380
- Sender2.Config = import_satori2.Schema.object({
381
+ __name(DiscordMessenger, "DiscordMessenger");
382
+ ((DiscordMessenger2) => {
383
+ DiscordMessenger2.Config = import_satori2.Schema.object({
381
384
  handleExternalAsset: import_satori2.Schema.union([
382
385
  import_satori2.Schema.const("download").description("先下载后发送"),
383
386
  import_satori2.Schema.const("direct").description("直接发送链接"),
@@ -389,9 +392,9 @@ __name(Sender, "Sender");
389
392
  import_satori2.Schema.const("auto").description("如果图片本身采用直接发送则与前面的文本分开,否则将文本作为图片的附带信息发送")
390
393
  ]).role("radio").description("发送图文等混合内容时采用的方式。").default("auto")
391
394
  }).description("发送设置");
392
- })(Sender || (Sender = {}));
395
+ })(DiscordMessenger || (DiscordMessenger = {}));
393
396
 
394
- // satori/adapters/discord/src/types/index.ts
397
+ // adapters/discord/src/types/index.ts
395
398
  var types_exports = {};
396
399
  __export(types_exports, {
397
400
  ActivityFlag: () => ActivityFlag,
@@ -402,12 +405,12 @@ __export(types_exports, {
402
405
  AuditLog: () => AuditLog,
403
406
  AutoModerationAction: () => AutoModerationAction,
404
407
  AutoModerationRule: () => AutoModerationRule,
405
- Channel: () => Channel3,
408
+ Channel: () => Channel2,
406
409
  ComponentType: () => ComponentType,
407
410
  DeviceType: () => DeviceType,
408
411
  GatewayIntent: () => GatewayIntent,
409
412
  GatewayOpcode: () => GatewayOpcode,
410
- Guild: () => Guild4,
413
+ Guild: () => Guild3,
411
414
  GuildFeature: () => GuildFeature,
412
415
  GuildScheduledEvent: () => GuildScheduledEvent,
413
416
  IntegrationExpireBehavior: () => IntegrationExpireBehavior,
@@ -417,7 +420,7 @@ __export(types_exports, {
417
420
  Internal: () => Internal,
418
421
  Invite: () => Invite,
419
422
  MembershipState: () => MembershipState,
420
- Message: () => Message3,
423
+ Message: () => Message2,
421
424
  Permission: () => Permission,
422
425
  StatusType: () => StatusType2,
423
426
  Sticker: () => Sticker3,
@@ -428,7 +431,7 @@ __export(types_exports, {
428
431
  Webhook: () => Webhook2
429
432
  });
430
433
 
431
- // satori/adapters/discord/src/types/internal.ts
434
+ // adapters/discord/src/types/internal.ts
432
435
  var import_cosmokit = require("cosmokit");
433
436
  var Internal = class {
434
437
  constructor(http) {
@@ -468,7 +471,7 @@ var Internal = class {
468
471
  };
469
472
  __name(Internal, "Internal");
470
473
 
471
- // satori/adapters/discord/src/types/application.ts
474
+ // adapters/discord/src/types/application.ts
472
475
  var ApplicationFlag = /* @__PURE__ */ ((ApplicationFlag2) => {
473
476
  ApplicationFlag2[ApplicationFlag2["GATEWAY_PRESENCE"] = 4096] = "GATEWAY_PRESENCE";
474
477
  ApplicationFlag2[ApplicationFlag2["GATEWAY_PRESENCE_LIMITED"] = 8192] = "GATEWAY_PRESENCE_LIMITED";
@@ -487,7 +490,7 @@ Internal.define({
487
490
  }
488
491
  });
489
492
 
490
- // satori/adapters/discord/src/types/audit-log.ts
493
+ // adapters/discord/src/types/audit-log.ts
491
494
  var AuditLog;
492
495
  ((AuditLog2) => {
493
496
  let Type;
@@ -554,7 +557,7 @@ Internal.define({
554
557
  }
555
558
  });
556
559
 
557
- // satori/adapters/discord/src/types/auto-moderation.ts
560
+ // adapters/discord/src/types/auto-moderation.ts
558
561
  var AutoModerationRule;
559
562
  ((AutoModerationRule2) => {
560
563
  let EventType;
@@ -596,7 +599,7 @@ Internal.define({
596
599
  }
597
600
  });
598
601
 
599
- // satori/adapters/discord/src/types/ban.ts
602
+ // adapters/discord/src/types/ban.ts
600
603
  Internal.define({
601
604
  "/guilds/{guild.id}/bans": {
602
605
  GET: "getGuildBans"
@@ -608,9 +611,9 @@ Internal.define({
608
611
  }
609
612
  });
610
613
 
611
- // satori/adapters/discord/src/types/channel.ts
612
- var Channel3;
613
- ((Channel11) => {
614
+ // adapters/discord/src/types/channel.ts
615
+ var Channel2;
616
+ ((Channel10) => {
614
617
  let Type;
615
618
  ((Type2) => {
616
619
  Type2[Type2["GUILD_TEXT"] = 0] = "GUILD_TEXT";
@@ -626,8 +629,8 @@ var Channel3;
626
629
  Type2[Type2["GUILD_STAGE_VOICE"] = 13] = "GUILD_STAGE_VOICE";
627
630
  Type2[Type2["GUILD_DIRECTORY"] = 14] = "GUILD_DIRECTORY";
628
631
  Type2[Type2["GUILD_FORUM"] = 15] = "GUILD_FORUM";
629
- })(Type = Channel11.Type || (Channel11.Type = {}));
630
- })(Channel3 || (Channel3 = {}));
632
+ })(Type = Channel10.Type || (Channel10.Type = {}));
633
+ })(Channel2 || (Channel2 = {}));
631
634
  var AllowedMentionType = /* @__PURE__ */ ((AllowedMentionType2) => {
632
635
  AllowedMentionType2["ROLE_MENTIONS"] = "roles";
633
636
  AllowedMentionType2["USER_MENTIONS"] = "users";
@@ -668,7 +671,7 @@ Internal.define({
668
671
  }
669
672
  });
670
673
 
671
- // satori/adapters/discord/src/types/command.ts
674
+ // adapters/discord/src/types/command.ts
672
675
  var ApplicationCommand;
673
676
  ((ApplicationCommand3) => {
674
677
  let Type;
@@ -727,7 +730,7 @@ Internal.define({
727
730
  }
728
731
  });
729
732
 
730
- // satori/adapters/discord/src/types/component.ts
733
+ // adapters/discord/src/types/component.ts
731
734
  var ComponentType = /* @__PURE__ */ ((ComponentType2) => {
732
735
  ComponentType2[ComponentType2["ACTION_ROW"] = 1] = "ACTION_ROW";
733
736
  ComponentType2[ComponentType2["BUTTON"] = 2] = "BUTTON";
@@ -741,7 +744,7 @@ var TextInputStyles = /* @__PURE__ */ ((TextInputStyles2) => {
741
744
  return TextInputStyles2;
742
745
  })(TextInputStyles || {});
743
746
 
744
- // satori/adapters/discord/src/types/device.ts
747
+ // adapters/discord/src/types/device.ts
745
748
  var DeviceType = /* @__PURE__ */ ((DeviceType2) => {
746
749
  DeviceType2["AUDIO_INPUT"] = "audioinput";
747
750
  DeviceType2["AUDIO_OUTPUT"] = "audiooutput";
@@ -749,7 +752,7 @@ var DeviceType = /* @__PURE__ */ ((DeviceType2) => {
749
752
  return DeviceType2;
750
753
  })(DeviceType || {});
751
754
 
752
- // satori/adapters/discord/src/types/emoji.ts
755
+ // adapters/discord/src/types/emoji.ts
753
756
  Internal.define({
754
757
  "/guilds/{guild.id}/emojis": {
755
758
  GET: "listGuildEmojis",
@@ -762,7 +765,7 @@ Internal.define({
762
765
  }
763
766
  });
764
767
 
765
- // satori/adapters/discord/src/types/gateway.ts
768
+ // adapters/discord/src/types/gateway.ts
766
769
  var GatewayOpcode = /* @__PURE__ */ ((GatewayOpcode2) => {
767
770
  GatewayOpcode2[GatewayOpcode2["DISPATCH"] = 0] = "DISPATCH";
768
771
  GatewayOpcode2[GatewayOpcode2["HEARTBEAT"] = 1] = "HEARTBEAT";
@@ -808,7 +811,7 @@ Internal.define({
808
811
  }
809
812
  });
810
813
 
811
- // satori/adapters/discord/src/types/guild-member.ts
814
+ // adapters/discord/src/types/guild-member.ts
812
815
  Internal.define({
813
816
  "/guilds/{guild.id}/members/{user.id}": {
814
817
  GET: "getGuildMember",
@@ -835,7 +838,7 @@ Internal.define({
835
838
  }
836
839
  });
837
840
 
838
- // satori/adapters/discord/src/types/guild-template.ts
841
+ // adapters/discord/src/types/guild-template.ts
839
842
  Internal.define({
840
843
  "/guilds/templates/{template.code}": {
841
844
  GET: "getGuildTemplate",
@@ -852,9 +855,9 @@ Internal.define({
852
855
  }
853
856
  });
854
857
 
855
- // satori/adapters/discord/src/types/guild.ts
856
- var Guild4;
857
- ((Guild7) => {
858
+ // adapters/discord/src/types/guild.ts
859
+ var Guild3;
860
+ ((Guild6) => {
858
861
  let Params;
859
862
  ((Params2) => {
860
863
  let WidgetStyleOptions;
@@ -865,8 +868,8 @@ var Guild4;
865
868
  WidgetStyleOptions2["banner3"] = "banner3";
866
869
  WidgetStyleOptions2["banner4"] = "banner4";
867
870
  })(WidgetStyleOptions = Params2.WidgetStyleOptions || (Params2.WidgetStyleOptions = {}));
868
- })(Params = Guild7.Params || (Guild7.Params = {}));
869
- })(Guild4 || (Guild4 = {}));
871
+ })(Params = Guild6.Params || (Guild6.Params = {}));
872
+ })(Guild3 || (Guild3 = {}));
870
873
  var SystemChannelFlag = /* @__PURE__ */ ((SystemChannelFlag2) => {
871
874
  SystemChannelFlag2[SystemChannelFlag2["SUPPRESS_JOIN_NOTIFICATIONS"] = 1] = "SUPPRESS_JOIN_NOTIFICATIONS";
872
875
  SystemChannelFlag2[SystemChannelFlag2["SUPPRESS_PREMIUM_SUBSCRIPTIONS"] = 2] = "SUPPRESS_PREMIUM_SUBSCRIPTIONS";
@@ -937,7 +940,7 @@ Internal.define({
937
940
  }
938
941
  });
939
942
 
940
- // satori/adapters/discord/src/types/integration.ts
943
+ // adapters/discord/src/types/integration.ts
941
944
  var IntegrationExpireBehavior = /* @__PURE__ */ ((IntegrationExpireBehavior2) => {
942
945
  IntegrationExpireBehavior2[IntegrationExpireBehavior2["REMOVE_ROLE"] = 0] = "REMOVE_ROLE";
943
946
  IntegrationExpireBehavior2[IntegrationExpireBehavior2["KICK"] = 1] = "KICK";
@@ -952,7 +955,7 @@ Internal.define({
952
955
  }
953
956
  });
954
957
 
955
- // satori/adapters/discord/src/types/interaction.ts
958
+ // adapters/discord/src/types/interaction.ts
956
959
  var InteractionType = /* @__PURE__ */ ((InteractionType2) => {
957
960
  InteractionType2[InteractionType2["PING"] = 1] = "PING";
958
961
  InteractionType2[InteractionType2["APPLICATION_COMMAND"] = 2] = "APPLICATION_COMMAND";
@@ -992,7 +995,7 @@ Internal.define({
992
995
  }
993
996
  });
994
997
 
995
- // satori/adapters/discord/src/types/invite.ts
998
+ // adapters/discord/src/types/invite.ts
996
999
  var Invite;
997
1000
  ((Invite2) => {
998
1001
  let TargetType;
@@ -1018,9 +1021,9 @@ Internal.define({
1018
1021
  }
1019
1022
  });
1020
1023
 
1021
- // satori/adapters/discord/src/types/message.ts
1022
- var Message3;
1023
- ((Message6) => {
1024
+ // adapters/discord/src/types/message.ts
1025
+ var Message2;
1026
+ ((Message4) => {
1024
1027
  let Type;
1025
1028
  ((Type2) => {
1026
1029
  Type2[Type2["DEFAULT"] = 0] = "DEFAULT";
@@ -1046,14 +1049,14 @@ var Message3;
1046
1049
  Type2[Type2["THREAD_STARTER_MESSAGE"] = 21] = "THREAD_STARTER_MESSAGE";
1047
1050
  Type2[Type2["GUILD_INVITE_REMINDER"] = 22] = "GUILD_INVITE_REMINDER";
1048
1051
  Type2[Type2["CONTEXT_MENU_COMMAND"] = 23] = "CONTEXT_MENU_COMMAND";
1049
- })(Type = Message6.Type || (Message6.Type = {}));
1052
+ })(Type = Message4.Type || (Message4.Type = {}));
1050
1053
  let ActivityType2;
1051
1054
  ((ActivityType3) => {
1052
1055
  ActivityType3[ActivityType3["JOIN"] = 1] = "JOIN";
1053
1056
  ActivityType3[ActivityType3["SPECTATE"] = 2] = "SPECTATE";
1054
1057
  ActivityType3[ActivityType3["LISTEN"] = 3] = "LISTEN";
1055
1058
  ActivityType3[ActivityType3["JOIN_REQUEST"] = 5] = "JOIN_REQUEST";
1056
- })(ActivityType2 = Message6.ActivityType || (Message6.ActivityType = {}));
1059
+ })(ActivityType2 = Message4.ActivityType || (Message4.ActivityType = {}));
1057
1060
  let Flag;
1058
1061
  ((Flag2) => {
1059
1062
  Flag2[Flag2["CROSSPOSTED"] = 1] = "CROSSPOSTED";
@@ -1064,8 +1067,8 @@ var Message3;
1064
1067
  Flag2[Flag2["HAS_THREAD"] = 32] = "HAS_THREAD";
1065
1068
  Flag2[Flag2["EPHEMERAL"] = 64] = "EPHEMERAL";
1066
1069
  Flag2[Flag2["LOADING"] = 128] = "LOADING";
1067
- })(Flag = Message6.Flag || (Message6.Flag = {}));
1068
- })(Message3 || (Message3 = {}));
1070
+ })(Flag = Message4.Flag || (Message4.Flag = {}));
1071
+ })(Message2 || (Message2 = {}));
1069
1072
  Internal.define({
1070
1073
  "/channels/{channel.id}/messages": {
1071
1074
  GET: "getChannelMessages",
@@ -1091,7 +1094,7 @@ Internal.define({
1091
1094
  }
1092
1095
  });
1093
1096
 
1094
- // satori/adapters/discord/src/types/presence.ts
1097
+ // adapters/discord/src/types/presence.ts
1095
1098
  var StatusType2 = /* @__PURE__ */ ((StatusType3) => {
1096
1099
  StatusType3["ONLINE"] = "ONLINE";
1097
1100
  StatusType3["DND"] = "DND";
@@ -1119,7 +1122,7 @@ var ActivityFlag = /* @__PURE__ */ ((ActivityFlag2) => {
1119
1122
  return ActivityFlag2;
1120
1123
  })(ActivityFlag || {});
1121
1124
 
1122
- // satori/adapters/discord/src/types/reaction.ts
1125
+ // adapters/discord/src/types/reaction.ts
1123
1126
  Internal.define({
1124
1127
  "/channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me": {
1125
1128
  PUT: "createReaction",
@@ -1137,7 +1140,7 @@ Internal.define({
1137
1140
  }
1138
1141
  });
1139
1142
 
1140
- // satori/adapters/discord/src/types/role.ts
1143
+ // adapters/discord/src/types/role.ts
1141
1144
  var Permission = /* @__PURE__ */ ((Permission2) => {
1142
1145
  Permission2[Permission2["CREATE_INSTANT_INVITE"] = 1] = "CREATE_INSTANT_INVITE";
1143
1146
  Permission2[Permission2["KICK_MEMBERS"] = 2] = "KICK_MEMBERS";
@@ -1192,7 +1195,7 @@ Internal.define({
1192
1195
  }
1193
1196
  });
1194
1197
 
1195
- // satori/adapters/discord/src/types/scheduled-event.ts
1198
+ // adapters/discord/src/types/scheduled-event.ts
1196
1199
  var GuildScheduledEvent;
1197
1200
  ((GuildScheduledEvent2) => {
1198
1201
  let PrivacyLevel;
@@ -1228,7 +1231,7 @@ Internal.define({
1228
1231
  }
1229
1232
  });
1230
1233
 
1231
- // satori/adapters/discord/src/types/stage-instance.ts
1234
+ // adapters/discord/src/types/stage-instance.ts
1232
1235
  Internal.define({
1233
1236
  "/stage-instances": {
1234
1237
  POST: "createStageInstance"
@@ -1240,7 +1243,7 @@ Internal.define({
1240
1243
  }
1241
1244
  });
1242
1245
 
1243
- // satori/adapters/discord/src/types/sticker.ts
1246
+ // adapters/discord/src/types/sticker.ts
1244
1247
  var Sticker3;
1245
1248
  ((Sticker4) => {
1246
1249
  let Type;
@@ -1273,14 +1276,14 @@ Internal.define({
1273
1276
  }
1274
1277
  });
1275
1278
 
1276
- // satori/adapters/discord/src/types/team.ts
1279
+ // adapters/discord/src/types/team.ts
1277
1280
  var MembershipState = /* @__PURE__ */ ((MembershipState2) => {
1278
1281
  MembershipState2[MembershipState2["INVITED"] = 1] = "INVITED";
1279
1282
  MembershipState2[MembershipState2["ACCEPTED"] = 2] = "ACCEPTED";
1280
1283
  return MembershipState2;
1281
1284
  })(MembershipState || {});
1282
1285
 
1283
- // satori/adapters/discord/src/types/thread.ts
1286
+ // adapters/discord/src/types/thread.ts
1284
1287
  Internal.define({
1285
1288
  "/guilds/{guild.id}/threads/active": {
1286
1289
  GET: "listActiveGuildThreads"
@@ -1317,7 +1320,7 @@ Internal.define({
1317
1320
  }
1318
1321
  });
1319
1322
 
1320
- // satori/adapters/discord/src/types/user.ts
1323
+ // adapters/discord/src/types/user.ts
1321
1324
  var UserFlag = /* @__PURE__ */ ((UserFlag2) => {
1322
1325
  UserFlag2[UserFlag2["NONE"] = 0] = "NONE";
1323
1326
  UserFlag2[UserFlag2["DISCORD_EMPLOYEE"] = 1] = "DISCORD_EMPLOYEE";
@@ -1353,7 +1356,7 @@ Internal.define({
1353
1356
  }
1354
1357
  });
1355
1358
 
1356
- // satori/adapters/discord/src/types/voice.ts
1359
+ // adapters/discord/src/types/voice.ts
1357
1360
  Internal.define({
1358
1361
  "/voice/regions": {
1359
1362
  GET: "listVoiceRegions"
@@ -1369,7 +1372,7 @@ Internal.define({
1369
1372
  }
1370
1373
  });
1371
1374
 
1372
- // satori/adapters/discord/src/types/webhook.ts
1375
+ // adapters/discord/src/types/webhook.ts
1373
1376
  var Webhook2;
1374
1377
  ((Webhook3) => {
1375
1378
  let Type;
@@ -1411,7 +1414,7 @@ Internal.define({
1411
1414
  }
1412
1415
  });
1413
1416
 
1414
- // satori/adapters/discord/src/ws.ts
1417
+ // adapters/discord/src/ws.ts
1415
1418
  var import_satori3 = require("@satorijs/satori");
1416
1419
  var logger = new import_satori3.Logger("discord");
1417
1420
  var WsClient = class extends import_satori3.Adapter.WsClient {
@@ -1499,7 +1502,7 @@ __name(WsClient, "WsClient");
1499
1502
  ]);
1500
1503
  })(WsClient || (WsClient = {}));
1501
1504
 
1502
- // satori/adapters/discord/src/bot.ts
1505
+ // adapters/discord/src/bot.ts
1503
1506
  var DiscordBot = class extends import_satori4.Bot {
1504
1507
  constructor(ctx, config) {
1505
1508
  super(ctx, config);
@@ -1518,41 +1521,18 @@ var DiscordBot = class extends import_satori4.Bot {
1518
1521
  return adaptUser(data);
1519
1522
  }
1520
1523
  async sendMessage(channelId, content, guildId) {
1521
- const fragment = import_satori4.segment.normalize(content);
1522
- const elements = fragment.children;
1523
- content = fragment.toString();
1524
- const session = this.session({
1525
- type: "send",
1526
- author: this,
1527
- channelId,
1528
- elements,
1529
- content,
1530
- guildId,
1531
- subtype: guildId ? "group" : "private"
1532
- });
1533
- if (await this.context.serial(session, "before-send", session))
1534
- return;
1535
- if (!session.content)
1536
- return [];
1537
- const sender = new Sender(this, `/channels/${channelId}/messages`);
1538
- const results = await sender.send(session.content);
1539
- for (const id of results) {
1540
- session.messageId = id;
1541
- this.context.emit(session, "send", session);
1542
- }
1543
- return results;
1524
+ return new DiscordMessenger(this, channelId, guildId).send(content);
1544
1525
  }
1545
1526
  async sendPrivateMessage(channelId, content) {
1546
- return this.sendMessage(channelId, content);
1527
+ return new DiscordMessenger(this, channelId).send(content);
1547
1528
  }
1548
1529
  async deleteMessage(channelId, messageId) {
1549
1530
  await this.internal.deleteMessage(channelId, messageId);
1550
1531
  }
1551
1532
  async editMessage(channelId, messageId, content) {
1552
- const fragment = import_satori4.segment.normalize(content);
1553
- content = fragment.toString();
1554
- const chain = fragment.children;
1555
- const image = chain.find((v) => v.type === "image");
1533
+ const elements = import_satori4.segment.normalize(content);
1534
+ content = elements.toString();
1535
+ const image = elements.find((v) => v.type === "image");
1556
1536
  if (image) {
1557
1537
  throw new Error("You can't include embed object(s) while editing message.");
1558
1538
  }
@@ -1610,19 +1590,19 @@ __name(DiscordBot, "DiscordBot");
1610
1590
  token: import_satori4.Schema.string().description("机器人的用户令牌。").role("secret").required()
1611
1591
  }),
1612
1592
  WsClient.Config,
1613
- Sender.Config,
1593
+ DiscordMessenger.Config,
1614
1594
  import_satori4.Quester.createConfig("https://discord.com/api/v10")
1615
1595
  ]);
1616
1596
  })(DiscordBot || (DiscordBot = {}));
1617
1597
  DiscordBot.prototype.platform = "discord";
1618
1598
 
1619
- // satori/adapters/discord/src/index.ts
1599
+ // adapters/discord/src/index.ts
1620
1600
  var src_default = DiscordBot;
1621
1601
  // Annotate the CommonJS export names for ESM import in node:
1622
1602
  0 && (module.exports = {
1623
1603
  Discord,
1624
1604
  DiscordBot,
1625
- Sender,
1605
+ DiscordMessenger,
1626
1606
  WsClient,
1627
1607
  adaptAuthor,
1628
1608
  adaptChannel,