@satorijs/adapter-discord 4.0.1 → 4.0.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/bot.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Bot, Context, Fragment, Quester, Schema, SendOptions, Universal } from '@satorijs/satori';
1
+ import { Bot, Context, Fragment, Quester, Schema, Universal } from '@satorijs/satori';
2
2
  import * as Discord from './utils';
3
3
  import { DiscordMessageEncoder } from './message';
4
4
  import { Internal, Webhook } from './types';
@@ -11,10 +11,9 @@ 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?: any, input?: any): import("@satorijs/core").Session;
15
14
  private _ensureWebhook;
16
15
  ensureWebhook(channelId: string): Promise<Discord.Webhook>;
17
- getSelf(): Promise<Universal.User>;
16
+ getLogin(): Promise<Universal.Login>;
18
17
  deleteMessage(channelId: string, messageId: string): Promise<void>;
19
18
  editMessage(channelId: string, messageId: string, content: Fragment): Promise<void>;
20
19
  getMessage(channelId: string, messageId: string): Promise<Universal.Message>;
@@ -50,14 +49,14 @@ export declare class DiscordBot extends Bot<DiscordBot.Config> {
50
49
  getGuildRoleList(guildId: string): Promise<{
51
50
  data: Universal.GuildRole[];
52
51
  }>;
53
- createGuildRole(guildId: string, data: Partial<Universal.GuildRole>): Promise<string>;
54
- modifyGuildRole(guildId: string, roleId: string, data: Partial<Universal.GuildRole>): Promise<void>;
52
+ createGuildRole(guildId: string, data: Partial<Universal.GuildRole>): Promise<Universal.GuildRole>;
53
+ updateGuildRole(guildId: string, roleId: string, data: Partial<Universal.GuildRole>): Promise<void>;
55
54
  deleteGuildRole(guildId: string, roleId: string): Promise<void>;
56
- sendPrivateMessage(userId: string, content: Fragment, options?: SendOptions): Promise<string[]>;
55
+ createDirectChannel(userId: string): Promise<Universal.Channel>;
57
56
  updateCommands(commands: Universal.Command[]): Promise<void>;
58
57
  }
59
58
  export declare namespace DiscordBot {
60
- interface Config extends Bot.Config, Quester.Config, DiscordMessageEncoder.Config, WsClient.Config {
59
+ interface Config extends Quester.Config, DiscordMessageEncoder.Config, WsClient.Config {
61
60
  token: string;
62
61
  slash?: boolean;
63
62
  }
package/lib/index.js CHANGED
@@ -84,7 +84,6 @@ __export(utils_exports, {
84
84
  VisibilityType: () => VisibilityType,
85
85
  Webhook: () => Webhook2,
86
86
  adaptSession: () => adaptSession,
87
- decodeAuthor: () => decodeAuthor,
88
87
  decodeChannel: () => decodeChannel,
89
88
  decodeGuild: () => decodeGuild,
90
89
  decodeGuildMember: () => decodeGuildMember,
@@ -1193,17 +1192,16 @@ var decodeUser = /* @__PURE__ */ __name((user) => ({
1193
1192
  id: user.id,
1194
1193
  name: user.username,
1195
1194
  userId: user.id,
1196
- avatar: `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`,
1195
+ avatar: user.avatar && `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`,
1197
1196
  username: user.username,
1198
1197
  discriminator: user.discriminator,
1199
1198
  isBot: user.bot || false
1200
1199
  }), "decodeUser");
1201
1200
  var decodeGuildMember = /* @__PURE__ */ __name((member) => ({
1202
- ...decodeUser(member.user),
1203
- user: decodeUser(member.user),
1204
- nickname: member.nick,
1201
+ user: member.user && decodeUser(member.user),
1202
+ name: member.nick,
1205
1203
  roles: member.roles,
1206
- avatar: member.user.avatar
1204
+ joinedAt: member.joined_at && new Date(member.joined_at).valueOf()
1207
1205
  }), "decodeGuildMember");
1208
1206
  var decodeGuild = /* @__PURE__ */ __name((data) => ({
1209
1207
  id: data.id,
@@ -1211,12 +1209,9 @@ var decodeGuild = /* @__PURE__ */ __name((data) => ({
1211
1209
  }), "decodeGuild");
1212
1210
  var decodeChannel = /* @__PURE__ */ __name((data) => ({
1213
1211
  id: data.id,
1214
- name: data.name
1212
+ name: data.name,
1213
+ type: data.type === Channel2.Type.DM ? import_satori2.Universal.Channel.Type.DIRECT : import_satori2.Universal.Channel.Type.TEXT
1215
1214
  }), "decodeChannel");
1216
- var decodeAuthor = /* @__PURE__ */ __name((author) => ({
1217
- ...decodeUser(author),
1218
- nickname: author.username
1219
- }), "decodeAuthor");
1220
1215
  var decodeRole = /* @__PURE__ */ __name((role) => ({
1221
1216
  ...role,
1222
1217
  permissions: BigInt(role.permissions)
@@ -1225,27 +1220,18 @@ var encodeRole = /* @__PURE__ */ __name((role) => ({
1225
1220
  ...role,
1226
1221
  permissions: role.permissions && "" + role.permissions
1227
1222
  }), "encodeRole");
1228
- async function decodeMessage(bot, meta, session = {}, reference = true) {
1229
- var _a, _b, _c;
1223
+ async function decodeMessage(bot, data, message, payload = message, details = true) {
1224
+ var _a;
1230
1225
  const { platform } = bot;
1231
- session.messageId = meta.id;
1232
- session.channelId = meta.channel_id;
1233
- session.timestamp = new Date(meta.timestamp).valueOf() || Date.now();
1234
- if (meta.author) {
1235
- session.author = decodeAuthor(meta.author);
1236
- session.userId = meta.author.id;
1237
- }
1238
- if ((_a = meta.member) == null ? void 0 : _a.nick) {
1239
- session.author.nickname = (_b = meta.member) == null ? void 0 : _b.nick;
1240
- }
1241
- session.content = "";
1242
- if (meta.content) {
1243
- session.content = meta.content.replace(/<@[!&]?(.+?)>/g, (_, id) => {
1226
+ message.id = message.messageId = data.id;
1227
+ message.content = "";
1228
+ if (data.content) {
1229
+ message.content = data.content.replace(/<@[!&]?(.+?)>/g, (_, id) => {
1244
1230
  var _a2;
1245
- if (meta.mention_roles.includes(id)) {
1231
+ if (data.mention_roles.includes(id)) {
1246
1232
  return (0, import_satori2.h)("at", { role: id }).toString();
1247
1233
  } else {
1248
- const user = (_a2 = meta.mentions) == null ? void 0 : _a2.find((u) => u.id === id || `${u.username}#${u.discriminator}` === id);
1234
+ const user = (_a2 = data.mentions) == null ? void 0 : _a2.find((u) => u.id === id || `${u.username}#${u.discriminator}` === id);
1249
1235
  return import_satori2.h.at(id, { name: user == null ? void 0 : user.username }).toString();
1250
1236
  }
1251
1237
  }).replace(/<a?:(.*):(.+?)>/g, (_, name, id) => {
@@ -1255,28 +1241,28 @@ async function decodeMessage(bot, meta, session = {}, reference = true) {
1255
1241
  ]).toString();
1256
1242
  }).replace(/@everyone/g, () => (0, import_satori2.h)("at", { type: "all" }).toString()).replace(/@here/g, () => (0, import_satori2.h)("at", { type: "here" }).toString()).replace(/<#(.+?)>/g, (_, id) => {
1257
1243
  var _a2;
1258
- const channel = (_a2 = meta.mention_channels) == null ? void 0 : _a2.find((c) => c.id === id);
1244
+ const channel = (_a2 = data.mention_channels) == null ? void 0 : _a2.find((c) => c.id === id);
1259
1245
  return import_satori2.h.sharp(id, { name: channel == null ? void 0 : channel.name }).toString();
1260
1246
  });
1261
1247
  }
1262
- if ((_c = meta.attachments) == null ? void 0 : _c.length) {
1263
- if (session.content)
1264
- session.content += " ";
1265
- session.content += meta.attachments.map((v) => {
1266
- var _a2, _b2, _c2;
1248
+ if ((_a = data.attachments) == null ? void 0 : _a.length) {
1249
+ if (message.content)
1250
+ message.content += " ";
1251
+ message.content += data.attachments.map((v) => {
1252
+ var _a2, _b, _c;
1267
1253
  if (v.height && v.width && ((_a2 = v.content_type) == null ? void 0 : _a2.startsWith("image/"))) {
1268
1254
  return (0, import_satori2.h)("image", {
1269
1255
  url: v.url,
1270
1256
  proxy_url: v.proxy_url,
1271
1257
  file: v.filename
1272
1258
  });
1273
- } else if (v.height && v.width && ((_b2 = v.content_type) == null ? void 0 : _b2.startsWith("video/"))) {
1259
+ } else if (v.height && v.width && ((_b = v.content_type) == null ? void 0 : _b.startsWith("video/"))) {
1274
1260
  return (0, import_satori2.h)("video", {
1275
1261
  url: v.url,
1276
1262
  proxy_url: v.proxy_url,
1277
1263
  file: v.filename
1278
1264
  });
1279
- } else if ((_c2 = v.content_type) == null ? void 0 : _c2.startsWith("audio/")) {
1265
+ } else if ((_c = v.content_type) == null ? void 0 : _c.startsWith("audio/")) {
1280
1266
  return (0, import_satori2.h)("record", {
1281
1267
  url: v.url,
1282
1268
  proxy_url: v.proxy_url,
@@ -1291,23 +1277,32 @@ async function decodeMessage(bot, meta, session = {}, reference = true) {
1291
1277
  }
1292
1278
  }).join("");
1293
1279
  }
1294
- for (const embed of meta.embeds) {
1280
+ for (const embed of data.embeds) {
1295
1281
  if (embed.image) {
1296
- session.content += (0, import_satori2.h)("image", { url: embed.image.url, proxy_url: embed.image.proxy_url });
1282
+ message.content += (0, import_satori2.h)("image", { url: embed.image.url, proxy_url: embed.image.proxy_url });
1297
1283
  }
1298
1284
  if (embed.thumbnail) {
1299
- session.content += (0, import_satori2.h)("image", { url: embed.thumbnail.url, proxy_url: embed.thumbnail.proxy_url });
1285
+ message.content += (0, import_satori2.h)("image", { url: embed.thumbnail.url, proxy_url: embed.thumbnail.proxy_url });
1300
1286
  }
1301
1287
  if (embed.video) {
1302
- session.content += (0, import_satori2.h)("video", { url: embed.video.url, proxy_url: embed.video.proxy_url });
1288
+ message.content += (0, import_satori2.h)("video", { url: embed.video.url, proxy_url: embed.video.proxy_url });
1303
1289
  }
1304
1290
  }
1305
- session.elements = import_satori2.h.parse(session.content);
1306
- if (reference && meta.message_reference) {
1307
- const { message_id, channel_id } = meta.message_reference;
1308
- session.quote = await bot.getMessage(channel_id, message_id);
1309
- }
1310
- return session;
1291
+ message.elements = import_satori2.h.parse(message.content);
1292
+ if (details && data.message_reference) {
1293
+ const { message_id, channel_id } = data.message_reference;
1294
+ message.quote = await bot.getMessage(channel_id, message_id);
1295
+ }
1296
+ if (!payload)
1297
+ return message;
1298
+ payload.channel = {
1299
+ id: data.channel_id,
1300
+ type: data.member ? import_satori2.Universal.Channel.Type.TEXT : import_satori2.Universal.Channel.Type.DIRECT
1301
+ };
1302
+ payload.user = decodeUser(data.author);
1303
+ payload.member = data.member && decodeGuildMember(data.member);
1304
+ payload.timestamp = new Date(data.timestamp).valueOf() || Date.now();
1305
+ return message;
1311
1306
  }
1312
1307
  __name(decodeMessage, "decodeMessage");
1313
1308
  function setupMessageGuildId(session, guildId) {
@@ -1330,7 +1325,8 @@ function setupReaction(session, data) {
1330
1325
  }
1331
1326
  __name(setupReaction, "setupReaction");
1332
1327
  async function adaptSession(bot, input) {
1333
- const session = bot.session({}, input);
1328
+ const session = bot.session();
1329
+ session.setInternal("discord", input);
1334
1330
  if (input.t === "MESSAGE_CREATE") {
1335
1331
  setupMessageGuildId(session, input.d.guild_id);
1336
1332
  if (input.d.webhook_id && !session.isDirect) {
@@ -1342,11 +1338,11 @@ async function adaptSession(bot, input) {
1342
1338
  }
1343
1339
  }
1344
1340
  session.type = "message";
1345
- await decodeMessage(bot, input.d, session);
1341
+ await decodeMessage(bot, input.d, session.event.message = {}, session.event);
1346
1342
  } else if (input.t === "MESSAGE_UPDATE") {
1347
1343
  session.type = "message-updated";
1348
1344
  const message = await bot.internal.getChannelMessage(input.d.channel_id, input.d.id);
1349
- await decodeMessage(bot, message, session);
1345
+ await decodeMessage(bot, message, session.event.message = {}, session.event);
1350
1346
  const channel = await bot.internal.getChannel(input.d.channel_id);
1351
1347
  setupMessageGuildId(session, channel.guild_id);
1352
1348
  } else if (input.t === "MESSAGE_DELETE") {
@@ -1373,12 +1369,12 @@ async function adaptSession(bot, input) {
1373
1369
  session.type = "guild-role-added";
1374
1370
  session.guildId = input.d.guild_id;
1375
1371
  session.roleId = input.d.role.id;
1376
- session.data.role = decodeRole(input.d.role);
1372
+ session.event.role = decodeRole(input.d.role);
1377
1373
  } else if (input.t === "GUILD_ROLE_UPDATE") {
1378
1374
  session.type = "guild-role-updated";
1379
1375
  session.guildId = input.d.guild_id;
1380
1376
  session.roleId = input.d.role.id;
1381
- session.data.role = decodeRole(input.d.role);
1377
+ session.event.role = decodeRole(input.d.role);
1382
1378
  } else if (input.t === "GUILD_ROLE_DELETE") {
1383
1379
  session.type = "guild-role-added";
1384
1380
  session.guildId = input.d.guild_id;
@@ -1399,7 +1395,7 @@ async function adaptSession(bot, input) {
1399
1395
  session.userId = session.isDirect ? input.d.user.id : input.d.member.user.id;
1400
1396
  session.messageId = input.d.id;
1401
1397
  session.content = "";
1402
- session.data.argv = decodeArgv(data, command);
1398
+ session.event.argv = decodeArgv(data, command);
1403
1399
  } else if (input.t === "CHANNEL_UPDATE") {
1404
1400
  session.type = "channel-updated";
1405
1401
  session.guildId = input.d.guild_id;
@@ -1517,14 +1513,14 @@ var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3
1517
1513
  if ((input == null ? void 0 : input.t) === "INTERACTION_CREATE") {
1518
1514
  return `/webhooks/${input.d.application_id}/${input.d.token}`;
1519
1515
  } else if (this.stack[0].type === "forward" && ((_c = this.stack[0].channel) == null ? void 0 : _c.id)) {
1520
- if (this.stack[1].author.nickname || this.stack[1].author.avatar) {
1516
+ if (this.stack[1].author.name || this.stack[1].author.avatar) {
1521
1517
  const webhook = await this.ensureWebhook();
1522
1518
  return `/webhooks/${webhook.id}/${webhook.token}?wait=true&thread_id=${(_d = this.stack[0].channel) == null ? void 0 : _d.id}`;
1523
1519
  } else {
1524
1520
  return `/channels/${this.stack[0].channel.id}/messages`;
1525
1521
  }
1526
1522
  } else {
1527
- if (this.stack[0].author.nickname || this.stack[0].author.avatar || this.stack[0].type === "forward" && !this.stack[0].threadCreated) {
1523
+ if (this.stack[0].author.name || this.stack[0].author.avatar || this.stack[0].type === "forward" && !this.stack[0].threadCreated) {
1528
1524
  const webhook = await this.ensureWebhook();
1529
1525
  return `/webhooks/${webhook.id}/${webhook.token}?wait=true`;
1530
1526
  } else {
@@ -1538,9 +1534,13 @@ var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3
1538
1534
  const url = await this.getUrl();
1539
1535
  const result = await this.bot.http.post(url, data, { headers });
1540
1536
  const session = this.bot.session();
1541
- const message = await decodeMessage(this.bot, result, session);
1537
+ const message = await decodeMessage(this.bot, result, session.event.message = {}, session.event);
1542
1538
  session.app.emit(session, "send", session);
1543
- this.results.push(session);
1539
+ this.results.push(session.event.message);
1540
+ Object.defineProperty(session.event.message, "channel", {
1541
+ configurable: true,
1542
+ get: () => session.event.channel
1543
+ });
1544
1544
  if (this.stack[0].type === "forward" && !this.stack[0].threadCreated) {
1545
1545
  this.stack[0].threadCreated = true;
1546
1546
  const thread = await this.bot.internal.startThreadFromMessage(this.channelId, result.id, {
@@ -1741,7 +1741,7 @@ var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3
1741
1741
  await this.flush();
1742
1742
  const parse = /* @__PURE__ */ __name((val) => val.replace(/\\([\\*_`~|()\[\]])/g, "$1"), "parse");
1743
1743
  const message = this.stack[this.stack[0].type === "forward" ? 1 : 0];
1744
- if (!message.author.avatar && !message.author.nickname && this.stack[0].type !== "forward") {
1744
+ if (!message.author.avatar && !message.author.name && this.stack[0].type !== "forward") {
1745
1745
  await this.flush();
1746
1746
  this.addition.message_reference = {
1747
1747
  message_id: attrs.id
@@ -1749,18 +1749,18 @@ var _DiscordMessageEncoder = class _DiscordMessageEncoder extends import_satori3
1749
1749
  } else {
1750
1750
  let replyId = attrs.id, channelId = this.channelId;
1751
1751
  if (this.stack[0].type === "forward" && ((_a = this.stack[0].fakeMessageMap[attrs.id]) == null ? void 0 : _a.length) >= 1) {
1752
- replyId = this.stack[0].fakeMessageMap[attrs.id][0].messageId;
1753
- channelId = this.stack[0].fakeMessageMap[attrs.id][0].channelId;
1752
+ replyId = this.stack[0].fakeMessageMap[attrs.id][0].id;
1753
+ channelId = this.stack[0].fakeMessageMap[attrs.id][0].channel.id;
1754
1754
  }
1755
- const quoted = await this.bot.getMessage(channelId, replyId);
1755
+ const quote = await this.bot.getMessage(channelId, replyId);
1756
1756
  this.addition.embeds = [{
1757
1757
  description: [
1758
- sanitize(parse(quoted.elements.filter((v) => v.type === "text").join("")).slice(0, 30)),
1759
- `<t:${Math.ceil(quoted.timestamp / 1e3)}:R> [[ ↑ ]](https://discord.com/channels/${this.guildId}/${channelId}/${replyId})`
1758
+ sanitize(parse(quote.elements.filter((v) => v.type === "text").join("")).slice(0, 30)),
1759
+ `<t:${Math.ceil(quote.timestamp / 1e3)}:R> [[ ↑ ]](https://discord.com/channels/${this.guildId}/${channelId}/${replyId})`
1760
1760
  ].join("\n\n"),
1761
1761
  author: {
1762
- name: quoted.author.nickname || quoted.author.username,
1763
- icon_url: quoted.author.avatar
1762
+ name: quote.user.name,
1763
+ icon_url: quote.user.avatar
1764
1764
  }
1765
1765
  }];
1766
1766
  }
@@ -1843,13 +1843,13 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
1843
1843
  }
1844
1844
  heartbeat() {
1845
1845
  logger2.debug(`heartbeat d ${this._d}`);
1846
- this.bot.socket.send(JSON.stringify({
1846
+ this.socket.send(JSON.stringify({
1847
1847
  op: Gateway.Opcode.HEARTBEAT,
1848
1848
  d: this._d
1849
1849
  }));
1850
1850
  }
1851
1851
  accept() {
1852
- this.bot.socket.addEventListener("message", async ({ data }) => {
1852
+ this.socket.addEventListener("message", async ({ data }) => {
1853
1853
  var _a, _b;
1854
1854
  let parsed;
1855
1855
  try {
@@ -1865,7 +1865,7 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
1865
1865
  this._ping = setInterval(() => this.heartbeat(), parsed.d.heartbeat_interval);
1866
1866
  if (this._sessionId) {
1867
1867
  logger2.debug("resuming");
1868
- this.bot.socket.send(JSON.stringify({
1868
+ this.socket.send(JSON.stringify({
1869
1869
  op: Gateway.Opcode.RESUME,
1870
1870
  d: {
1871
1871
  token: this.bot.config.token,
@@ -1874,7 +1874,7 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
1874
1874
  }
1875
1875
  }));
1876
1876
  } else {
1877
- this.bot.socket.send(JSON.stringify({
1877
+ this.socket.send(JSON.stringify({
1878
1878
  op: Gateway.Opcode.IDENTIFY,
1879
1879
  d: {
1880
1880
  token: this.bot.config.token,
@@ -1890,15 +1890,18 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
1890
1890
  return;
1891
1891
  this._sessionId = "";
1892
1892
  logger2.warn("offline: invalid session");
1893
- (_a = this.bot.socket) == null ? void 0 : _a.close();
1893
+ (_a = this.socket) == null ? void 0 : _a.close();
1894
1894
  }
1895
1895
  if (parsed.op === Gateway.Opcode.DISPATCH) {
1896
- this.bot.ctx.emit("discord/" + parsed.t.toLowerCase().replace(/_/g, "-"), parsed);
1896
+ this.bot.dispatch(this.bot.session({
1897
+ type: "internal",
1898
+ _type: "discord/" + parsed.t.toLowerCase().replace(/_/g, "-"),
1899
+ _data: parsed
1900
+ }));
1897
1901
  if (parsed.t === "READY") {
1898
1902
  this._sessionId = parsed.d.session_id;
1899
1903
  this._resumeUrl = parsed.d.resume_gateway_url;
1900
- const user = decodeUser(parsed.d.user);
1901
- Object.assign(this.bot, user);
1904
+ this.bot.user = decodeUser(parsed.d.user);
1902
1905
  logger2.debug("session_id " + this._sessionId);
1903
1906
  return this.bot.online();
1904
1907
  }
@@ -1911,10 +1914,10 @@ var _WsClient = class _WsClient extends import_satori4.Adapter.WsClient {
1911
1914
  }
1912
1915
  if (parsed.op === Gateway.Opcode.RECONNECT) {
1913
1916
  logger2.warn("offline: discord request reconnect");
1914
- (_b = this.bot.socket) == null ? void 0 : _b.close();
1917
+ (_b = this.socket) == null ? void 0 : _b.close();
1915
1918
  }
1916
1919
  });
1917
- this.bot.socket.addEventListener("close", () => {
1920
+ this.socket.addEventListener("close", () => {
1918
1921
  clearInterval(this._ping);
1919
1922
  });
1920
1923
  }
@@ -1926,7 +1929,7 @@ var WsClient = _WsClient;
1926
1929
  import_satori4.Schema.object({
1927
1930
  intents: import_satori4.Schema.bitset(Gateway.Intent).description("需要订阅的机器人事件。").default(0 | Gateway.Intent.GUILD_MESSAGES | Gateway.Intent.GUILD_MESSAGE_REACTIONS | Gateway.Intent.DIRECT_MESSAGES | Gateway.Intent.DIRECT_MESSAGE_REACTIONS | Gateway.Intent.MESSAGE_CONTENT)
1928
1931
  }).description("推送设置"),
1929
- import_satori4.Adapter.WsClient.Config
1932
+ import_satori4.Adapter.WsClientConfig
1930
1933
  ]);
1931
1934
  })(WsClient || (WsClient = {}));
1932
1935
 
@@ -1953,9 +1956,6 @@ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
1953
1956
  this.internal = new Internal(this.http);
1954
1957
  ctx.plugin(WsClient, this);
1955
1958
  }
1956
- session(payload, input) {
1957
- return (0, import_satori5.defineProperty)(super.session(payload), "discord", Object.assign(Object.create(this.internal), input));
1958
- }
1959
1959
  async _ensureWebhook(channelId) {
1960
1960
  let webhook;
1961
1961
  const webhooks = await this.internal.getChannelWebhooks(channelId);
@@ -1981,9 +1981,10 @@ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
1981
1981
  }
1982
1982
  return (_a = this.webhookLock)[channelId] || (_a[channelId] = this._ensureWebhook(channelId));
1983
1983
  }
1984
- async getSelf() {
1984
+ async getLogin() {
1985
1985
  const data = await this.internal.getCurrentUser();
1986
- return decodeUser(data);
1986
+ this.user = decodeUser(data);
1987
+ return this.toJSON();
1987
1988
  }
1988
1989
  async deleteMessage(channelId, messageId) {
1989
1990
  await this.internal.deleteMessage(channelId, messageId);
@@ -2001,13 +2002,13 @@ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
2001
2002
  }
2002
2003
  async getMessage(channelId, messageId) {
2003
2004
  const data = await this.internal.getChannelMessage(channelId, messageId);
2004
- return await decodeMessage(this, data);
2005
+ return await decodeMessage(this, data, {});
2005
2006
  }
2006
2007
  async getMessageList(channelId, before) {
2007
2008
  var _a;
2008
2009
  const messages = await this.internal.getChannelMessages(channelId, { before, limit: 100 });
2009
- const data = await Promise.all(messages.reverse().map((data2) => decodeMessage(this, data2, {}, false)));
2010
- return { data, next: (_a = data[0]) == null ? void 0 : _a.messageId };
2010
+ const data = await Promise.all(messages.reverse().map((data2) => decodeMessage(this, data2, {}, void 0, false)));
2011
+ return { data, next: (_a = data[0]) == null ? void 0 : _a.id };
2011
2012
  }
2012
2013
  async getUser(userId) {
2013
2014
  const data = await this.internal.getUser(userId);
@@ -2078,19 +2079,17 @@ var _DiscordBot = class _DiscordBot extends import_satori5.Bot {
2078
2079
  }
2079
2080
  async createGuildRole(guildId, data) {
2080
2081
  const role = await this.internal.createGuildRole(guildId, encodeRole(data));
2081
- return role.id;
2082
+ return decodeRole(role);
2082
2083
  }
2083
- async modifyGuildRole(guildId, roleId, data) {
2084
+ async updateGuildRole(guildId, roleId, data) {
2084
2085
  await this.internal.modifyGuildRole(guildId, roleId, encodeRole(data));
2085
2086
  }
2086
2087
  deleteGuildRole(guildId, roleId) {
2087
2088
  return this.internal.deleteGuildRole(guildId, roleId);
2088
2089
  }
2089
- async sendPrivateMessage(userId, content, options) {
2090
- const channel = await this.internal.createDM({
2091
- recipient_id: userId
2092
- });
2093
- return this.sendMessage(channel.id, content, null, options);
2090
+ async createDirectChannel(userId) {
2091
+ const channel = await this.internal.createDM({ recipient_id: userId });
2092
+ return decodeChannel(channel);
2094
2093
  }
2095
2094
  async updateCommands(commands) {
2096
2095
  if (!this.config.slash)