@satorijs/adapter-discord 3.2.5 → 3.2.6

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,7 +23,7 @@ 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
- // adapters/discord/src/index.ts
26
+ // satori/adapters/discord/src/index.ts
27
27
  var src_exports = {};
28
28
  __export(src_exports, {
29
29
  Discord: () => types_exports,
@@ -41,10 +41,10 @@ __export(src_exports, {
41
41
  });
42
42
  module.exports = __toCommonJS(src_exports);
43
43
 
44
- // adapters/discord/src/bot.ts
44
+ // satori/adapters/discord/src/bot.ts
45
45
  var import_satori4 = require("@satorijs/satori");
46
46
 
47
- // adapters/discord/src/utils.ts
47
+ // satori/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,
@@ -200,7 +200,7 @@ async function adaptSession(bot, input) {
200
200
  }
201
201
  __name(adaptSession, "adaptSession");
202
202
 
203
- // adapters/discord/src/sender.ts
203
+ // satori/adapters/discord/src/sender.ts
204
204
  var import_satori2 = require("@satorijs/satori");
205
205
  var import_file_type = require("file-type");
206
206
  var import_form_data = __toESM(require("form-data"));
@@ -219,6 +219,8 @@ var Sender = class {
219
219
  this.errors = [];
220
220
  this.buffer = "";
221
221
  this.addition = {};
222
+ this.figure = null;
223
+ this.mode = "default";
222
224
  }
223
225
  async post(data, headers) {
224
226
  try {
@@ -231,7 +233,7 @@ var Sender = class {
231
233
  async sendEmbed(fileBuffer, payload_json, filename) {
232
234
  const fd = new import_form_data.default();
233
235
  filename || (filename = "file." + (await (0, import_file_type.fromBuffer)(fileBuffer)).ext);
234
- fd.append("file", fileBuffer, filename);
236
+ fd.append("file", Buffer.from(fileBuffer), filename);
235
237
  fd.append("payload_json", JSON.stringify(payload_json));
236
238
  return this.post(fd, fd.getHeaders());
237
239
  }
@@ -286,9 +288,13 @@ var Sender = class {
286
288
  this.addition = {};
287
289
  }
288
290
  async render(elements) {
289
- for (const { type, attrs, children } of elements) {
291
+ for (const element of elements) {
292
+ const { type, attrs, children } = element;
290
293
  if (type === "text") {
291
294
  this.buffer += attrs.content;
295
+ } else if (type === "p") {
296
+ await this.render(children);
297
+ this.buffer += "\n";
292
298
  } else if (type === "at") {
293
299
  if (attrs.id) {
294
300
  this.buffer += `<@${attrs.id}>`;
@@ -302,11 +308,15 @@ var Sender = class {
302
308
  } else if (type === "face" && attrs.name && attrs.id) {
303
309
  this.buffer += `<:${attrs.name}:${attrs.id}>`;
304
310
  } else if ((type === "image" || type === "video") && attrs.url) {
305
- await this.sendAsset(type, attrs, {
306
- ...this.addition,
307
- content: this.buffer.trim()
308
- });
309
- this.buffer = "";
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
+ }
310
320
  } else if (type === "share") {
311
321
  await this.sendBuffer();
312
322
  await this.post({
@@ -319,19 +329,34 @@ var Sender = class {
319
329
  content: this.buffer.trim()
320
330
  });
321
331
  this.buffer = "";
332
+ } else if (type === "figure") {
333
+ await this.sendBuffer();
334
+ this.mode = "figure";
335
+ 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";
322
342
  } else if (type === "quote") {
323
343
  await this.sendBuffer();
324
344
  this.addition.message_reference = {
325
345
  message_id: attrs.id
326
346
  };
327
347
  } else if (type === "message") {
328
- await this.sendBuffer();
329
- if ("quote" in attrs) {
330
- this.addition.message_reference = {
331
- message_id: attrs.id
332
- };
348
+ if (this.mode === "figure") {
349
+ await this.render(children);
350
+ this.buffer += "\n";
333
351
  } else {
334
- await this.sendMessage(children);
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
+ }
335
360
  }
336
361
  } else {
337
362
  await this.render(children);
@@ -366,7 +391,7 @@ __name(Sender, "Sender");
366
391
  }).description("发送设置");
367
392
  })(Sender || (Sender = {}));
368
393
 
369
- // adapters/discord/src/types/index.ts
394
+ // satori/adapters/discord/src/types/index.ts
370
395
  var types_exports = {};
371
396
  __export(types_exports, {
372
397
  ActivityFlag: () => ActivityFlag,
@@ -403,7 +428,7 @@ __export(types_exports, {
403
428
  Webhook: () => Webhook2
404
429
  });
405
430
 
406
- // adapters/discord/src/types/internal.ts
431
+ // satori/adapters/discord/src/types/internal.ts
407
432
  var import_cosmokit = require("cosmokit");
408
433
  var Internal = class {
409
434
  constructor(http) {
@@ -443,7 +468,7 @@ var Internal = class {
443
468
  };
444
469
  __name(Internal, "Internal");
445
470
 
446
- // adapters/discord/src/types/application.ts
471
+ // satori/adapters/discord/src/types/application.ts
447
472
  var ApplicationFlag = /* @__PURE__ */ ((ApplicationFlag2) => {
448
473
  ApplicationFlag2[ApplicationFlag2["GATEWAY_PRESENCE"] = 4096] = "GATEWAY_PRESENCE";
449
474
  ApplicationFlag2[ApplicationFlag2["GATEWAY_PRESENCE_LIMITED"] = 8192] = "GATEWAY_PRESENCE_LIMITED";
@@ -462,7 +487,7 @@ Internal.define({
462
487
  }
463
488
  });
464
489
 
465
- // adapters/discord/src/types/audit-log.ts
490
+ // satori/adapters/discord/src/types/audit-log.ts
466
491
  var AuditLog;
467
492
  ((AuditLog2) => {
468
493
  let Type;
@@ -529,7 +554,7 @@ Internal.define({
529
554
  }
530
555
  });
531
556
 
532
- // adapters/discord/src/types/auto-moderation.ts
557
+ // satori/adapters/discord/src/types/auto-moderation.ts
533
558
  var AutoModerationRule;
534
559
  ((AutoModerationRule2) => {
535
560
  let EventType;
@@ -571,7 +596,7 @@ Internal.define({
571
596
  }
572
597
  });
573
598
 
574
- // adapters/discord/src/types/ban.ts
599
+ // satori/adapters/discord/src/types/ban.ts
575
600
  Internal.define({
576
601
  "/guilds/{guild.id}/bans": {
577
602
  GET: "getGuildBans"
@@ -583,7 +608,7 @@ Internal.define({
583
608
  }
584
609
  });
585
610
 
586
- // adapters/discord/src/types/channel.ts
611
+ // satori/adapters/discord/src/types/channel.ts
587
612
  var Channel3;
588
613
  ((Channel11) => {
589
614
  let Type;
@@ -643,7 +668,7 @@ Internal.define({
643
668
  }
644
669
  });
645
670
 
646
- // adapters/discord/src/types/command.ts
671
+ // satori/adapters/discord/src/types/command.ts
647
672
  var ApplicationCommand;
648
673
  ((ApplicationCommand3) => {
649
674
  let Type;
@@ -702,7 +727,7 @@ Internal.define({
702
727
  }
703
728
  });
704
729
 
705
- // adapters/discord/src/types/component.ts
730
+ // satori/adapters/discord/src/types/component.ts
706
731
  var ComponentType = /* @__PURE__ */ ((ComponentType2) => {
707
732
  ComponentType2[ComponentType2["ACTION_ROW"] = 1] = "ACTION_ROW";
708
733
  ComponentType2[ComponentType2["BUTTON"] = 2] = "BUTTON";
@@ -716,7 +741,7 @@ var TextInputStyles = /* @__PURE__ */ ((TextInputStyles2) => {
716
741
  return TextInputStyles2;
717
742
  })(TextInputStyles || {});
718
743
 
719
- // adapters/discord/src/types/device.ts
744
+ // satori/adapters/discord/src/types/device.ts
720
745
  var DeviceType = /* @__PURE__ */ ((DeviceType2) => {
721
746
  DeviceType2["AUDIO_INPUT"] = "audioinput";
722
747
  DeviceType2["AUDIO_OUTPUT"] = "audiooutput";
@@ -724,7 +749,7 @@ var DeviceType = /* @__PURE__ */ ((DeviceType2) => {
724
749
  return DeviceType2;
725
750
  })(DeviceType || {});
726
751
 
727
- // adapters/discord/src/types/emoji.ts
752
+ // satori/adapters/discord/src/types/emoji.ts
728
753
  Internal.define({
729
754
  "/guilds/{guild.id}/emojis": {
730
755
  GET: "listGuildEmojis",
@@ -737,7 +762,7 @@ Internal.define({
737
762
  }
738
763
  });
739
764
 
740
- // adapters/discord/src/types/gateway.ts
765
+ // satori/adapters/discord/src/types/gateway.ts
741
766
  var GatewayOpcode = /* @__PURE__ */ ((GatewayOpcode2) => {
742
767
  GatewayOpcode2[GatewayOpcode2["DISPATCH"] = 0] = "DISPATCH";
743
768
  GatewayOpcode2[GatewayOpcode2["HEARTBEAT"] = 1] = "HEARTBEAT";
@@ -783,7 +808,7 @@ Internal.define({
783
808
  }
784
809
  });
785
810
 
786
- // adapters/discord/src/types/guild-member.ts
811
+ // satori/adapters/discord/src/types/guild-member.ts
787
812
  Internal.define({
788
813
  "/guilds/{guild.id}/members/{user.id}": {
789
814
  GET: "getGuildMember",
@@ -810,7 +835,7 @@ Internal.define({
810
835
  }
811
836
  });
812
837
 
813
- // adapters/discord/src/types/guild-template.ts
838
+ // satori/adapters/discord/src/types/guild-template.ts
814
839
  Internal.define({
815
840
  "/guilds/templates/{template.code}": {
816
841
  GET: "getGuildTemplate",
@@ -827,7 +852,7 @@ Internal.define({
827
852
  }
828
853
  });
829
854
 
830
- // adapters/discord/src/types/guild.ts
855
+ // satori/adapters/discord/src/types/guild.ts
831
856
  var Guild4;
832
857
  ((Guild7) => {
833
858
  let Params;
@@ -912,7 +937,7 @@ Internal.define({
912
937
  }
913
938
  });
914
939
 
915
- // adapters/discord/src/types/integration.ts
940
+ // satori/adapters/discord/src/types/integration.ts
916
941
  var IntegrationExpireBehavior = /* @__PURE__ */ ((IntegrationExpireBehavior2) => {
917
942
  IntegrationExpireBehavior2[IntegrationExpireBehavior2["REMOVE_ROLE"] = 0] = "REMOVE_ROLE";
918
943
  IntegrationExpireBehavior2[IntegrationExpireBehavior2["KICK"] = 1] = "KICK";
@@ -927,7 +952,7 @@ Internal.define({
927
952
  }
928
953
  });
929
954
 
930
- // adapters/discord/src/types/interaction.ts
955
+ // satori/adapters/discord/src/types/interaction.ts
931
956
  var InteractionType = /* @__PURE__ */ ((InteractionType2) => {
932
957
  InteractionType2[InteractionType2["PING"] = 1] = "PING";
933
958
  InteractionType2[InteractionType2["APPLICATION_COMMAND"] = 2] = "APPLICATION_COMMAND";
@@ -967,7 +992,7 @@ Internal.define({
967
992
  }
968
993
  });
969
994
 
970
- // adapters/discord/src/types/invite.ts
995
+ // satori/adapters/discord/src/types/invite.ts
971
996
  var Invite;
972
997
  ((Invite2) => {
973
998
  let TargetType;
@@ -993,7 +1018,7 @@ Internal.define({
993
1018
  }
994
1019
  });
995
1020
 
996
- // adapters/discord/src/types/message.ts
1021
+ // satori/adapters/discord/src/types/message.ts
997
1022
  var Message3;
998
1023
  ((Message6) => {
999
1024
  let Type;
@@ -1066,7 +1091,7 @@ Internal.define({
1066
1091
  }
1067
1092
  });
1068
1093
 
1069
- // adapters/discord/src/types/presence.ts
1094
+ // satori/adapters/discord/src/types/presence.ts
1070
1095
  var StatusType2 = /* @__PURE__ */ ((StatusType3) => {
1071
1096
  StatusType3["ONLINE"] = "ONLINE";
1072
1097
  StatusType3["DND"] = "DND";
@@ -1094,7 +1119,7 @@ var ActivityFlag = /* @__PURE__ */ ((ActivityFlag2) => {
1094
1119
  return ActivityFlag2;
1095
1120
  })(ActivityFlag || {});
1096
1121
 
1097
- // adapters/discord/src/types/reaction.ts
1122
+ // satori/adapters/discord/src/types/reaction.ts
1098
1123
  Internal.define({
1099
1124
  "/channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me": {
1100
1125
  PUT: "createReaction",
@@ -1112,7 +1137,7 @@ Internal.define({
1112
1137
  }
1113
1138
  });
1114
1139
 
1115
- // adapters/discord/src/types/role.ts
1140
+ // satori/adapters/discord/src/types/role.ts
1116
1141
  var Permission = /* @__PURE__ */ ((Permission2) => {
1117
1142
  Permission2[Permission2["CREATE_INSTANT_INVITE"] = 1] = "CREATE_INSTANT_INVITE";
1118
1143
  Permission2[Permission2["KICK_MEMBERS"] = 2] = "KICK_MEMBERS";
@@ -1167,7 +1192,7 @@ Internal.define({
1167
1192
  }
1168
1193
  });
1169
1194
 
1170
- // adapters/discord/src/types/scheduled-event.ts
1195
+ // satori/adapters/discord/src/types/scheduled-event.ts
1171
1196
  var GuildScheduledEvent;
1172
1197
  ((GuildScheduledEvent2) => {
1173
1198
  let PrivacyLevel;
@@ -1203,7 +1228,7 @@ Internal.define({
1203
1228
  }
1204
1229
  });
1205
1230
 
1206
- // adapters/discord/src/types/stage-instance.ts
1231
+ // satori/adapters/discord/src/types/stage-instance.ts
1207
1232
  Internal.define({
1208
1233
  "/stage-instances": {
1209
1234
  POST: "createStageInstance"
@@ -1215,7 +1240,7 @@ Internal.define({
1215
1240
  }
1216
1241
  });
1217
1242
 
1218
- // adapters/discord/src/types/sticker.ts
1243
+ // satori/adapters/discord/src/types/sticker.ts
1219
1244
  var Sticker3;
1220
1245
  ((Sticker4) => {
1221
1246
  let Type;
@@ -1248,14 +1273,14 @@ Internal.define({
1248
1273
  }
1249
1274
  });
1250
1275
 
1251
- // adapters/discord/src/types/team.ts
1276
+ // satori/adapters/discord/src/types/team.ts
1252
1277
  var MembershipState = /* @__PURE__ */ ((MembershipState2) => {
1253
1278
  MembershipState2[MembershipState2["INVITED"] = 1] = "INVITED";
1254
1279
  MembershipState2[MembershipState2["ACCEPTED"] = 2] = "ACCEPTED";
1255
1280
  return MembershipState2;
1256
1281
  })(MembershipState || {});
1257
1282
 
1258
- // adapters/discord/src/types/thread.ts
1283
+ // satori/adapters/discord/src/types/thread.ts
1259
1284
  Internal.define({
1260
1285
  "/guilds/{guild.id}/threads/active": {
1261
1286
  GET: "listActiveGuildThreads"
@@ -1292,7 +1317,7 @@ Internal.define({
1292
1317
  }
1293
1318
  });
1294
1319
 
1295
- // adapters/discord/src/types/user.ts
1320
+ // satori/adapters/discord/src/types/user.ts
1296
1321
  var UserFlag = /* @__PURE__ */ ((UserFlag2) => {
1297
1322
  UserFlag2[UserFlag2["NONE"] = 0] = "NONE";
1298
1323
  UserFlag2[UserFlag2["DISCORD_EMPLOYEE"] = 1] = "DISCORD_EMPLOYEE";
@@ -1328,7 +1353,7 @@ Internal.define({
1328
1353
  }
1329
1354
  });
1330
1355
 
1331
- // adapters/discord/src/types/voice.ts
1356
+ // satori/adapters/discord/src/types/voice.ts
1332
1357
  Internal.define({
1333
1358
  "/voice/regions": {
1334
1359
  GET: "listVoiceRegions"
@@ -1344,7 +1369,7 @@ Internal.define({
1344
1369
  }
1345
1370
  });
1346
1371
 
1347
- // adapters/discord/src/types/webhook.ts
1372
+ // satori/adapters/discord/src/types/webhook.ts
1348
1373
  var Webhook2;
1349
1374
  ((Webhook3) => {
1350
1375
  let Type;
@@ -1386,7 +1411,7 @@ Internal.define({
1386
1411
  }
1387
1412
  });
1388
1413
 
1389
- // adapters/discord/src/ws.ts
1414
+ // satori/adapters/discord/src/ws.ts
1390
1415
  var import_satori3 = require("@satorijs/satori");
1391
1416
  var logger = new import_satori3.Logger("discord");
1392
1417
  var WsClient = class extends import_satori3.Adapter.WsClient {
@@ -1474,7 +1499,7 @@ __name(WsClient, "WsClient");
1474
1499
  ]);
1475
1500
  })(WsClient || (WsClient = {}));
1476
1501
 
1477
- // adapters/discord/src/bot.ts
1502
+ // satori/adapters/discord/src/bot.ts
1478
1503
  var DiscordBot = class extends import_satori4.Bot {
1479
1504
  constructor(ctx, config) {
1480
1505
  super(ctx, config);
@@ -1591,7 +1616,7 @@ __name(DiscordBot, "DiscordBot");
1591
1616
  })(DiscordBot || (DiscordBot = {}));
1592
1617
  DiscordBot.prototype.platform = "discord";
1593
1618
 
1594
- // adapters/discord/src/index.ts
1619
+ // satori/adapters/discord/src/index.ts
1595
1620
  var src_default = DiscordBot;
1596
1621
  // Annotate the CommonJS export names for ESM import in node:
1597
1622
  0 && (module.exports = {