@satorijs/adapter-discord 3.3.1 → 3.3.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/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;
@@ -394,7 +404,7 @@ __name(DiscordMessenger, "DiscordMessenger");
394
404
  }).description("发送设置");
395
405
  })(DiscordMessenger || (DiscordMessenger = {}));
396
406
 
397
- // adapters/discord/src/types/index.ts
407
+ // satori/adapters/discord/src/types/index.ts
398
408
  var types_exports = {};
399
409
  __export(types_exports, {
400
410
  ActivityFlag: () => ActivityFlag,
@@ -431,7 +441,7 @@ __export(types_exports, {
431
441
  Webhook: () => Webhook2
432
442
  });
433
443
 
434
- // adapters/discord/src/types/internal.ts
444
+ // satori/adapters/discord/src/types/internal.ts
435
445
  var import_cosmokit = require("cosmokit");
436
446
  var Internal = class {
437
447
  constructor(http) {
@@ -471,7 +481,7 @@ var Internal = class {
471
481
  };
472
482
  __name(Internal, "Internal");
473
483
 
474
- // adapters/discord/src/types/application.ts
484
+ // satori/adapters/discord/src/types/application.ts
475
485
  var ApplicationFlag = /* @__PURE__ */ ((ApplicationFlag2) => {
476
486
  ApplicationFlag2[ApplicationFlag2["GATEWAY_PRESENCE"] = 4096] = "GATEWAY_PRESENCE";
477
487
  ApplicationFlag2[ApplicationFlag2["GATEWAY_PRESENCE_LIMITED"] = 8192] = "GATEWAY_PRESENCE_LIMITED";
@@ -490,7 +500,7 @@ Internal.define({
490
500
  }
491
501
  });
492
502
 
493
- // adapters/discord/src/types/audit-log.ts
503
+ // satori/adapters/discord/src/types/audit-log.ts
494
504
  var AuditLog;
495
505
  ((AuditLog2) => {
496
506
  let Type;
@@ -557,7 +567,7 @@ Internal.define({
557
567
  }
558
568
  });
559
569
 
560
- // adapters/discord/src/types/auto-moderation.ts
570
+ // satori/adapters/discord/src/types/auto-moderation.ts
561
571
  var AutoModerationRule;
562
572
  ((AutoModerationRule2) => {
563
573
  let EventType;
@@ -599,7 +609,7 @@ Internal.define({
599
609
  }
600
610
  });
601
611
 
602
- // adapters/discord/src/types/ban.ts
612
+ // satori/adapters/discord/src/types/ban.ts
603
613
  Internal.define({
604
614
  "/guilds/{guild.id}/bans": {
605
615
  GET: "getGuildBans"
@@ -611,7 +621,7 @@ Internal.define({
611
621
  }
612
622
  });
613
623
 
614
- // adapters/discord/src/types/channel.ts
624
+ // satori/adapters/discord/src/types/channel.ts
615
625
  var Channel2;
616
626
  ((Channel10) => {
617
627
  let Type;
@@ -671,7 +681,7 @@ Internal.define({
671
681
  }
672
682
  });
673
683
 
674
- // adapters/discord/src/types/command.ts
684
+ // satori/adapters/discord/src/types/command.ts
675
685
  var ApplicationCommand;
676
686
  ((ApplicationCommand3) => {
677
687
  let Type;
@@ -730,7 +740,7 @@ Internal.define({
730
740
  }
731
741
  });
732
742
 
733
- // adapters/discord/src/types/component.ts
743
+ // satori/adapters/discord/src/types/component.ts
734
744
  var ComponentType = /* @__PURE__ */ ((ComponentType2) => {
735
745
  ComponentType2[ComponentType2["ACTION_ROW"] = 1] = "ACTION_ROW";
736
746
  ComponentType2[ComponentType2["BUTTON"] = 2] = "BUTTON";
@@ -744,7 +754,7 @@ var TextInputStyles = /* @__PURE__ */ ((TextInputStyles2) => {
744
754
  return TextInputStyles2;
745
755
  })(TextInputStyles || {});
746
756
 
747
- // adapters/discord/src/types/device.ts
757
+ // satori/adapters/discord/src/types/device.ts
748
758
  var DeviceType = /* @__PURE__ */ ((DeviceType2) => {
749
759
  DeviceType2["AUDIO_INPUT"] = "audioinput";
750
760
  DeviceType2["AUDIO_OUTPUT"] = "audiooutput";
@@ -752,7 +762,7 @@ var DeviceType = /* @__PURE__ */ ((DeviceType2) => {
752
762
  return DeviceType2;
753
763
  })(DeviceType || {});
754
764
 
755
- // adapters/discord/src/types/emoji.ts
765
+ // satori/adapters/discord/src/types/emoji.ts
756
766
  Internal.define({
757
767
  "/guilds/{guild.id}/emojis": {
758
768
  GET: "listGuildEmojis",
@@ -765,7 +775,7 @@ Internal.define({
765
775
  }
766
776
  });
767
777
 
768
- // adapters/discord/src/types/gateway.ts
778
+ // satori/adapters/discord/src/types/gateway.ts
769
779
  var GatewayOpcode = /* @__PURE__ */ ((GatewayOpcode2) => {
770
780
  GatewayOpcode2[GatewayOpcode2["DISPATCH"] = 0] = "DISPATCH";
771
781
  GatewayOpcode2[GatewayOpcode2["HEARTBEAT"] = 1] = "HEARTBEAT";
@@ -811,7 +821,7 @@ Internal.define({
811
821
  }
812
822
  });
813
823
 
814
- // adapters/discord/src/types/guild-member.ts
824
+ // satori/adapters/discord/src/types/guild-member.ts
815
825
  Internal.define({
816
826
  "/guilds/{guild.id}/members/{user.id}": {
817
827
  GET: "getGuildMember",
@@ -838,7 +848,7 @@ Internal.define({
838
848
  }
839
849
  });
840
850
 
841
- // adapters/discord/src/types/guild-template.ts
851
+ // satori/adapters/discord/src/types/guild-template.ts
842
852
  Internal.define({
843
853
  "/guilds/templates/{template.code}": {
844
854
  GET: "getGuildTemplate",
@@ -855,7 +865,7 @@ Internal.define({
855
865
  }
856
866
  });
857
867
 
858
- // adapters/discord/src/types/guild.ts
868
+ // satori/adapters/discord/src/types/guild.ts
859
869
  var Guild3;
860
870
  ((Guild6) => {
861
871
  let Params;
@@ -940,7 +950,7 @@ Internal.define({
940
950
  }
941
951
  });
942
952
 
943
- // adapters/discord/src/types/integration.ts
953
+ // satori/adapters/discord/src/types/integration.ts
944
954
  var IntegrationExpireBehavior = /* @__PURE__ */ ((IntegrationExpireBehavior2) => {
945
955
  IntegrationExpireBehavior2[IntegrationExpireBehavior2["REMOVE_ROLE"] = 0] = "REMOVE_ROLE";
946
956
  IntegrationExpireBehavior2[IntegrationExpireBehavior2["KICK"] = 1] = "KICK";
@@ -955,7 +965,7 @@ Internal.define({
955
965
  }
956
966
  });
957
967
 
958
- // adapters/discord/src/types/interaction.ts
968
+ // satori/adapters/discord/src/types/interaction.ts
959
969
  var InteractionType = /* @__PURE__ */ ((InteractionType2) => {
960
970
  InteractionType2[InteractionType2["PING"] = 1] = "PING";
961
971
  InteractionType2[InteractionType2["APPLICATION_COMMAND"] = 2] = "APPLICATION_COMMAND";
@@ -995,7 +1005,7 @@ Internal.define({
995
1005
  }
996
1006
  });
997
1007
 
998
- // adapters/discord/src/types/invite.ts
1008
+ // satori/adapters/discord/src/types/invite.ts
999
1009
  var Invite;
1000
1010
  ((Invite2) => {
1001
1011
  let TargetType;
@@ -1021,7 +1031,7 @@ Internal.define({
1021
1031
  }
1022
1032
  });
1023
1033
 
1024
- // adapters/discord/src/types/message.ts
1034
+ // satori/adapters/discord/src/types/message.ts
1025
1035
  var Message2;
1026
1036
  ((Message4) => {
1027
1037
  let Type;
@@ -1094,7 +1104,7 @@ Internal.define({
1094
1104
  }
1095
1105
  });
1096
1106
 
1097
- // adapters/discord/src/types/presence.ts
1107
+ // satori/adapters/discord/src/types/presence.ts
1098
1108
  var StatusType2 = /* @__PURE__ */ ((StatusType3) => {
1099
1109
  StatusType3["ONLINE"] = "ONLINE";
1100
1110
  StatusType3["DND"] = "DND";
@@ -1122,7 +1132,7 @@ var ActivityFlag = /* @__PURE__ */ ((ActivityFlag2) => {
1122
1132
  return ActivityFlag2;
1123
1133
  })(ActivityFlag || {});
1124
1134
 
1125
- // adapters/discord/src/types/reaction.ts
1135
+ // satori/adapters/discord/src/types/reaction.ts
1126
1136
  Internal.define({
1127
1137
  "/channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me": {
1128
1138
  PUT: "createReaction",
@@ -1140,7 +1150,7 @@ Internal.define({
1140
1150
  }
1141
1151
  });
1142
1152
 
1143
- // adapters/discord/src/types/role.ts
1153
+ // satori/adapters/discord/src/types/role.ts
1144
1154
  var Permission = /* @__PURE__ */ ((Permission2) => {
1145
1155
  Permission2[Permission2["CREATE_INSTANT_INVITE"] = 1] = "CREATE_INSTANT_INVITE";
1146
1156
  Permission2[Permission2["KICK_MEMBERS"] = 2] = "KICK_MEMBERS";
@@ -1195,7 +1205,7 @@ Internal.define({
1195
1205
  }
1196
1206
  });
1197
1207
 
1198
- // adapters/discord/src/types/scheduled-event.ts
1208
+ // satori/adapters/discord/src/types/scheduled-event.ts
1199
1209
  var GuildScheduledEvent;
1200
1210
  ((GuildScheduledEvent2) => {
1201
1211
  let PrivacyLevel;
@@ -1231,7 +1241,7 @@ Internal.define({
1231
1241
  }
1232
1242
  });
1233
1243
 
1234
- // adapters/discord/src/types/stage-instance.ts
1244
+ // satori/adapters/discord/src/types/stage-instance.ts
1235
1245
  Internal.define({
1236
1246
  "/stage-instances": {
1237
1247
  POST: "createStageInstance"
@@ -1243,7 +1253,7 @@ Internal.define({
1243
1253
  }
1244
1254
  });
1245
1255
 
1246
- // adapters/discord/src/types/sticker.ts
1256
+ // satori/adapters/discord/src/types/sticker.ts
1247
1257
  var Sticker3;
1248
1258
  ((Sticker4) => {
1249
1259
  let Type;
@@ -1276,14 +1286,14 @@ Internal.define({
1276
1286
  }
1277
1287
  });
1278
1288
 
1279
- // adapters/discord/src/types/team.ts
1289
+ // satori/adapters/discord/src/types/team.ts
1280
1290
  var MembershipState = /* @__PURE__ */ ((MembershipState2) => {
1281
1291
  MembershipState2[MembershipState2["INVITED"] = 1] = "INVITED";
1282
1292
  MembershipState2[MembershipState2["ACCEPTED"] = 2] = "ACCEPTED";
1283
1293
  return MembershipState2;
1284
1294
  })(MembershipState || {});
1285
1295
 
1286
- // adapters/discord/src/types/thread.ts
1296
+ // satori/adapters/discord/src/types/thread.ts
1287
1297
  Internal.define({
1288
1298
  "/guilds/{guild.id}/threads/active": {
1289
1299
  GET: "listActiveGuildThreads"
@@ -1320,7 +1330,7 @@ Internal.define({
1320
1330
  }
1321
1331
  });
1322
1332
 
1323
- // adapters/discord/src/types/user.ts
1333
+ // satori/adapters/discord/src/types/user.ts
1324
1334
  var UserFlag = /* @__PURE__ */ ((UserFlag2) => {
1325
1335
  UserFlag2[UserFlag2["NONE"] = 0] = "NONE";
1326
1336
  UserFlag2[UserFlag2["DISCORD_EMPLOYEE"] = 1] = "DISCORD_EMPLOYEE";
@@ -1356,7 +1366,7 @@ Internal.define({
1356
1366
  }
1357
1367
  });
1358
1368
 
1359
- // adapters/discord/src/types/voice.ts
1369
+ // satori/adapters/discord/src/types/voice.ts
1360
1370
  Internal.define({
1361
1371
  "/voice/regions": {
1362
1372
  GET: "listVoiceRegions"
@@ -1372,7 +1382,7 @@ Internal.define({
1372
1382
  }
1373
1383
  });
1374
1384
 
1375
- // adapters/discord/src/types/webhook.ts
1385
+ // satori/adapters/discord/src/types/webhook.ts
1376
1386
  var Webhook2;
1377
1387
  ((Webhook3) => {
1378
1388
  let Type;
@@ -1414,7 +1424,7 @@ Internal.define({
1414
1424
  }
1415
1425
  });
1416
1426
 
1417
- // adapters/discord/src/ws.ts
1427
+ // satori/adapters/discord/src/ws.ts
1418
1428
  var import_satori3 = require("@satorijs/satori");
1419
1429
  var logger = new import_satori3.Logger("discord");
1420
1430
  var WsClient = class extends import_satori3.Adapter.WsClient {
@@ -1502,7 +1512,7 @@ __name(WsClient, "WsClient");
1502
1512
  ]);
1503
1513
  })(WsClient || (WsClient = {}));
1504
1514
 
1505
- // adapters/discord/src/bot.ts
1515
+ // satori/adapters/discord/src/bot.ts
1506
1516
  var DiscordBot = class extends import_satori4.Bot {
1507
1517
  constructor(ctx, config) {
1508
1518
  super(ctx, config);
@@ -1596,7 +1606,7 @@ __name(DiscordBot, "DiscordBot");
1596
1606
  })(DiscordBot || (DiscordBot = {}));
1597
1607
  DiscordBot.prototype.platform = "discord";
1598
1608
 
1599
- // adapters/discord/src/index.ts
1609
+ // satori/adapters/discord/src/index.ts
1600
1610
  var src_default = DiscordBot;
1601
1611
  // Annotate the CommonJS export names for ESM import in node:
1602
1612
  0 && (module.exports = {