@koishijs/plugin-adapter-discord 2.0.6 → 2.0.9

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
@@ -40,6 +40,7 @@ export declare class DiscordBot extends Bot<BotConfig> {
40
40
  discriminator?: string;
41
41
  isBot?: boolean;
42
42
  }>;
43
+ kickGuildMember(guildId: string, userId: string): Promise<void>;
43
44
  getGuild(guildId: string): Promise<Bot.Guild>;
44
45
  getGuildList(): Promise<Bot.Guild[]>;
45
46
  getChannelList(guildId: string): Promise<Bot.Channel[]>;
package/lib/index.js CHANGED
@@ -91,8 +91,7 @@ var _Sender = class {
91
91
  }
92
92
  async sendEmbed(fileBuffer, payload_json, filename) {
93
93
  const fd = new import_form_data.default();
94
- const type = await (0, import_file_type.fromBuffer)(fileBuffer);
95
- filename || (filename = "file." + type.ext);
94
+ filename || (filename = "file." + (await (0, import_file_type.fromBuffer)(fileBuffer)).ext);
96
95
  fd.append("file", fileBuffer, filename);
97
96
  fd.append("payload_json", JSON.stringify(payload_json));
98
97
  return this.post(fd, fd.getHeaders());
@@ -120,12 +119,11 @@ var _Sender = class {
120
119
  return this.post(__spreadProps(__spreadValues({}, addition), { content: data.url }));
121
120
  }, "sendDirect");
122
121
  const sendDownload = /* @__PURE__ */ __name(async () => {
123
- const filename = (0, import_path.basename)(data.url);
124
122
  const buffer = await this.bot.app.http.get(data.url, {
125
123
  headers: { accept: type + "/*" },
126
124
  responseType: "arraybuffer"
127
125
  });
128
- return this.sendEmbed(buffer, addition, data.file || filename);
126
+ return this.sendEmbed(buffer, addition, data.file);
129
127
  }, "sendDownload");
130
128
  const mode = data.mode || handleExternalAsset;
131
129
  if (mode === "download" || handleMixedContent === "attach" && addition.content || type === "file") {
@@ -235,7 +233,7 @@ __name(adaptChannel, "adaptChannel");
235
233
  var adaptAuthor = /* @__PURE__ */ __name((author) => __spreadProps(__spreadValues({}, adaptUser(author)), {
236
234
  nickname: author.username
237
235
  }), "adaptAuthor");
238
- function adaptMessage(bot, meta, session = {}) {
236
+ function adaptMessage(meta, session = {}) {
239
237
  var _a, _b, _c;
240
238
  if (meta.author) {
241
239
  session.author = adaptAuthor(meta.author);
@@ -246,7 +244,7 @@ function adaptMessage(bot, meta, session = {}) {
246
244
  }
247
245
  session.content = "";
248
246
  if (meta.content) {
249
- session.content = meta.content.replace(/<@[!&](.+?)>/, (_, id) => {
247
+ session.content = meta.content.replace(/<@[!&]?(.+?)>/g, (_, id) => {
250
248
  var _a2;
251
249
  if (meta.mention_roles.includes(id)) {
252
250
  return (0, import_koishi2.segment)("at", { role: id });
@@ -254,7 +252,7 @@ function adaptMessage(bot, meta, session = {}) {
254
252
  const user = (_a2 = meta.mentions) == null ? void 0 : _a2.find((u) => u.id === id || `${u.username}#${u.discriminator}` === id);
255
253
  return import_koishi2.segment.at(id, { name: user == null ? void 0 : user.username });
256
254
  }
257
- }).replace(/<:(.*):(.+?)>/, (_, name, id) => (0, import_koishi2.segment)("face", { id, name })).replace(/<a:(.*):(.+?)>/, (_, name, id) => (0, import_koishi2.segment)("face", { id, name, animated: true })).replace(/@everyone/, () => (0, import_koishi2.segment)("at", { type: "all" })).replace(/@here/, () => (0, import_koishi2.segment)("at", { type: "here" })).replace(/<#(.+?)>/, (_, id) => {
255
+ }).replace(/<:(.*):(.+?)>/g, (_, name, id) => (0, import_koishi2.segment)("face", { id, name })).replace(/<a:(.*):(.+?)>/g, (_, name, id) => (0, import_koishi2.segment)("face", { id, name, animated: true })).replace(/@everyone/g, () => (0, import_koishi2.segment)("at", { type: "all" })).replace(/@here/g, () => (0, import_koishi2.segment)("at", { type: "here" })).replace(/<#(.+?)>/g, (_, id) => {
258
256
  var _a2;
259
257
  const channel = (_a2 = meta.mention_channels) == null ? void 0 : _a2.find((c) => c.id === id);
260
258
  return import_koishi2.segment.sharp(id, { name: channel == null ? void 0 : channel.name });
@@ -305,7 +303,7 @@ function adaptMessage(bot, meta, session = {}) {
305
303
  }
306
304
  __name(adaptMessage, "adaptMessage");
307
305
  function adaptMessageSession(bot, meta, session = {}) {
308
- adaptMessage(bot, meta, session);
306
+ adaptMessage(meta, session);
309
307
  session.messageId = meta.id;
310
308
  session.timestamp = new Date(meta.timestamp).valueOf() || Date.now();
311
309
  if (meta.message_reference) {
@@ -1405,24 +1403,12 @@ var DiscordBot = class extends import_koishi4.Bot {
1405
1403
  });
1406
1404
  }
1407
1405
  async getMessage(channelId, messageId) {
1408
- var _a;
1409
- const [msg, channel] = await Promise.all([
1410
- this.internal.getChannelMessage(channelId, messageId),
1411
- this.internal.getChannel(channelId)
1412
- ]);
1413
- const result = {
1414
- messageId: msg.id,
1415
- channelId: msg.channel_id,
1416
- guildId: channel.guild_id,
1417
- userId: msg.author.id,
1418
- content: msg.content,
1419
- timestamp: new Date(msg.timestamp).valueOf(),
1420
- author: adaptUser(msg.author)
1421
- };
1422
- result.author.nickname = (_a = msg.member) == null ? void 0 : _a.nick;
1423
- if (msg.message_reference) {
1424
- const quoteMsg = await this.internal.getChannelMessage(msg.message_reference.channel_id, msg.message_reference.message_id);
1425
- result.quote = adaptMessage(this, quoteMsg);
1406
+ const original = await this.internal.getChannelMessage(channelId, messageId);
1407
+ const result = adaptMessage(original);
1408
+ const reference = original.message_reference;
1409
+ if (reference) {
1410
+ const quoteMsg = await this.internal.getChannelMessage(reference.channel_id, reference.message_id);
1411
+ result.quote = adaptMessage(quoteMsg);
1426
1412
  }
1427
1413
  return result;
1428
1414
  }
@@ -1444,6 +1430,9 @@ var DiscordBot = class extends import_koishi4.Bot {
1444
1430
  nickname: member.nick
1445
1431
  });
1446
1432
  }
1433
+ async kickGuildMember(guildId, userId) {
1434
+ return this.internal.removeGuildMember(guildId, userId);
1435
+ }
1447
1436
  async getGuild(guildId) {
1448
1437
  const data = await this.internal.getGuild(guildId);
1449
1438
  return adaptGroup(data);
@@ -1462,11 +1451,11 @@ DiscordBot.schema = AdapterConfig;
1462
1451
 
1463
1452
  // plugins/adapter/discord/src/ws.ts
1464
1453
  var import_koishi5 = __toModule(require("koishi"));
1465
- var import_ws = __toModule(require("ws"));
1466
1454
  var logger = new import_koishi5.Logger("discord");
1467
1455
  var WebSocketClient = class extends import_koishi5.Adapter.WebSocketClient {
1468
1456
  prepare(bot) {
1469
- return new import_ws.default(bot.config.gateway);
1457
+ const http = this.ctx.http.extend(bot.config);
1458
+ return http.ws(bot.config.gateway);
1470
1459
  }
1471
1460
  heartbeat(bot) {
1472
1461
  logger.debug(`heartbeat d ${bot._d}`);