@koishijs/plugin-adapter-discord 2.0.8 → 2.1.1

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,3 @@
1
- /// <reference types="koishi/lib" />
2
1
  /// <reference types="node" />
3
2
  import { Adapter, Bot, Quester, Schema } from 'koishi';
4
3
  import { AdapterConfig } from './utils';
@@ -12,7 +11,23 @@ export interface BotConfig extends Bot.BaseConfig, Quester.Config {
12
11
  gateway?: string;
13
12
  intents?: PrivilegedIntents;
14
13
  }
15
- export declare const BotConfig: Schema<unknown, any>;
14
+ export declare const BotConfig: Schema<Quester.Config & {
15
+ gateway?: string;
16
+ intents?: {
17
+ members?: boolean;
18
+ presence?: boolean;
19
+ } & import("koishi").Dict<any, string>;
20
+ } & import("koishi").Dict<any, string> & {
21
+ token?: string;
22
+ }, Quester.Config & {
23
+ gateway: string;
24
+ intents: {
25
+ members: boolean;
26
+ presence: boolean;
27
+ } & import("koishi").Dict<any, string>;
28
+ } & import("koishi").Dict<any, string> & {
29
+ token: string;
30
+ }>;
16
31
  export declare class DiscordBot extends Bot<BotConfig> {
17
32
  static schema: Schema<AdapterConfig, AdapterConfig>;
18
33
  _d: number;
@@ -40,8 +55,10 @@ export declare class DiscordBot extends Bot<BotConfig> {
40
55
  discriminator?: string;
41
56
  isBot?: boolean;
42
57
  }>;
58
+ kickGuildMember(guildId: string, userId: string): Promise<void>;
43
59
  getGuild(guildId: string): Promise<Bot.Guild>;
44
60
  getGuildList(): Promise<Bot.Guild[]>;
45
61
  getChannelList(guildId: string): Promise<Bot.Channel[]>;
62
+ getChannelMessageHistory(channelId: string, before?: string): Promise<Bot.Message[]>;
46
63
  }
47
64
  export {};
package/lib/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- /// <reference path="index.d.ts" />
2
- /// <reference types="koishi/lib" />
3
1
  import { Adapter } from 'koishi';
4
2
  import * as Discord from './types';
5
3
  export { Discord };
@@ -12,5 +10,5 @@ declare module 'koishi' {
12
10
  discord?: Discord.GatewayPayload & Discord.Internal;
13
11
  }
14
12
  }
15
- declare const _default: import("koishi").Plugin.Object<Adapter.PluginConfig<import("./utils").AdapterConfig, import("./bot").BotConfig>>;
13
+ declare const _default: import("koishi").Plugin.Object<Adapter.PluginConfig<import("./utils").AdapterConfig, import("./bot").BotConfig>, any>;
16
14
  export default _default;
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
 
@@ -244,7 +246,7 @@ function adaptMessage(meta, session = {}) {
244
246
  }
245
247
  session.content = "";
246
248
  if (meta.content) {
247
- session.content = meta.content.replace(/<@[!&](.+?)>/g, (_, id) => {
249
+ session.content = meta.content.replace(/<@[!&]?(.+?)>/g, (_, id) => {
248
250
  var _a2;
249
251
  if (meta.mention_roles.includes(id)) {
250
252
  return (0, import_koishi2.segment)("at", { role: id });
@@ -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,16 +340,12 @@ 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);
342
- if (session.userId === bot.selfId)
343
- return;
343
+ adaptMessageSession(input.d, session);
344
344
  } else if (input.t === "MESSAGE_UPDATE") {
345
345
  session.type = "message-updated";
346
346
  prepareMessageSession(session, input.d);
347
347
  const msg = await bot.internal.getChannelMessage(input.d.channel_id, input.d.id);
348
- adaptMessageSession(bot, msg, session);
349
- if (session.userId === bot.selfId)
350
- return;
348
+ adaptMessageSession(msg, session);
351
349
  } else if (input.t === "MESSAGE_DELETE") {
352
350
  session.type = "message-deleted";
353
351
  session.messageId = input.d.id;
@@ -367,6 +365,11 @@ async function adaptSession(bot, input) {
367
365
  session.type = "reaction-deleted";
368
366
  session.subtype = "emoji";
369
367
  prepareReactionSession(session, input.d);
368
+ } else if (input.t === "CHANNEL_UPDATE") {
369
+ session.type = "channel-updated";
370
+ session.guildId = input.d.guild_id;
371
+ session.subtype = input.d.guild_id ? "group" : "private";
372
+ session.channelId = input.d.id;
370
373
  } else {
371
374
  return;
372
375
  }
@@ -699,7 +702,7 @@ var GatewayOpcode;
699
702
  })(GatewayOpcode || (GatewayOpcode = {}));
700
703
  var GatewayIntent;
701
704
  (function(GatewayIntent2) {
702
- GatewayIntent2[GatewayIntent2["GUILD_CREATE"] = 1] = "GUILD_CREATE";
705
+ GatewayIntent2[GatewayIntent2["GUILDS"] = 1] = "GUILDS";
703
706
  GatewayIntent2[GatewayIntent2["GUILD_MEMBERS"] = 2] = "GUILD_MEMBERS";
704
707
  GatewayIntent2[GatewayIntent2["GUILD_BANS"] = 4] = "GUILD_BANS";
705
708
  GatewayIntent2[GatewayIntent2["GUILD_EMOJIS_AND_STICKERS"] = 8] = "GUILD_EMOJIS_AND_STICKERS";
@@ -1430,6 +1433,9 @@ var DiscordBot = class extends import_koishi4.Bot {
1430
1433
  nickname: member.nick
1431
1434
  });
1432
1435
  }
1436
+ async kickGuildMember(guildId, userId) {
1437
+ return this.internal.removeGuildMember(guildId, userId);
1438
+ }
1433
1439
  async getGuild(guildId) {
1434
1440
  const data = await this.internal.getGuild(guildId);
1435
1441
  return adaptGroup(data);
@@ -1442,6 +1448,18 @@ var DiscordBot = class extends import_koishi4.Bot {
1442
1448
  const data = await this.internal.getGuildChannels(guildId);
1443
1449
  return data.map((v) => adaptChannel(v));
1444
1450
  }
1451
+ async getChannelMessageHistory(channelId, before) {
1452
+ const data = (await this.internal.getChannelMessages(channelId, {
1453
+ before,
1454
+ limit: 50
1455
+ })).reverse();
1456
+ return data.map((v) => {
1457
+ const session = {};
1458
+ prepareMessageSession(session, v);
1459
+ adaptMessageSession(v, session);
1460
+ return session;
1461
+ });
1462
+ }
1445
1463
  };
1446
1464
  __name(DiscordBot, "DiscordBot");
1447
1465
  DiscordBot.schema = AdapterConfig;
@@ -1534,7 +1552,9 @@ var src_default = import_koishi6.Adapter.define("discord", DiscordBot, WebSocket
1534
1552
  adaptChannel,
1535
1553
  adaptGroup,
1536
1554
  adaptMessage,
1555
+ adaptMessageSession,
1537
1556
  adaptSession,
1538
- adaptUser
1557
+ adaptUser,
1558
+ prepareMessageSession
1539
1559
  });
1540
1560
  //# sourceMappingURL=index.js.map