@satorijs/adapter-discord 3.8.7 → 3.8.9

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
@@ -1215,7 +1215,7 @@ var encodeRole = /* @__PURE__ */ __name((role) => ({
1215
1215
  ...role,
1216
1216
  permissions: role.permissions && "" + role.permissions
1217
1217
  }), "encodeRole");
1218
- async function decodeMessage(bot, meta, session = {}) {
1218
+ async function decodeMessage(bot, meta, session = {}, reference = true) {
1219
1219
  var _a, _b, _c;
1220
1220
  const { platform } = bot;
1221
1221
  session.messageId = meta.id;
@@ -1293,7 +1293,7 @@ async function decodeMessage(bot, meta, session = {}) {
1293
1293
  }
1294
1294
  }
1295
1295
  session.elements = import_satori2.h.parse(session.content);
1296
- if (meta.message_reference) {
1296
+ if (reference && meta.message_reference) {
1297
1297
  const { message_id, channel_id } = meta.message_reference;
1298
1298
  session.quote = await bot.getMessage(channel_id, message_id);
1299
1299
  }
@@ -1575,26 +1575,31 @@ var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3
1575
1575
  }
1576
1576
  return this.post({ ...addition, content: attrs.url });
1577
1577
  }, "sendDirect");
1578
- const sendDownload = /* @__PURE__ */ __name(() => this.sendEmbed(attrs, addition), "sendDownload");
1579
- if (["file:", "data:", "base64:"].some((prefix) => attrs.url.startsWith(prefix))) {
1580
- return await sendDownload();
1578
+ if (this.bot.http.isPrivate(attrs.url)) {
1579
+ return await this.sendEmbed(attrs, addition);
1581
1580
  }
1582
1581
  const mode = attrs.mode || handleExternalAsset;
1583
1582
  if (mode === "download" || handleMixedContent === "attach" && addition.content || type === "file") {
1584
- return sendDownload();
1583
+ return this.sendEmbed(attrs, addition);
1585
1584
  } else if (mode === "direct") {
1586
1585
  return sendDirect();
1587
1586
  }
1588
- return await this.bot.ctx.http.head(attrs.url, {
1587
+ if (await this.checkMediaType(attrs.url, type)) {
1588
+ return sendDirect();
1589
+ } else {
1590
+ return this.sendEmbed(attrs, addition);
1591
+ }
1592
+ }
1593
+ checkMediaType(url, type) {
1594
+ if (url.startsWith("https://cdn.discordapp.com/"))
1595
+ return true;
1596
+ return this.bot.ctx.http.head(url, {
1589
1597
  headers: { accept: type + "/*" },
1590
- timeout: +attrs.timeout || void 0
1591
- }).then((headers) => {
1592
- if (headers["content-type"].startsWith(type)) {
1593
- return sendDirect();
1594
- } else {
1595
- return sendDownload();
1596
- }
1597
- }, sendDownload);
1598
+ timeout: 1e3
1599
+ }).then(
1600
+ (headers) => headers["content-type"].startsWith(type),
1601
+ () => false
1602
+ );
1598
1603
  }
1599
1604
  async ensureWebhook() {
1600
1605
  return this.bot.ensureWebhook(this.channelId);
@@ -1988,7 +1993,7 @@ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
1988
1993
  }
1989
1994
  async getMessageList(channelId, before) {
1990
1995
  const data = (await this.internal.getChannelMessages(channelId, { before, limit: 50 })).reverse();
1991
- return await Promise.all(data.map((data2) => decodeMessage(this, data2)));
1996
+ return await Promise.all(data.map((data2) => decodeMessage(this, data2, {}, false)));
1992
1997
  }
1993
1998
  async getUser(userId) {
1994
1999
  const data = await this.internal.getUser(userId);