@satorijs/adapter-discord 3.3.1 → 3.3.3

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,
@@ -67,6 +67,7 @@ var adaptAuthor = /* @__PURE__ */ __name((author) => ({
67
67
  }), "adaptAuthor");
68
68
  async function adaptMessage(bot, meta, session = {}) {
69
69
  var _a, _b, _c;
70
+ const { platform } = bot;
70
71
  prepareMessage(session, meta);
71
72
  session.messageId = meta.id;
72
73
  session.timestamp = new Date(meta.timestamp).valueOf() || Date.now();
@@ -87,7 +88,12 @@ async function adaptMessage(bot, meta, session = {}) {
87
88
  const user = (_a2 = meta.mentions) == null ? void 0 : _a2.find((u) => u.id === id || `${u.username}#${u.discriminator}` === id);
88
89
  return import_satori.segment.at(id, { name: user == null ? void 0 : user.username }).toString();
89
90
  }
90
- }).replace(/<:(.*):(.+?)>/g, (_, name, id) => (0, import_satori.segment)("face", { id, name }).toString()).replace(/<a:(.*):(.+?)>/g, (_, name, id) => (0, import_satori.segment)("face", { id, name, animated: true }).toString()).replace(/@everyone/g, () => (0, import_satori.segment)("at", { type: "all" }).toString()).replace(/@here/g, () => (0, import_satori.segment)("at", { type: "here" }).toString()).replace(/<#(.+?)>/g, (_, id) => {
91
+ }).replace(/<a?:(.*):(.+?)>/g, (_, name, id) => {
92
+ const animated = _[1] === "a";
93
+ return (0, import_satori.segment)("face", { id, name, animated, platform }, [
94
+ import_satori.segment.image(`https://cdn.discordapp.com/emojis/${id}.gif?quality=lossless`)
95
+ ]).toString();
96
+ }).replace(/@everyone/g, () => (0, import_satori.segment)("at", { type: "all" }).toString()).replace(/@here/g, () => (0, import_satori.segment)("at", { type: "here" }).toString()).replace(/<#(.+?)>/g, (_, id) => {
91
97
  var _a2;
92
98
  const channel = (_a2 = meta.mention_channels) == null ? void 0 : _a2.find((c) => c.id === id);
93
99
  return import_satori.segment.sharp(id, { name: channel == null ? void 0 : channel.name }).toString();
@@ -202,7 +208,7 @@ async function adaptSession(bot, input) {
202
208
  }
203
209
  __name(adaptSession, "adaptSession");
204
210
 
205
- // adapters/discord/src/message.ts
211
+ // satori/adapters/discord/src/message.ts
206
212
  var import_satori2 = require("@satorijs/satori");
207
213
  var import_file_type = require("file-type");
208
214
  var import_form_data = __toESM(require("form-data"));
@@ -326,8 +332,12 @@ var DiscordMessenger = class extends import_satori2.Messenger {
326
332
  }
327
333
  } else if (type === "sharp" && attrs.id) {
328
334
  this.buffer += `<#${attrs.id}>`;
329
- } else if (type === "face" && attrs.name && attrs.id) {
330
- this.buffer += `<:${attrs.name}:${attrs.id}>`;
335
+ } else if (type === "face") {
336
+ if (attrs.platform && attrs.platform !== this.bot.platform) {
337
+ return this.render(children);
338
+ } else {
339
+ this.buffer += `<${attrs.animated ? "a" : ""}:${attrs.name}:${attrs.id}>`;
340
+ }
331
341
  } else if ((type === "image" || type === "video") && attrs.url) {
332
342
  if (this.mode === "figure") {
333
343
  this.figure = element;
@@ -371,7 +381,8 @@ var DiscordMessenger = class extends import_satori2.Messenger {
371
381
  this.buffer += "\n";
372
382
  } else {
373
383
  await this.flush();
374
- await this.render(children, true);
384
+ await this.render(children);
385
+ await this.flush();
375
386
  }
376
387
  } else {
377
388
  await this.render(children);
@@ -394,7 +405,7 @@ __name(DiscordMessenger, "DiscordMessenger");
394
405
  }).description("发送设置");
395
406
  })(DiscordMessenger || (DiscordMessenger = {}));
396
407
 
397
- // adapters/discord/src/types/index.ts
408
+ // satori/adapters/discord/src/types/index.ts
398
409
  var types_exports = {};
399
410
  __export(types_exports, {
400
411
  ActivityFlag: () => ActivityFlag,
@@ -431,7 +442,7 @@ __export(types_exports, {
431
442
  Webhook: () => Webhook2
432
443
  });
433
444
 
434
- // adapters/discord/src/types/internal.ts
445
+ // satori/adapters/discord/src/types/internal.ts
435
446
  var import_cosmokit = require("cosmokit");
436
447
  var Internal = class {
437
448
  constructor(http) {
@@ -471,7 +482,7 @@ var Internal = class {
471
482
  };
472
483
  __name(Internal, "Internal");
473
484
 
474
- // adapters/discord/src/types/application.ts
485
+ // satori/adapters/discord/src/types/application.ts
475
486
  var ApplicationFlag = /* @__PURE__ */ ((ApplicationFlag2) => {
476
487
  ApplicationFlag2[ApplicationFlag2["GATEWAY_PRESENCE"] = 4096] = "GATEWAY_PRESENCE";
477
488
  ApplicationFlag2[ApplicationFlag2["GATEWAY_PRESENCE_LIMITED"] = 8192] = "GATEWAY_PRESENCE_LIMITED";
@@ -490,7 +501,7 @@ Internal.define({
490
501
  }
491
502
  });
492
503
 
493
- // adapters/discord/src/types/audit-log.ts
504
+ // satori/adapters/discord/src/types/audit-log.ts
494
505
  var AuditLog;
495
506
  ((AuditLog2) => {
496
507
  let Type;
@@ -557,7 +568,7 @@ Internal.define({
557
568
  }
558
569
  });
559
570
 
560
- // adapters/discord/src/types/auto-moderation.ts
571
+ // satori/adapters/discord/src/types/auto-moderation.ts
561
572
  var AutoModerationRule;
562
573
  ((AutoModerationRule2) => {
563
574
  let EventType;
@@ -599,7 +610,7 @@ Internal.define({
599
610
  }
600
611
  });
601
612
 
602
- // adapters/discord/src/types/ban.ts
613
+ // satori/adapters/discord/src/types/ban.ts
603
614
  Internal.define({
604
615
  "/guilds/{guild.id}/bans": {
605
616
  GET: "getGuildBans"
@@ -611,7 +622,7 @@ Internal.define({
611
622
  }
612
623
  });
613
624
 
614
- // adapters/discord/src/types/channel.ts
625
+ // satori/adapters/discord/src/types/channel.ts
615
626
  var Channel2;
616
627
  ((Channel10) => {
617
628
  let Type;
@@ -671,7 +682,7 @@ Internal.define({
671
682
  }
672
683
  });
673
684
 
674
- // adapters/discord/src/types/command.ts
685
+ // satori/adapters/discord/src/types/command.ts
675
686
  var ApplicationCommand;
676
687
  ((ApplicationCommand3) => {
677
688
  let Type;
@@ -730,7 +741,7 @@ Internal.define({
730
741
  }
731
742
  });
732
743
 
733
- // adapters/discord/src/types/component.ts
744
+ // satori/adapters/discord/src/types/component.ts
734
745
  var ComponentType = /* @__PURE__ */ ((ComponentType2) => {
735
746
  ComponentType2[ComponentType2["ACTION_ROW"] = 1] = "ACTION_ROW";
736
747
  ComponentType2[ComponentType2["BUTTON"] = 2] = "BUTTON";
@@ -744,7 +755,7 @@ var TextInputStyles = /* @__PURE__ */ ((TextInputStyles2) => {
744
755
  return TextInputStyles2;
745
756
  })(TextInputStyles || {});
746
757
 
747
- // adapters/discord/src/types/device.ts
758
+ // satori/adapters/discord/src/types/device.ts
748
759
  var DeviceType = /* @__PURE__ */ ((DeviceType2) => {
749
760
  DeviceType2["AUDIO_INPUT"] = "audioinput";
750
761
  DeviceType2["AUDIO_OUTPUT"] = "audiooutput";
@@ -752,7 +763,7 @@ var DeviceType = /* @__PURE__ */ ((DeviceType2) => {
752
763
  return DeviceType2;
753
764
  })(DeviceType || {});
754
765
 
755
- // adapters/discord/src/types/emoji.ts
766
+ // satori/adapters/discord/src/types/emoji.ts
756
767
  Internal.define({
757
768
  "/guilds/{guild.id}/emojis": {
758
769
  GET: "listGuildEmojis",
@@ -765,7 +776,7 @@ Internal.define({
765
776
  }
766
777
  });
767
778
 
768
- // adapters/discord/src/types/gateway.ts
779
+ // satori/adapters/discord/src/types/gateway.ts
769
780
  var GatewayOpcode = /* @__PURE__ */ ((GatewayOpcode2) => {
770
781
  GatewayOpcode2[GatewayOpcode2["DISPATCH"] = 0] = "DISPATCH";
771
782
  GatewayOpcode2[GatewayOpcode2["HEARTBEAT"] = 1] = "HEARTBEAT";
@@ -811,7 +822,7 @@ Internal.define({
811
822
  }
812
823
  });
813
824
 
814
- // adapters/discord/src/types/guild-member.ts
825
+ // satori/adapters/discord/src/types/guild-member.ts
815
826
  Internal.define({
816
827
  "/guilds/{guild.id}/members/{user.id}": {
817
828
  GET: "getGuildMember",
@@ -838,7 +849,7 @@ Internal.define({
838
849
  }
839
850
  });
840
851
 
841
- // adapters/discord/src/types/guild-template.ts
852
+ // satori/adapters/discord/src/types/guild-template.ts
842
853
  Internal.define({
843
854
  "/guilds/templates/{template.code}": {
844
855
  GET: "getGuildTemplate",
@@ -855,7 +866,7 @@ Internal.define({
855
866
  }
856
867
  });
857
868
 
858
- // adapters/discord/src/types/guild.ts
869
+ // satori/adapters/discord/src/types/guild.ts
859
870
  var Guild3;
860
871
  ((Guild6) => {
861
872
  let Params;
@@ -940,7 +951,7 @@ Internal.define({
940
951
  }
941
952
  });
942
953
 
943
- // adapters/discord/src/types/integration.ts
954
+ // satori/adapters/discord/src/types/integration.ts
944
955
  var IntegrationExpireBehavior = /* @__PURE__ */ ((IntegrationExpireBehavior2) => {
945
956
  IntegrationExpireBehavior2[IntegrationExpireBehavior2["REMOVE_ROLE"] = 0] = "REMOVE_ROLE";
946
957
  IntegrationExpireBehavior2[IntegrationExpireBehavior2["KICK"] = 1] = "KICK";
@@ -955,7 +966,7 @@ Internal.define({
955
966
  }
956
967
  });
957
968
 
958
- // adapters/discord/src/types/interaction.ts
969
+ // satori/adapters/discord/src/types/interaction.ts
959
970
  var InteractionType = /* @__PURE__ */ ((InteractionType2) => {
960
971
  InteractionType2[InteractionType2["PING"] = 1] = "PING";
961
972
  InteractionType2[InteractionType2["APPLICATION_COMMAND"] = 2] = "APPLICATION_COMMAND";
@@ -995,7 +1006,7 @@ Internal.define({
995
1006
  }
996
1007
  });
997
1008
 
998
- // adapters/discord/src/types/invite.ts
1009
+ // satori/adapters/discord/src/types/invite.ts
999
1010
  var Invite;
1000
1011
  ((Invite2) => {
1001
1012
  let TargetType;
@@ -1021,7 +1032,7 @@ Internal.define({
1021
1032
  }
1022
1033
  });
1023
1034
 
1024
- // adapters/discord/src/types/message.ts
1035
+ // satori/adapters/discord/src/types/message.ts
1025
1036
  var Message2;
1026
1037
  ((Message4) => {
1027
1038
  let Type;
@@ -1094,7 +1105,7 @@ Internal.define({
1094
1105
  }
1095
1106
  });
1096
1107
 
1097
- // adapters/discord/src/types/presence.ts
1108
+ // satori/adapters/discord/src/types/presence.ts
1098
1109
  var StatusType2 = /* @__PURE__ */ ((StatusType3) => {
1099
1110
  StatusType3["ONLINE"] = "ONLINE";
1100
1111
  StatusType3["DND"] = "DND";
@@ -1122,7 +1133,7 @@ var ActivityFlag = /* @__PURE__ */ ((ActivityFlag2) => {
1122
1133
  return ActivityFlag2;
1123
1134
  })(ActivityFlag || {});
1124
1135
 
1125
- // adapters/discord/src/types/reaction.ts
1136
+ // satori/adapters/discord/src/types/reaction.ts
1126
1137
  Internal.define({
1127
1138
  "/channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me": {
1128
1139
  PUT: "createReaction",
@@ -1140,7 +1151,7 @@ Internal.define({
1140
1151
  }
1141
1152
  });
1142
1153
 
1143
- // adapters/discord/src/types/role.ts
1154
+ // satori/adapters/discord/src/types/role.ts
1144
1155
  var Permission = /* @__PURE__ */ ((Permission2) => {
1145
1156
  Permission2[Permission2["CREATE_INSTANT_INVITE"] = 1] = "CREATE_INSTANT_INVITE";
1146
1157
  Permission2[Permission2["KICK_MEMBERS"] = 2] = "KICK_MEMBERS";
@@ -1195,7 +1206,7 @@ Internal.define({
1195
1206
  }
1196
1207
  });
1197
1208
 
1198
- // adapters/discord/src/types/scheduled-event.ts
1209
+ // satori/adapters/discord/src/types/scheduled-event.ts
1199
1210
  var GuildScheduledEvent;
1200
1211
  ((GuildScheduledEvent2) => {
1201
1212
  let PrivacyLevel;
@@ -1231,7 +1242,7 @@ Internal.define({
1231
1242
  }
1232
1243
  });
1233
1244
 
1234
- // adapters/discord/src/types/stage-instance.ts
1245
+ // satori/adapters/discord/src/types/stage-instance.ts
1235
1246
  Internal.define({
1236
1247
  "/stage-instances": {
1237
1248
  POST: "createStageInstance"
@@ -1243,7 +1254,7 @@ Internal.define({
1243
1254
  }
1244
1255
  });
1245
1256
 
1246
- // adapters/discord/src/types/sticker.ts
1257
+ // satori/adapters/discord/src/types/sticker.ts
1247
1258
  var Sticker3;
1248
1259
  ((Sticker4) => {
1249
1260
  let Type;
@@ -1276,14 +1287,14 @@ Internal.define({
1276
1287
  }
1277
1288
  });
1278
1289
 
1279
- // adapters/discord/src/types/team.ts
1290
+ // satori/adapters/discord/src/types/team.ts
1280
1291
  var MembershipState = /* @__PURE__ */ ((MembershipState2) => {
1281
1292
  MembershipState2[MembershipState2["INVITED"] = 1] = "INVITED";
1282
1293
  MembershipState2[MembershipState2["ACCEPTED"] = 2] = "ACCEPTED";
1283
1294
  return MembershipState2;
1284
1295
  })(MembershipState || {});
1285
1296
 
1286
- // adapters/discord/src/types/thread.ts
1297
+ // satori/adapters/discord/src/types/thread.ts
1287
1298
  Internal.define({
1288
1299
  "/guilds/{guild.id}/threads/active": {
1289
1300
  GET: "listActiveGuildThreads"
@@ -1320,7 +1331,7 @@ Internal.define({
1320
1331
  }
1321
1332
  });
1322
1333
 
1323
- // adapters/discord/src/types/user.ts
1334
+ // satori/adapters/discord/src/types/user.ts
1324
1335
  var UserFlag = /* @__PURE__ */ ((UserFlag2) => {
1325
1336
  UserFlag2[UserFlag2["NONE"] = 0] = "NONE";
1326
1337
  UserFlag2[UserFlag2["DISCORD_EMPLOYEE"] = 1] = "DISCORD_EMPLOYEE";
@@ -1356,7 +1367,7 @@ Internal.define({
1356
1367
  }
1357
1368
  });
1358
1369
 
1359
- // adapters/discord/src/types/voice.ts
1370
+ // satori/adapters/discord/src/types/voice.ts
1360
1371
  Internal.define({
1361
1372
  "/voice/regions": {
1362
1373
  GET: "listVoiceRegions"
@@ -1372,7 +1383,7 @@ Internal.define({
1372
1383
  }
1373
1384
  });
1374
1385
 
1375
- // adapters/discord/src/types/webhook.ts
1386
+ // satori/adapters/discord/src/types/webhook.ts
1376
1387
  var Webhook2;
1377
1388
  ((Webhook3) => {
1378
1389
  let Type;
@@ -1414,7 +1425,7 @@ Internal.define({
1414
1425
  }
1415
1426
  });
1416
1427
 
1417
- // adapters/discord/src/ws.ts
1428
+ // satori/adapters/discord/src/ws.ts
1418
1429
  var import_satori3 = require("@satorijs/satori");
1419
1430
  var logger = new import_satori3.Logger("discord");
1420
1431
  var WsClient = class extends import_satori3.Adapter.WsClient {
@@ -1502,7 +1513,7 @@ __name(WsClient, "WsClient");
1502
1513
  ]);
1503
1514
  })(WsClient || (WsClient = {}));
1504
1515
 
1505
- // adapters/discord/src/bot.ts
1516
+ // satori/adapters/discord/src/bot.ts
1506
1517
  var DiscordBot = class extends import_satori4.Bot {
1507
1518
  constructor(ctx, config) {
1508
1519
  super(ctx, config);
@@ -1596,7 +1607,7 @@ __name(DiscordBot, "DiscordBot");
1596
1607
  })(DiscordBot || (DiscordBot = {}));
1597
1608
  DiscordBot.prototype.platform = "discord";
1598
1609
 
1599
- // adapters/discord/src/index.ts
1610
+ // satori/adapters/discord/src/index.ts
1600
1611
  var src_default = DiscordBot;
1601
1612
  // Annotate the CommonJS export names for ESM import in node:
1602
1613
  0 && (module.exports = {