@satorijs/adapter-discord 3.8.2 → 3.8.4

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/bot.d.ts CHANGED
@@ -11,7 +11,7 @@ export declare class DiscordBot extends Bot<DiscordBot.Config> {
11
11
  webhookLock: Record<string, Promise<Webhook>>;
12
12
  commands: Universal.Command[];
13
13
  constructor(ctx: Context, config: DiscordBot.Config);
14
- session(payload?: {}): import("@satorijs/core").Session;
14
+ session(payload?: any, input?: any): import("@satorijs/core").Session;
15
15
  private _ensureWebhook;
16
16
  ensureWebhook(channelId: string): Promise<Discord.Webhook>;
17
17
  getSelf(): Promise<Universal.User>;
@@ -41,7 +41,7 @@ export declare class DiscordBot extends Bot<DiscordBot.Config> {
41
41
  setGuildMemberRole(guildId: string, userId: string, roleId: string): Promise<void>;
42
42
  unsetGuildMemberRole(guildId: string, userId: string, roleId: string): Promise<void>;
43
43
  getGuildRoles(guildId: string): Promise<Universal.Role[]>;
44
- createGuildRole(guildId: string, data: Partial<Universal.Role>): Promise<Universal.Role>;
44
+ createGuildRole(guildId: string, data: Partial<Universal.Role>): Promise<string>;
45
45
  modifyGuildRole(guildId: string, roleId: string, data: Partial<Universal.Role>): Promise<void>;
46
46
  deleteGuildRole(guildId: string, roleId: string): Promise<void>;
47
47
  sendPrivateMessage(userId: string, content: Fragment, options?: SendOptions): Promise<string[]>;
package/lib/index.js CHANGED
@@ -95,7 +95,7 @@ var import_satori2 = require("@satorijs/satori");
95
95
 
96
96
  // satori/adapters/discord/src/types/internal.ts
97
97
  var import_satori = require("@satorijs/satori");
98
- var Internal = class {
98
+ var _Internal = class _Internal {
99
99
  constructor(http) {
100
100
  this.http = http;
101
101
  }
@@ -104,7 +104,7 @@ var Internal = class {
104
104
  for (const key in routes[path]) {
105
105
  const method = key;
106
106
  for (const name of (0, import_satori.makeArray)(routes[path][method])) {
107
- Internal.prototype[name] = async function(...args) {
107
+ _Internal.prototype[name] = async function(...args) {
108
108
  const raw = args.join(", ");
109
109
  const url = path.replace(/\{([^}]+)\}/g, () => {
110
110
  if (!args.length)
@@ -137,7 +137,8 @@ var Internal = class {
137
137
  }
138
138
  }
139
139
  };
140
- __name(Internal, "Internal");
140
+ __name(_Internal, "Internal");
141
+ var Internal = _Internal;
141
142
 
142
143
  // satori/adapters/discord/src/types/application.ts
143
144
  var ApplicationFlag = /* @__PURE__ */ ((ApplicationFlag2) => {
@@ -1314,7 +1315,7 @@ function setupReaction(session, data) {
1314
1315
  }
1315
1316
  __name(setupReaction, "setupReaction");
1316
1317
  async function adaptSession(bot, input) {
1317
- const session = bot.session();
1318
+ const session = bot.session({}, input);
1318
1319
  if (input.t === "MESSAGE_CREATE") {
1319
1320
  if (input.d.webhook_id) {
1320
1321
  const webhook = await bot.ensureWebhook(input.d.channel_id);
@@ -1466,7 +1467,7 @@ __name(encodeCommandOptions, "encodeCommandOptions");
1466
1467
  var import_satori3 = require("@satorijs/satori");
1467
1468
  var import_form_data = __toESM(require("form-data"));
1468
1469
  var logger = new import_satori3.Logger("discord");
1469
- var State = class {
1470
+ var _State = class _State {
1470
1471
  // forward: send the first message and create a thread
1471
1472
  constructor(type) {
1472
1473
  this.type = type;
@@ -1478,8 +1479,9 @@ var State = class {
1478
1479
  this.threadCreated = false;
1479
1480
  }
1480
1481
  };
1481
- __name(State, "State");
1482
- var DiscordMessageEncoder = class extends import_satori3.MessageEncoder {
1482
+ __name(_State, "State");
1483
+ var State = _State;
1484
+ var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3.MessageEncoder {
1483
1485
  constructor() {
1484
1486
  super(...arguments);
1485
1487
  this.stack = [new State("message")];
@@ -1487,6 +1489,7 @@ var DiscordMessageEncoder = class extends import_satori3.MessageEncoder {
1487
1489
  this.addition = {};
1488
1490
  this.figure = null;
1489
1491
  this.mode = "default";
1492
+ this.listType = null;
1490
1493
  }
1491
1494
  async getUrl() {
1492
1495
  var _a, _b, _c, _d;
@@ -1631,8 +1634,30 @@ var DiscordMessageEncoder = class extends import_satori3.MessageEncoder {
1631
1634
  this.buffer += ` (<${attrs.href}>) `;
1632
1635
  }
1633
1636
  } else if (type === "p") {
1637
+ if (!this.buffer.endsWith("\n"))
1638
+ this.buffer += "\n";
1639
+ await this.render(children);
1640
+ this.buffer += "\n";
1641
+ } else if (type === "blockquote") {
1642
+ if (!this.buffer.endsWith("\n"))
1643
+ this.buffer += "\n";
1644
+ this.buffer += "> ";
1634
1645
  await this.render(children);
1635
1646
  this.buffer += "\n";
1647
+ } else if (type === "ul" || type === "ol") {
1648
+ this.listType = type;
1649
+ await this.render(children);
1650
+ this.listType = null;
1651
+ } else if (type === "li") {
1652
+ if (!this.buffer.endsWith("\n"))
1653
+ this.buffer += "\n";
1654
+ if (this.listType === "ol") {
1655
+ this.buffer += "0. ";
1656
+ } else if (this.listType === "ul") {
1657
+ this.buffer += "- ";
1658
+ }
1659
+ this.render(children);
1660
+ this.buffer += "\n";
1636
1661
  } else if (type === "at") {
1637
1662
  if (attrs.id) {
1638
1663
  this.buffer += `<@${attrs.id}>`;
@@ -1755,7 +1780,8 @@ var DiscordMessageEncoder = class extends import_satori3.MessageEncoder {
1755
1780
  }
1756
1781
  }
1757
1782
  };
1758
- __name(DiscordMessageEncoder, "DiscordMessageEncoder");
1783
+ __name(_DiscordMessageEncoder, "DiscordMessageEncoder");
1784
+ var DiscordMessageEncoder = _DiscordMessageEncoder;
1759
1785
  ((DiscordMessageEncoder2) => {
1760
1786
  DiscordMessageEncoder2.Config = import_satori3.Schema.object({
1761
1787
  handleExternalAsset: import_satori3.Schema.union([
@@ -1774,7 +1800,7 @@ __name(DiscordMessageEncoder, "DiscordMessageEncoder");
1774
1800
  // satori/adapters/discord/src/ws.ts
1775
1801
  var import_satori4 = require("@satorijs/satori");
1776
1802
  var logger2 = new import_satori4.Logger("discord");
1777
- var WsClient = class extends import_satori4.Adapter.WsClient {
1803
+ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
1778
1804
  constructor() {
1779
1805
  super(...arguments);
1780
1806
  this._d = 0;
@@ -1869,7 +1895,8 @@ var WsClient = class extends import_satori4.Adapter.WsClient {
1869
1895
  });
1870
1896
  }
1871
1897
  };
1872
- __name(WsClient, "WsClient");
1898
+ __name(_WsClient, "WsClient");
1899
+ var WsClient = _WsClient;
1873
1900
  ((WsClient2) => {
1874
1901
  WsClient2.Config = import_satori4.Schema.intersect([
1875
1902
  import_satori4.Schema.object({
@@ -1882,7 +1909,7 @@ __name(WsClient, "WsClient");
1882
1909
  // satori/adapters/discord/src/bot.ts
1883
1910
  var import_package = require("../package.json");
1884
1911
  var logger3 = new import_satori5.Logger("discord");
1885
- var DiscordBot = class extends import_satori5.Bot {
1912
+ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
1886
1913
  constructor(ctx, config) {
1887
1914
  super(ctx, config);
1888
1915
  this.webhooks = {};
@@ -1899,8 +1926,8 @@ var DiscordBot = class extends import_satori5.Bot {
1899
1926
  this.internal = new Internal(this.http);
1900
1927
  ctx.plugin(WsClient, this);
1901
1928
  }
1902
- session(payload = {}) {
1903
- return (0, import_satori5.defineProperty)(super.session(), "discord", Object.assign(Object.create(this.internal), payload));
1929
+ session(payload, input) {
1930
+ return (0, import_satori5.defineProperty)(super.session(payload), "discord", Object.assign(Object.create(this.internal), input));
1904
1931
  }
1905
1932
  async _ensureWebhook(channelId) {
1906
1933
  let webhook;
@@ -2020,7 +2047,7 @@ var DiscordBot = class extends import_satori5.Bot {
2020
2047
  }
2021
2048
  async createGuildRole(guildId, data) {
2022
2049
  const role = await this.internal.createGuildRole(guildId, encodeRole(data));
2023
- return decodeRole(role);
2050
+ return role.id;
2024
2051
  }
2025
2052
  async modifyGuildRole(guildId, roleId, data) {
2026
2053
  await this.internal.modifyGuildRole(guildId, roleId, encodeRole(data));
@@ -2056,8 +2083,9 @@ var DiscordBot = class extends import_satori5.Bot {
2056
2083
  }
2057
2084
  }
2058
2085
  };
2059
- __name(DiscordBot, "DiscordBot");
2060
- DiscordBot.MessageEncoder = DiscordMessageEncoder;
2086
+ __name(_DiscordBot, "DiscordBot");
2087
+ _DiscordBot.MessageEncoder = DiscordMessageEncoder;
2088
+ var DiscordBot = _DiscordBot;
2061
2089
  function shapeEqual(a, b, strict = false) {
2062
2090
  if (a === b)
2063
2091
  return true;