@satorijs/adapter-discord 3.0.0 → 3.0.3

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
@@ -2,11 +2,10 @@ import { Bot, Context, Message, Quester, Schema } from '@satorijs/satori';
2
2
  import { Sender } from './sender';
3
3
  import { Internal } from './types';
4
4
  import { WsClient } from './ws';
5
- export declare class DiscordBot extends Bot<Context, DiscordBot.Config> {
5
+ export declare class DiscordBot<C extends Context = Context> extends Bot<C, DiscordBot.Config> {
6
6
  http: Quester;
7
7
  internal: Internal;
8
- constructor(ctx: Context, config: DiscordBot.Config);
9
- getIntents(): number;
8
+ constructor(ctx: C, config: DiscordBot.Config);
10
9
  getSelf(): Promise<import("@satorijs/core").User>;
11
10
  private parseQuote;
12
11
  sendMessage(channelId: string, content: string, guildId?: string): Promise<string[]>;
package/lib/index.js CHANGED
@@ -339,12 +339,12 @@ __name(Sender, "Sender");
339
339
  import_satori2.Schema.const("download").description("先下载后发送"),
340
340
  import_satori2.Schema.const("direct").description("直接发送链接"),
341
341
  import_satori2.Schema.const("auto").description("发送一个 HEAD 请求,根据返回的 Content-Type 决定发送方式")
342
- ]).description("发送外链资源时采用的方式。").default("auto"),
342
+ ]).role("radio").description("发送外链资源时采用的方式。").default("auto"),
343
343
  handleMixedContent: import_satori2.Schema.union([
344
344
  import_satori2.Schema.const("separate").description("将每个不同形式的内容分开发送"),
345
345
  import_satori2.Schema.const("attach").description("图片前如果有文本内容,则将文本作为图片的附带信息进行发送"),
346
346
  import_satori2.Schema.const("auto").description("如果图片本身采用直接发送则与前面的文本分开,否则将文本作为图片的附带信息发送")
347
- ]).description("发送图文等混合内容时采用的方式。").default("auto")
347
+ ]).role("radio").description("发送图文等混合内容时采用的方式。").default("auto")
348
348
  }).description("发送设置");
349
349
  })(Sender || (Sender = {}));
350
350
 
@@ -1349,7 +1349,7 @@ var WsClient = class extends import_satori3.Adapter.WsClient {
1349
1349
  token: this.bot.config.token,
1350
1350
  properties: {},
1351
1351
  compress: false,
1352
- intents: this.bot.getIntents()
1352
+ intents: this.bot.config.intents
1353
1353
  }
1354
1354
  }));
1355
1355
  }
@@ -1377,11 +1377,8 @@ __name(WsClient, "WsClient");
1377
1377
  ((WsClient2) => {
1378
1378
  WsClient2.Config = import_satori3.Schema.intersect([
1379
1379
  import_satori3.Schema.object({
1380
- gateway: import_satori3.Schema.string().role("url").default("wss://gateway.discord.gg/?v=8&encoding=json").description("要连接的 WebSocket 网关。"),
1381
- intents: import_satori3.Schema.object({
1382
- members: import_satori3.Schema.boolean().description("启用 GUILD_MEMBERS 推送。").default(true),
1383
- presence: import_satori3.Schema.boolean().description("启用 GUILD_PRESENCES 推送。").default(false)
1384
- })
1380
+ gateway: import_satori3.Schema.string().default("wss://gateway.discord.gg/?v=8&encoding=json").description("要连接的 WebSocket 网关。"),
1381
+ intents: import_satori3.Schema.bitset(GatewayIntent).description("需要订阅的机器人事件。").default(0 | 512 /* GUILD_MESSAGES */ | 1024 /* GUILD_MESSAGE_REACTIONS */ | 4096 /* DIRECT_MESSAGES */ | 8192 /* DIRECT_MESSAGE_REACTIONS */)
1385
1382
  }).description("推送设置"),
1386
1383
  import_satori3.Adapter.WsClient.Config
1387
1384
  ]);
@@ -1401,16 +1398,6 @@ var DiscordBot = class extends import_satori4.Bot {
1401
1398
  this.internal = new Internal(this.http);
1402
1399
  ctx.plugin(WsClient, this);
1403
1400
  }
1404
- getIntents() {
1405
- let intents = 0 | 512 /* GUILD_MESSAGES */ | 1024 /* GUILD_MESSAGE_REACTIONS */ | 4096 /* DIRECT_MESSAGES */ | 8192 /* DIRECT_MESSAGE_REACTIONS */;
1406
- if (this.config.intents.members) {
1407
- intents |= 2 /* GUILD_MEMBERS */;
1408
- }
1409
- if (this.config.intents.presence) {
1410
- intents |= 256 /* GUILD_PRESENCES */;
1411
- }
1412
- return intents;
1413
- }
1414
1401
  async getSelf() {
1415
1402
  const data = await this.internal.getCurrentUser();
1416
1403
  return adaptUser(data);
@@ -1429,7 +1416,7 @@ var DiscordBot = class extends import_satori4.Bot {
1429
1416
  guildId,
1430
1417
  subtype: guildId ? "group" : "private"
1431
1418
  });
1432
- if (await this.ctx.serial(session, "before-send", session))
1419
+ if (await this.context.serial(session, "before-send", session))
1433
1420
  return;
1434
1421
  if (!(session == null ? void 0 : session.content))
1435
1422
  return [];
@@ -1442,7 +1429,7 @@ var DiscordBot = class extends import_satori4.Bot {
1442
1429
  const results = await send(session.content, { message_reference });
1443
1430
  for (const id of results) {
1444
1431
  session.messageId = id;
1445
- this.ctx.emit(session, "send", session);
1432
+ this.context.emit(session, "send", session);
1446
1433
  }
1447
1434
  return results;
1448
1435
  }
@@ -1527,12 +1514,7 @@ __name(DiscordBot, "DiscordBot");
1527
1514
  }),
1528
1515
  WsClient.Config,
1529
1516
  Sender.Config,
1530
- import_satori4.Schema.object({
1531
- endpoint: import_satori4.Schema.string().role("url").description("要连接的服务器地址。").default("https://discord.com/api/v8"),
1532
- proxyAgent: import_satori4.Schema.string().role("url").description("使用的代理服务器地址。"),
1533
- headers: import_satori4.Schema.dict(String).description("要附加的额外请求头。"),
1534
- timeout: import_satori4.Schema.natural().role("ms").description("等待连接建立的最长时间。")
1535
- }).description("请求设置")
1517
+ import_satori4.Quester.createConfig("https://discord.com/api/v8")
1536
1518
  ]);
1537
1519
  })(DiscordBot || (DiscordBot = {}));
1538
1520
  DiscordBot.prototype.platform = "discord";