@satorijs/adapter-discord 3.8.6 → 3.8.8

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
@@ -1412,11 +1412,19 @@ var types = {
1412
1412
  channel: ApplicationCommand2.OptionType.STRING,
1413
1413
  guild: ApplicationCommand2.OptionType.STRING
1414
1414
  };
1415
+ var trimDescription = /* @__PURE__ */ __name((source) => {
1416
+ if (!source || source.length < 96)
1417
+ return source;
1418
+ return source.slice(0, 93) + "...";
1419
+ }, "trimDescription");
1420
+ var encodeDescription = /* @__PURE__ */ __name((object) => ({
1421
+ description: trimDescription(object.description[""] || object.name),
1422
+ description_localizations: (0, import_satori2.valueMap)((0, import_satori2.pick)(object.description, Locale3), trimDescription)
1423
+ }), "encodeDescription");
1415
1424
  var encodeCommand = /* @__PURE__ */ __name((cmd) => ({
1425
+ ...encodeDescription(cmd),
1416
1426
  name: cmd.name,
1417
1427
  type: ApplicationCommand2.Type.CHAT_INPUT,
1418
- description: cmd.description[""] || cmd.name,
1419
- description_localizations: (0, import_satori2.pick)(cmd.description, Locale3),
1420
1428
  options: encodeCommandOptions(cmd)
1421
1429
  }), "encodeCommand");
1422
1430
  var decodeArgv = /* @__PURE__ */ __name((data, command) => {
@@ -1448,18 +1456,16 @@ function encodeCommandOptions(cmd) {
1448
1456
  } else {
1449
1457
  for (const arg of cmd.arguments) {
1450
1458
  result.push({
1459
+ ...encodeDescription(arg),
1451
1460
  name: arg.name.toLowerCase().replace(/[^a-z0-9]/g, ""),
1452
- description: arg.description[""] || arg.name,
1453
- description_localizations: (0, import_satori2.pick)(arg.description, Locale3),
1454
1461
  type: (_a = types[arg.type]) != null ? _a : types.text
1455
1462
  // required: arg.required ?? false,
1456
1463
  });
1457
1464
  }
1458
1465
  for (const option of cmd.options) {
1459
1466
  result.push({
1467
+ ...encodeDescription(option),
1460
1468
  name: option.name.toLowerCase(),
1461
- description: option.description[""] || option.name,
1462
- description_localizations: (0, import_satori2.pick)(option.description, Locale3),
1463
1469
  type: (_b = types[option.type]) != null ? _b : types.text,
1464
1470
  // required: option.required ?? false,
1465
1471
  min_value: option.type === "posint" ? 1 : void 0
@@ -1569,26 +1575,31 @@ var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3
1569
1575
  }
1570
1576
  return this.post({ ...addition, content: attrs.url });
1571
1577
  }, "sendDirect");
1572
- const sendDownload = /* @__PURE__ */ __name(() => this.sendEmbed(attrs, addition), "sendDownload");
1573
- if (["file:", "data:", "base64:"].some((prefix) => attrs.url.startsWith(prefix))) {
1574
- return await sendDownload();
1578
+ if (this.bot.http.isPrivate(attrs.url)) {
1579
+ return await this.sendEmbed(attrs, addition);
1575
1580
  }
1576
1581
  const mode = attrs.mode || handleExternalAsset;
1577
1582
  if (mode === "download" || handleMixedContent === "attach" && addition.content || type === "file") {
1578
- return sendDownload();
1583
+ return this.sendEmbed(attrs, addition);
1579
1584
  } else if (mode === "direct") {
1580
1585
  return sendDirect();
1581
1586
  }
1582
- 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, {
1583
1597
  headers: { accept: type + "/*" },
1584
- timeout: +attrs.timeout || void 0
1585
- }).then((headers) => {
1586
- if (headers["content-type"].startsWith(type)) {
1587
- return sendDirect();
1588
- } else {
1589
- return sendDownload();
1590
- }
1591
- }, sendDownload);
1598
+ timeout: 1e3
1599
+ }).then(
1600
+ (headers) => headers["content-type"].startsWith(type),
1601
+ () => false
1602
+ );
1592
1603
  }
1593
1604
  async ensureWebhook() {
1594
1605
  return this.bot.ensureWebhook(this.channelId);