@koishijs/plugin-adapter-discord 2.0.9 → 2.1.0

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
@@ -44,5 +44,6 @@ export declare class DiscordBot extends Bot<BotConfig> {
44
44
  getGuild(guildId: string): Promise<Bot.Guild>;
45
45
  getGuildList(): Promise<Bot.Guild[]>;
46
46
  getChannelList(guildId: string): Promise<Bot.Channel[]>;
47
+ getChannelMessageHistory(channelId: string, before?: string): Promise<Bot.Message[]>;
47
48
  }
48
49
  export {};
package/lib/index.js CHANGED
@@ -51,9 +51,11 @@ __export(exports, {
51
51
  adaptChannel: () => adaptChannel,
52
52
  adaptGroup: () => adaptGroup,
53
53
  adaptMessage: () => adaptMessage,
54
+ adaptMessageSession: () => adaptMessageSession,
54
55
  adaptSession: () => adaptSession,
55
56
  adaptUser: () => adaptUser,
56
- default: () => src_default
57
+ default: () => src_default,
58
+ prepareMessageSession: () => prepareMessageSession
57
59
  });
58
60
  var import_koishi6 = __toModule(require("koishi"));
59
61
 
@@ -302,7 +304,7 @@ function adaptMessage(meta, session = {}) {
302
304
  return session;
303
305
  }
304
306
  __name(adaptMessage, "adaptMessage");
305
- function adaptMessageSession(bot, meta, session = {}) {
307
+ function adaptMessageSession(meta, session = {}) {
306
308
  adaptMessage(meta, session);
307
309
  session.messageId = meta.id;
308
310
  session.timestamp = new Date(meta.timestamp).valueOf() || Date.now();
@@ -338,14 +340,14 @@ async function adaptSession(bot, input) {
338
340
  if (input.t === "MESSAGE_CREATE") {
339
341
  session.type = "message";
340
342
  prepareMessageSession(session, input.d);
341
- adaptMessageSession(bot, input.d, session);
343
+ adaptMessageSession(input.d, session);
342
344
  if (session.userId === bot.selfId)
343
345
  return;
344
346
  } else if (input.t === "MESSAGE_UPDATE") {
345
347
  session.type = "message-updated";
346
348
  prepareMessageSession(session, input.d);
347
349
  const msg = await bot.internal.getChannelMessage(input.d.channel_id, input.d.id);
348
- adaptMessageSession(bot, msg, session);
350
+ adaptMessageSession(msg, session);
349
351
  if (session.userId === bot.selfId)
350
352
  return;
351
353
  } else if (input.t === "MESSAGE_DELETE") {
@@ -367,6 +369,11 @@ async function adaptSession(bot, input) {
367
369
  session.type = "reaction-deleted";
368
370
  session.subtype = "emoji";
369
371
  prepareReactionSession(session, input.d);
372
+ } else if (input.t === "CHANNEL_UPDATE") {
373
+ session.type = "channel-updated";
374
+ session.guildId = input.d.guild_id;
375
+ session.subtype = input.d.guild_id ? "group" : "private";
376
+ session.channelId = input.d.id;
370
377
  } else {
371
378
  return;
372
379
  }
@@ -699,7 +706,7 @@ var GatewayOpcode;
699
706
  })(GatewayOpcode || (GatewayOpcode = {}));
700
707
  var GatewayIntent;
701
708
  (function(GatewayIntent2) {
702
- GatewayIntent2[GatewayIntent2["GUILD_CREATE"] = 1] = "GUILD_CREATE";
709
+ GatewayIntent2[GatewayIntent2["GUILDS"] = 1] = "GUILDS";
703
710
  GatewayIntent2[GatewayIntent2["GUILD_MEMBERS"] = 2] = "GUILD_MEMBERS";
704
711
  GatewayIntent2[GatewayIntent2["GUILD_BANS"] = 4] = "GUILD_BANS";
705
712
  GatewayIntent2[GatewayIntent2["GUILD_EMOJIS_AND_STICKERS"] = 8] = "GUILD_EMOJIS_AND_STICKERS";
@@ -1445,6 +1452,18 @@ var DiscordBot = class extends import_koishi4.Bot {
1445
1452
  const data = await this.internal.getGuildChannels(guildId);
1446
1453
  return data.map((v) => adaptChannel(v));
1447
1454
  }
1455
+ async getChannelMessageHistory(channelId, before) {
1456
+ const data = (await this.internal.getChannelMessages(channelId, {
1457
+ before,
1458
+ limit: 50
1459
+ })).reverse();
1460
+ return data.map((v) => {
1461
+ const session = {};
1462
+ prepareMessageSession(session, v);
1463
+ adaptMessageSession(v, session);
1464
+ return session;
1465
+ });
1466
+ }
1448
1467
  };
1449
1468
  __name(DiscordBot, "DiscordBot");
1450
1469
  DiscordBot.schema = AdapterConfig;
@@ -1537,7 +1556,9 @@ var src_default = import_koishi6.Adapter.define("discord", DiscordBot, WebSocket
1537
1556
  adaptChannel,
1538
1557
  adaptGroup,
1539
1558
  adaptMessage,
1559
+ adaptMessageSession,
1540
1560
  adaptSession,
1541
- adaptUser
1561
+ adaptUser,
1562
+ prepareMessageSession
1542
1563
  });
1543
1564
  //# sourceMappingURL=index.js.map