@satorijs/adapter-discord 3.5.5 → 3.5.7

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
@@ -46,7 +46,7 @@ __export(src_exports, {
46
46
  module.exports = __toCommonJS(src_exports);
47
47
 
48
48
  // satori/adapters/discord/src/bot.ts
49
- var import_satori4 = require("@satorijs/satori");
49
+ var import_satori5 = require("@satorijs/satori");
50
50
 
51
51
  // satori/adapters/discord/src/utils.ts
52
52
  var import_satori = require("@satorijs/satori");
@@ -234,11 +234,13 @@ var DiscordMessenger = class extends import_satori2.Messenger {
234
234
  this.errors.push(e);
235
235
  }
236
236
  }
237
- async sendEmbed(buffer, payload, filename) {
238
- const fd = new import_form_data.default();
239
- fd.append("file", buffer, filename);
240
- fd.append("payload_json", JSON.stringify(payload));
241
- return this.post(fd, fd.getHeaders());
237
+ async sendEmbed(attrs, payload) {
238
+ const { filename, data, mime } = await this.bot.ctx.http.file(attrs.url);
239
+ const form = new import_form_data.default();
240
+ const value = process.env.KOISHI_ENV === "browser" ? new Blob([data], { type: mime }) : Buffer.from(data);
241
+ form.append("file", value, attrs.file || filename);
242
+ form.append("payload_json", JSON.stringify(payload));
243
+ return this.post(form, form.getHeaders());
242
244
  }
243
245
  async sendContent(content, addition) {
244
246
  return this.post({ ...addition, content });
@@ -255,10 +257,7 @@ var DiscordMessenger = class extends import_satori2.Messenger {
255
257
  }
256
258
  return this.post({ ...addition, content: attrs.url });
257
259
  }, "sendDirect");
258
- const sendDownload = /* @__PURE__ */ __name(async () => {
259
- const { filename, data } = await this.bot.ctx.http.file(attrs.url);
260
- return this.sendEmbed(data, addition, attrs.file || filename);
261
- }, "sendDownload");
260
+ const sendDownload = /* @__PURE__ */ __name(() => this.sendEmbed(attrs, addition), "sendDownload");
262
261
  if (["file:", "data:", "base64:"].some((prefix) => attrs.url.startsWith(prefix))) {
263
262
  return await sendDownload();
264
263
  }
@@ -448,7 +447,7 @@ __export(types_exports, {
448
447
  });
449
448
 
450
449
  // satori/adapters/discord/src/types/internal.ts
451
- var import_cosmokit = require("cosmokit");
450
+ var import_satori3 = require("@satorijs/satori");
452
451
  var Internal = class {
453
452
  constructor(http) {
454
453
  this.http = http;
@@ -457,7 +456,7 @@ var Internal = class {
457
456
  for (const path in routes) {
458
457
  for (const key in routes[path]) {
459
458
  const method = key;
460
- for (const name of (0, import_cosmokit.makeArray)(routes[path][method])) {
459
+ for (const name of (0, import_satori3.makeArray)(routes[path][method])) {
461
460
  Internal.prototype[name] = function(...args) {
462
461
  const raw = args.join(", ");
463
462
  const url = path.replace(/\{([^}]+)\}/g, () => {
@@ -1487,9 +1486,9 @@ Internal.define({
1487
1486
  });
1488
1487
 
1489
1488
  // satori/adapters/discord/src/ws.ts
1490
- var import_satori3 = require("@satorijs/satori");
1491
- var logger = new import_satori3.Logger("discord");
1492
- var WsClient = class extends import_satori3.Adapter.WsClient {
1489
+ var import_satori4 = require("@satorijs/satori");
1490
+ var logger = new import_satori4.Logger("discord");
1491
+ var WsClient = class extends import_satori4.Adapter.WsClient {
1493
1492
  constructor() {
1494
1493
  super(...arguments);
1495
1494
  this._d = 0;
@@ -1510,7 +1509,7 @@ var WsClient = class extends import_satori3.Adapter.WsClient {
1510
1509
  }));
1511
1510
  }
1512
1511
  accept() {
1513
- this.bot.socket.on("message", async (data) => {
1512
+ this.bot.socket.addEventListener("message", async ({ data }) => {
1514
1513
  var _a, _b;
1515
1514
  let parsed;
1516
1515
  try {
@@ -1578,29 +1577,31 @@ var WsClient = class extends import_satori3.Adapter.WsClient {
1578
1577
  (_b = this.bot.socket) == null ? void 0 : _b.close();
1579
1578
  }
1580
1579
  });
1581
- this.bot.socket.on("close", () => {
1580
+ this.bot.socket.addEventListener("close", () => {
1582
1581
  clearInterval(this._ping);
1583
1582
  });
1584
1583
  }
1585
1584
  };
1586
1585
  __name(WsClient, "WsClient");
1587
1586
  ((WsClient2) => {
1588
- WsClient2.Config = import_satori3.Schema.intersect([
1589
- import_satori3.Schema.object({
1590
- intents: import_satori3.Schema.bitset(GatewayIntent).description("需要订阅的机器人事件。").default(0 | 512 /* GUILD_MESSAGES */ | 1024 /* GUILD_MESSAGE_REACTIONS */ | 4096 /* DIRECT_MESSAGES */ | 8192 /* DIRECT_MESSAGE_REACTIONS */ | 32768 /* MESSAGE_CONTENT */)
1587
+ WsClient2.Config = import_satori4.Schema.intersect([
1588
+ import_satori4.Schema.object({
1589
+ intents: import_satori4.Schema.bitset(GatewayIntent).description("需要订阅的机器人事件。").default(0 | 512 /* GUILD_MESSAGES */ | 1024 /* GUILD_MESSAGE_REACTIONS */ | 4096 /* DIRECT_MESSAGES */ | 8192 /* DIRECT_MESSAGE_REACTIONS */ | 32768 /* MESSAGE_CONTENT */)
1591
1590
  }).description("推送设置"),
1592
- import_satori3.Adapter.WsClient.Config
1591
+ import_satori4.Adapter.WsClient.Config
1593
1592
  ]);
1594
1593
  })(WsClient || (WsClient = {}));
1595
1594
 
1596
1595
  // satori/adapters/discord/src/bot.ts
1597
- var DiscordBot = class extends import_satori4.Bot {
1596
+ var import_package = require("../package.json");
1597
+ var DiscordBot = class extends import_satori5.Bot {
1598
1598
  constructor(ctx, config) {
1599
1599
  super(ctx, config);
1600
1600
  this.http = ctx.http.extend({
1601
1601
  ...config,
1602
1602
  headers: {
1603
1603
  Authorization: `Bot ${config.token}`,
1604
+ "User-Agent": `Koishi (https://koishi.chat/, ${import_package.version})`,
1604
1605
  ...config.headers
1605
1606
  }
1606
1607
  });
@@ -1621,7 +1622,7 @@ var DiscordBot = class extends import_satori4.Bot {
1621
1622
  await this.internal.deleteMessage(channelId, messageId);
1622
1623
  }
1623
1624
  async editMessage(channelId, messageId, content) {
1624
- const elements = import_satori4.segment.normalize(content);
1625
+ const elements = import_satori5.segment.normalize(content);
1625
1626
  content = elements.toString();
1626
1627
  const image = elements.find((v) => v.type === "image");
1627
1628
  if (image) {
@@ -1676,13 +1677,13 @@ var DiscordBot = class extends import_satori4.Bot {
1676
1677
  };
1677
1678
  __name(DiscordBot, "DiscordBot");
1678
1679
  ((DiscordBot2) => {
1679
- DiscordBot2.Config = import_satori4.Schema.intersect([
1680
- import_satori4.Schema.object({
1681
- token: import_satori4.Schema.string().description("机器人的用户令牌。").role("secret").required()
1680
+ DiscordBot2.Config = import_satori5.Schema.intersect([
1681
+ import_satori5.Schema.object({
1682
+ token: import_satori5.Schema.string().description("机器人的用户令牌。").role("secret").required()
1682
1683
  }),
1683
1684
  WsClient.Config,
1684
1685
  DiscordMessenger.Config,
1685
- import_satori4.Quester.createConfig("https://discord.com/api/v10")
1686
+ import_satori5.Quester.createConfig("https://discord.com/api/v10")
1686
1687
  ]);
1687
1688
  })(DiscordBot || (DiscordBot = {}));
1688
1689
  DiscordBot.prototype.platform = "discord";