@satorijs/adapter-discord 3.7.0 → 3.8.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/index.js CHANGED
@@ -30,21 +30,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // satori/adapters/discord/src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- Discord: () => types_exports,
33
+ Discord: () => utils_exports,
34
34
  DiscordBot: () => DiscordBot,
35
35
  DiscordMessageEncoder: () => DiscordMessageEncoder,
36
36
  WsClient: () => WsClient,
37
- adaptAuthor: () => adaptAuthor,
38
- adaptChannel: () => adaptChannel,
39
- adaptGuild: () => adaptGuild,
40
- adaptMessage: () => adaptMessage,
41
- adaptSession: () => adaptSession,
42
- adaptUser: () => adaptUser,
43
- decodeRole: () => decodeRole,
44
- default: () => src_default,
45
- encodeRole: () => encodeRole,
46
- prepareMessage: () => prepareMessage,
47
- sanitize: () => sanitize
37
+ default: () => src_default
48
38
  });
49
39
  module.exports = __toCommonJS(src_exports);
50
40
 
@@ -52,606 +42,146 @@ module.exports = __toCommonJS(src_exports);
52
42
  var import_satori5 = require("@satorijs/satori");
53
43
 
54
44
  // satori/adapters/discord/src/utils.ts
45
+ var utils_exports = {};
46
+ __export(utils_exports, {
47
+ ActivityFlag: () => ActivityFlag,
48
+ ActivityType: () => ActivityType,
49
+ AllowedMentionType: () => AllowedMentionType,
50
+ ApplicationCommand: () => ApplicationCommand2,
51
+ ApplicationFlag: () => ApplicationFlag,
52
+ ApplicationRoleConnection: () => ApplicationRoleConnection,
53
+ AuditLog: () => AuditLog,
54
+ AutoModerationAction: () => AutoModerationAction,
55
+ AutoModerationRule: () => AutoModerationRule2,
56
+ ButtonStyles: () => ButtonStyles,
57
+ Channel: () => Channel2,
58
+ ComponentType: () => ComponentType,
59
+ DeviceType: () => DeviceType,
60
+ Gateway: () => Gateway,
61
+ Guild: () => Guild3,
62
+ GuildFeature: () => GuildFeature,
63
+ GuildScheduledEvent: () => GuildScheduledEvent3,
64
+ IntegrationExpireBehavior: () => IntegrationExpireBehavior,
65
+ Interaction: () => Interaction,
66
+ Internal: () => Internal,
67
+ Invite: () => Invite,
68
+ Locale: () => Locale3,
69
+ MembershipState: () => MembershipState,
70
+ Message: () => Message2,
71
+ OverwriteType: () => OverwriteType,
72
+ Permission: () => Permission,
73
+ PremiumType: () => PremiumType,
74
+ StatusType: () => StatusType2,
75
+ Sticker: () => Sticker3,
76
+ SystemChannelFlag: () => SystemChannelFlag,
77
+ TextInputStyles: () => TextInputStyles,
78
+ UserFlag: () => UserFlag,
79
+ VisibilityType: () => VisibilityType,
80
+ Webhook: () => Webhook2,
81
+ adaptSession: () => adaptSession,
82
+ decodeAuthor: () => decodeAuthor,
83
+ decodeChannel: () => decodeChannel,
84
+ decodeGuild: () => decodeGuild,
85
+ decodeMessage: () => decodeMessage,
86
+ decodeRole: () => decodeRole,
87
+ decodeUser: () => decodeUser,
88
+ encodeCommand: () => encodeCommand,
89
+ encodeCommandOptions: () => encodeCommandOptions,
90
+ encodeRole: () => encodeRole,
91
+ sanitize: () => sanitize,
92
+ setupMessage: () => setupMessage
93
+ });
94
+ var import_satori2 = require("@satorijs/satori");
95
+
96
+ // satori/adapters/discord/src/types/internal.ts
55
97
  var import_satori = require("@satorijs/satori");
56
- var sanitize = /* @__PURE__ */ __name((val) => val.replace(/[\\*_`~|()\[\]]/g, "\\$&").replace(/@everyone/g, () => "\\@everyone").replace(/@here/g, () => "\\@here"), "sanitize");
57
- var adaptUser = /* @__PURE__ */ __name((user) => ({
58
- userId: user.id,
59
- avatar: `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`,
60
- username: user.username,
61
- discriminator: user.discriminator,
62
- isBot: user.bot || false
63
- }), "adaptUser");
64
- var adaptGuild = /* @__PURE__ */ __name((data) => ({
65
- guildId: data.id,
66
- guildName: data.name
67
- }), "adaptGuild");
68
- var adaptChannel = /* @__PURE__ */ __name((data) => ({
69
- channelId: data.id,
70
- channelName: data.name
71
- }), "adaptChannel");
72
- var adaptAuthor = /* @__PURE__ */ __name((author) => ({
73
- ...adaptUser(author),
74
- nickname: author.username
75
- }), "adaptAuthor");
76
- var decodeRole = /* @__PURE__ */ __name((role) => ({
77
- ...role,
78
- permissions: BigInt(role.permissions)
79
- }), "decodeRole");
80
- var encodeRole = /* @__PURE__ */ __name((role) => ({
81
- ...role,
82
- permissions: role.permissions && "" + role.permissions
83
- }), "encodeRole");
84
- async function adaptMessage(bot, meta, session = {}) {
85
- var _a, _b, _c;
86
- const { platform } = bot;
87
- prepareMessage(session, meta);
88
- session.messageId = meta.id;
89
- session.timestamp = new Date(meta.timestamp).valueOf() || Date.now();
90
- if (meta.author) {
91
- session.author = adaptAuthor(meta.author);
92
- session.userId = meta.author.id;
93
- }
94
- if ((_a = meta.member) == null ? void 0 : _a.nick) {
95
- session.author.nickname = (_b = meta.member) == null ? void 0 : _b.nick;
96
- }
97
- session.content = "";
98
- if (meta.content) {
99
- session.content = meta.content.replace(/<@[!&]?(.+?)>/g, (_, id) => {
100
- var _a2;
101
- if (meta.mention_roles.includes(id)) {
102
- return (0, import_satori.h)("at", { role: id }).toString();
103
- } else {
104
- const user = (_a2 = meta.mentions) == null ? void 0 : _a2.find((u) => u.id === id || `${u.username}#${u.discriminator}` === id);
105
- return import_satori.h.at(id, { name: user == null ? void 0 : user.username }).toString();
106
- }
107
- }).replace(/<a?:(.*):(.+?)>/g, (_, name, id) => {
108
- const animated = _[1] === "a";
109
- return (0, import_satori.h)("face", { id, name, animated, platform }, [
110
- import_satori.h.image(`https://cdn.discordapp.com/emojis/${id}.gif?quality=lossless`)
111
- ]).toString();
112
- }).replace(/@everyone/g, () => (0, import_satori.h)("at", { type: "all" }).toString()).replace(/@here/g, () => (0, import_satori.h)("at", { type: "here" }).toString()).replace(/<#(.+?)>/g, (_, id) => {
113
- var _a2;
114
- const channel = (_a2 = meta.mention_channels) == null ? void 0 : _a2.find((c) => c.id === id);
115
- return import_satori.h.sharp(id, { name: channel == null ? void 0 : channel.name }).toString();
116
- });
98
+ var Internal = class {
99
+ constructor(http) {
100
+ this.http = http;
117
101
  }
118
- if ((_c = meta.attachments) == null ? void 0 : _c.length) {
119
- if (session.content)
120
- session.content += " ";
121
- session.content += meta.attachments.map((v) => {
122
- var _a2, _b2, _c2;
123
- if (v.height && v.width && ((_a2 = v.content_type) == null ? void 0 : _a2.startsWith("image/"))) {
124
- return (0, import_satori.h)("image", {
125
- url: v.url,
126
- proxy_url: v.proxy_url,
127
- file: v.filename
128
- });
129
- } else if (v.height && v.width && ((_b2 = v.content_type) == null ? void 0 : _b2.startsWith("video/"))) {
130
- return (0, import_satori.h)("video", {
131
- url: v.url,
132
- proxy_url: v.proxy_url,
133
- file: v.filename
134
- });
135
- } else if ((_c2 = v.content_type) == null ? void 0 : _c2.startsWith("audio/")) {
136
- return (0, import_satori.h)("record", {
137
- url: v.url,
138
- proxy_url: v.proxy_url,
139
- file: v.filename
140
- });
141
- } else {
142
- return (0, import_satori.h)("file", {
143
- url: v.url,
144
- proxy_url: v.proxy_url,
145
- file: v.filename
146
- });
102
+ static define(routes) {
103
+ for (const path in routes) {
104
+ for (const key in routes[path]) {
105
+ const method = key;
106
+ for (const name of (0, import_satori.makeArray)(routes[path][method])) {
107
+ Internal.prototype[name] = async function(...args) {
108
+ const raw = args.join(", ");
109
+ const url = path.replace(/\{([^}]+)\}/g, () => {
110
+ if (!args.length)
111
+ throw new Error(`too few arguments for ${path}, received ${raw}`);
112
+ return args.shift();
113
+ });
114
+ const config = {};
115
+ if (args.length === 1) {
116
+ if (method === "GET" || method === "DELETE") {
117
+ config.params = args[0];
118
+ } else {
119
+ config.data = args[0];
120
+ }
121
+ } else if (args.length === 2 && method !== "GET" && method !== "DELETE") {
122
+ config.data = args[0];
123
+ config.params = args[1];
124
+ } else if (args.length > 1) {
125
+ throw new Error(`too many arguments for ${path}, received ${raw}`);
126
+ }
127
+ try {
128
+ return await this.http(method, url, config);
129
+ } catch (error) {
130
+ if (!import_satori.Quester.isAxiosError(error) || !error.response)
131
+ throw error;
132
+ throw new Error(`[${error.response.status}] ${JSON.stringify(error.response.data)}`);
133
+ }
134
+ };
135
+ }
147
136
  }
148
- }).join("");
149
- }
150
- for (const embed of meta.embeds) {
151
- if (embed.image) {
152
- session.content += (0, import_satori.h)("image", { url: embed.image.url, proxy_url: embed.image.proxy_url });
153
- }
154
- if (embed.thumbnail) {
155
- session.content += (0, import_satori.h)("image", { url: embed.thumbnail.url, proxy_url: embed.thumbnail.proxy_url });
156
- }
157
- if (embed.video) {
158
- session.content += (0, import_satori.h)("video", { url: embed.video.url, proxy_url: embed.video.proxy_url });
159
137
  }
160
138
  }
161
- session.elements = import_satori.h.parse(session.content);
162
- if (meta.message_reference) {
163
- const { message_id, channel_id } = meta.message_reference;
164
- session.quote = await bot.getMessage(channel_id, message_id);
139
+ };
140
+ __name(Internal, "Internal");
141
+
142
+ // satori/adapters/discord/src/types/application.ts
143
+ var ApplicationFlag = /* @__PURE__ */ ((ApplicationFlag2) => {
144
+ ApplicationFlag2[ApplicationFlag2["GATEWAY_PRESENCE"] = 4096] = "GATEWAY_PRESENCE";
145
+ ApplicationFlag2[ApplicationFlag2["GATEWAY_PRESENCE_LIMITED"] = 8192] = "GATEWAY_PRESENCE_LIMITED";
146
+ ApplicationFlag2[ApplicationFlag2["GATEWAY_GUILD_MEMBERS"] = 16384] = "GATEWAY_GUILD_MEMBERS";
147
+ ApplicationFlag2[ApplicationFlag2["GATEWAY_GUILD_MEMBERS_LIMITED"] = 32768] = "GATEWAY_GUILD_MEMBERS_LIMITED";
148
+ ApplicationFlag2[ApplicationFlag2["VERIFICATION_PENDING_GUILD_LIMIT"] = 65536] = "VERIFICATION_PENDING_GUILD_LIMIT";
149
+ ApplicationFlag2[ApplicationFlag2["EMBEDDED"] = 131072] = "EMBEDDED";
150
+ ApplicationFlag2[ApplicationFlag2["GATEWAY_MESSAGE_CONTENT"] = 262144] = "GATEWAY_MESSAGE_CONTENT";
151
+ ApplicationFlag2[ApplicationFlag2["GATEWAY_MESSAGE_CONTENT_LIMITED"] = 524288] = "GATEWAY_MESSAGE_CONTENT_LIMITED";
152
+ ApplicationFlag2[ApplicationFlag2["APPLICATION_COMMAND_BADGE"] = 8388608] = "APPLICATION_COMMAND_BADGE";
153
+ return ApplicationFlag2;
154
+ })(ApplicationFlag || {});
155
+ Internal.define({
156
+ "/oauth2/applications/@me": {
157
+ GET: "getCurrentBotApplicationInformation"
158
+ },
159
+ "/oauth2/@me": {
160
+ GET: "getCurrentAuthorizationInformation"
165
161
  }
166
- return session;
167
- }
168
- __name(adaptMessage, "adaptMessage");
169
- function prepareMessage(session, data) {
170
- session.guildId = data.guild_id;
171
- session.subtype = data.guild_id ? "group" : "private";
172
- session.channelId = data.channel_id;
173
- }
174
- __name(prepareMessage, "prepareMessage");
175
- function prepareReactionSession(session, data) {
176
- session.userId = data.user_id;
177
- session.messageId = data.message_id;
178
- session.guildId = data.guild_id;
179
- session.channelId = data.channel_id;
180
- session.subtype = data.guild_id ? "group" : "private";
181
- if (!data.emoji)
182
- return;
183
- const { id, name } = data.emoji;
184
- session.content = id ? `${name}:${id}` : name;
185
- }
186
- __name(prepareReactionSession, "prepareReactionSession");
187
- async function adaptSession(bot, input) {
188
- const session = bot.session();
189
- if (input.t === "MESSAGE_CREATE") {
190
- if (input.d.webhook_id) {
191
- const webhook = await bot.ensureWebhook(input.d.channel_id);
192
- if (webhook.id === input.d.webhook_id) {
193
- return;
194
- }
195
- }
196
- session.type = "message";
197
- await adaptMessage(bot, input.d, session);
198
- } else if (input.t === "MESSAGE_UPDATE") {
199
- session.type = "message-updated";
200
- const msg = await bot.internal.getChannelMessage(input.d.channel_id, input.d.id);
201
- await adaptMessage(bot, msg, session);
202
- } else if (input.t === "MESSAGE_DELETE") {
203
- session.type = "message-deleted";
204
- session.messageId = input.d.id;
205
- prepareMessage(session, input.d);
206
- } else if (input.t === "MESSAGE_REACTION_ADD") {
207
- session.type = "reaction-added";
208
- prepareReactionSession(session, input.d);
209
- } else if (input.t === "MESSAGE_REACTION_REMOVE") {
210
- session.type = "reaction-deleted";
211
- session.subtype = "one";
212
- prepareReactionSession(session, input.d);
213
- } else if (input.t === "MESSAGE_REACTION_REMOVE_ALL") {
214
- session.type = "reaction-deleted";
215
- session.subtype = "all";
216
- prepareReactionSession(session, input.d);
217
- } else if (input.t === "MESSAGE_REACTION_REMOVE_EMOJI") {
218
- session.type = "reaction-deleted";
219
- session.subtype = "emoji";
220
- prepareReactionSession(session, input.d);
221
- } else if (input.t === "CHANNEL_UPDATE") {
222
- session.type = "channel-updated";
223
- session.guildId = input.d.guild_id;
224
- session.subtype = input.d.guild_id ? "group" : "private";
225
- session.channelId = input.d.id;
226
- } else {
227
- return;
162
+ });
163
+
164
+ // satori/adapters/discord/src/types/application-role-connection.ts
165
+ var ApplicationRoleConnection;
166
+ ((ApplicationRoleConnection2) => {
167
+ let MetadataType;
168
+ ((MetadataType2) => {
169
+ MetadataType2[MetadataType2["INTEGER_LESS_THAN_OR_EQUAL"] = 1] = "INTEGER_LESS_THAN_OR_EQUAL";
170
+ MetadataType2[MetadataType2["INTEGER_GREATER_THAN_OR_EQUAL"] = 2] = "INTEGER_GREATER_THAN_OR_EQUAL";
171
+ MetadataType2[MetadataType2["INTEGER_EQUAL"] = 3] = "INTEGER_EQUAL";
172
+ MetadataType2[MetadataType2["INTEGER_NOT_EQUAL"] = 4] = "INTEGER_NOT_EQUAL";
173
+ MetadataType2[MetadataType2["DATETIME_LESS_THAN_OR_EQUAL"] = 5] = "DATETIME_LESS_THAN_OR_EQUAL";
174
+ MetadataType2[MetadataType2["DATETIME_GREATER_THAN_OR_EQUAL"] = 6] = "DATETIME_GREATER_THAN_OR_EQUAL";
175
+ MetadataType2[MetadataType2["BOOLEAN_EQUAL"] = 7] = "BOOLEAN_EQUAL";
176
+ MetadataType2[MetadataType2["BOOLEAN_NOT_EQUAL"] = 8] = "BOOLEAN_NOT_EQUAL";
177
+ })(MetadataType = ApplicationRoleConnection2.MetadataType || (ApplicationRoleConnection2.MetadataType = {}));
178
+ })(ApplicationRoleConnection || (ApplicationRoleConnection = {}));
179
+ Internal.define({
180
+ "/applications/{application.id}/role-connections/metadata": {
181
+ GET: "getApplicationRoleConnectionMetadataRecords",
182
+ PUT: "updateApplicationRoleConnectionMetadataRecords"
228
183
  }
229
- return session;
230
- }
231
- __name(adaptSession, "adaptSession");
232
-
233
- // satori/adapters/discord/src/message.ts
234
- var import_satori2 = require("@satorijs/satori");
235
- var import_form_data = __toESM(require("form-data"));
236
- var logger = new import_satori2.Logger("discord");
237
- var State = class {
238
- // forward: send the first message and create a thread
239
- constructor(type) {
240
- this.type = type;
241
- this.author = {};
242
- this.quote = {};
243
- this.channel = {};
244
- this.fakeMessageMap = {};
245
- // [userInput] = discord messages
246
- this.threadCreated = false;
247
- }
248
- };
249
- __name(State, "State");
250
- var DiscordMessageEncoder = class extends import_satori2.MessageEncoder {
251
- constructor() {
252
- super(...arguments);
253
- this.stack = [new State("message")];
254
- this.buffer = "";
255
- this.addition = {};
256
- this.figure = null;
257
- this.mode = "default";
258
- }
259
- async post(data, headers) {
260
- var _a, _b, _c;
261
- try {
262
- let url = `/channels/${this.channelId}/messages`;
263
- if (this.stack[0].author.nickname || this.stack[0].author.avatar || this.stack[0].type === "forward" && !this.stack[0].threadCreated) {
264
- const webhook = await this.ensureWebhook();
265
- url = `/webhooks/${webhook.id}/${webhook.token}?wait=true`;
266
- }
267
- if (this.stack[0].type === "forward" && ((_a = this.stack[0].channel) == null ? void 0 : _a.id)) {
268
- if (this.stack[1].author.nickname || this.stack[1].author.avatar) {
269
- const webhook = await this.ensureWebhook();
270
- url = `/webhooks/${webhook.id}/${webhook.token}?wait=true&thread_id=${(_b = this.stack[0].channel) == null ? void 0 : _b.id}`;
271
- } else {
272
- url = `/channels/${this.stack[0].channel.id}/messages`;
273
- }
274
- }
275
- const result = await this.bot.http.post(url, data, { headers });
276
- const session = this.bot.session();
277
- const message = await adaptMessage(this.bot, result, session);
278
- session.app.emit(session, "send", session);
279
- this.results.push(session);
280
- if (this.stack[0].type === "forward" && !this.stack[0].threadCreated) {
281
- this.stack[0].threadCreated = true;
282
- const thread = await this.bot.internal.startThreadFromMessage(this.channelId, result.id, {
283
- name: "Forward",
284
- auto_archive_duration: 60
285
- });
286
- this.stack[0].channel = thread;
287
- }
288
- return message;
289
- } catch (e) {
290
- if (import_satori2.Quester.isAxiosError(e) && ((_c = e.response) == null ? void 0 : _c.data.code) === 10015) {
291
- logger.debug("webhook has been deleted, recreating..., %o", e.response.data);
292
- if (!this.bot.webhookLock[this.channelId])
293
- this.bot.webhooks[this.channelId] = null;
294
- await this.ensureWebhook();
295
- return this.post(data, headers);
296
- }
297
- this.errors.push(e);
298
- }
299
- }
300
- async sendEmbed(attrs, payload) {
301
- const { filename, data, mime } = await this.bot.ctx.http.file(attrs.url, attrs);
302
- const form = new import_form_data.default();
303
- const value = process.env.KOISHI_ENV === "browser" ? new Blob([data], { type: mime }) : Buffer.from(data);
304
- form.append("file", value, attrs.file || filename);
305
- form.append("payload_json", JSON.stringify(payload));
306
- return this.post(form, form.getHeaders());
307
- }
308
- async sendAsset(type, attrs, addition) {
309
- const { handleMixedContent, handleExternalAsset } = this.bot.config;
310
- if (handleMixedContent === "separate" && addition.content) {
311
- await this.post(addition);
312
- addition.content = "";
313
- }
314
- const sendDirect = /* @__PURE__ */ __name(async () => {
315
- if (addition.content) {
316
- await this.post(addition);
317
- }
318
- return this.post({ ...addition, content: attrs.url });
319
- }, "sendDirect");
320
- const sendDownload = /* @__PURE__ */ __name(() => this.sendEmbed(attrs, addition), "sendDownload");
321
- if (["file:", "data:", "base64:"].some((prefix) => attrs.url.startsWith(prefix))) {
322
- return await sendDownload();
323
- }
324
- const mode = attrs.mode || handleExternalAsset;
325
- if (mode === "download" || handleMixedContent === "attach" && addition.content || type === "file") {
326
- return sendDownload();
327
- } else if (mode === "direct") {
328
- return sendDirect();
329
- }
330
- return await this.bot.ctx.http.head(attrs.url, {
331
- headers: { accept: type + "/*" },
332
- timeout: +attrs.timeout || void 0
333
- }).then((headers) => {
334
- if (headers["content-type"].startsWith(type)) {
335
- return sendDirect();
336
- } else {
337
- return sendDownload();
338
- }
339
- }, sendDownload);
340
- }
341
- async ensureWebhook() {
342
- return this.bot.ensureWebhook(this.channelId);
343
- }
344
- async flush() {
345
- const content = this.buffer.trim();
346
- if (!content)
347
- return;
348
- await this.post({ ...this.addition, content });
349
- this.buffer = "";
350
- this.addition = {};
351
- }
352
- async visit(element) {
353
- var _a;
354
- const { type, attrs, children } = element;
355
- if (type === "text") {
356
- this.buffer += sanitize(attrs.content);
357
- } else if (type === "b" || type === "strong") {
358
- this.buffer += "**";
359
- await this.render(children);
360
- this.buffer += "**";
361
- } else if (type === "i" || type === "em") {
362
- this.buffer += "*";
363
- await this.render(children);
364
- this.buffer += "*";
365
- } else if (type === "u" || type === "ins") {
366
- this.buffer += "__";
367
- await this.render(children);
368
- this.buffer += "__";
369
- } else if (type === "s" || type === "del") {
370
- this.buffer += "~~";
371
- await this.render(children);
372
- this.buffer += "~~";
373
- } else if (type === "spl") {
374
- this.buffer += "||";
375
- await this.render(children);
376
- this.buffer += "||";
377
- } else if (type === "code") {
378
- this.buffer += "`";
379
- await this.render(children);
380
- this.buffer += "`";
381
- } else if (type === "a") {
382
- await this.render(children);
383
- if (this.options.linkPreview) {
384
- this.buffer += ` (${attrs.href}) `;
385
- } else {
386
- this.buffer += ` (<${attrs.href}>) `;
387
- }
388
- } else if (type === "p") {
389
- await this.render(children);
390
- this.buffer += "\n";
391
- } else if (type === "at") {
392
- if (attrs.id) {
393
- this.buffer += `<@${attrs.id}>`;
394
- } else if (attrs.type === "all") {
395
- this.buffer += `@everyone`;
396
- } else if (attrs.type === "here") {
397
- this.buffer += `@here`;
398
- }
399
- } else if (type === "sharp" && attrs.id) {
400
- this.buffer += `<#${attrs.id}>`;
401
- } else if (type === "face") {
402
- if (attrs.platform && attrs.platform !== this.bot.platform) {
403
- return this.render(children);
404
- } else {
405
- this.buffer += `<${attrs.animated ? "a" : ""}:${attrs.name}:${attrs.id}>`;
406
- }
407
- } else if ((type === "image" || type === "video") && attrs.url) {
408
- if (this.mode === "figure") {
409
- this.figure = element;
410
- } else {
411
- await this.sendAsset(type, attrs, {
412
- ...this.addition,
413
- content: this.buffer.trim()
414
- });
415
- this.buffer = "";
416
- }
417
- } else if (type === "share") {
418
- await this.flush();
419
- await this.post({
420
- ...this.addition,
421
- embeds: [{ ...attrs }]
422
- });
423
- } else if (type === "audio") {
424
- await this.sendAsset("file", attrs, {
425
- ...this.addition,
426
- content: this.buffer.trim()
427
- });
428
- this.buffer = "";
429
- } else if (type === "figure") {
430
- await this.flush();
431
- this.mode = "figure";
432
- await this.render(children);
433
- await this.sendAsset(this.figure.type, this.figure.attrs, {
434
- ...this.addition,
435
- content: this.buffer.trim()
436
- });
437
- this.buffer = "";
438
- this.mode = "default";
439
- } else if (type === "message" && !attrs.forward) {
440
- if (this.mode === "figure") {
441
- await this.render(children);
442
- this.buffer += "\n";
443
- } else {
444
- const resultLength = +this.results.length;
445
- await this.flush();
446
- const [author] = import_satori2.segment.select(children, "author");
447
- if (author) {
448
- const { avatar, nickname } = author.attrs;
449
- if (avatar)
450
- this.addition.avatar_url = avatar;
451
- if (nickname)
452
- this.addition.username = nickname;
453
- if (this.stack[0].type === "message") {
454
- this.stack[0].author = author.attrs;
455
- }
456
- if (this.stack[0].type === "forward") {
457
- this.stack[1].author = author.attrs;
458
- }
459
- }
460
- const [quote] = import_satori2.segment.select(children, "quote");
461
- if (quote) {
462
- const parse = /* @__PURE__ */ __name((val) => val.replace(/\\([\\*_`~|()\[\]])/g, "$1"), "parse");
463
- const message = this.stack[this.stack[0].type === "forward" ? 1 : 0];
464
- if (!message.author.avatar && !message.author.nickname && this.stack[0].type !== "forward") {
465
- await this.flush();
466
- this.addition.message_reference = {
467
- message_id: quote.attrs.id
468
- };
469
- } else {
470
- let replyId = quote.attrs.id, channelId = this.channelId;
471
- if (this.stack[0].type === "forward" && ((_a = this.stack[0].fakeMessageMap[quote.attrs.id]) == null ? void 0 : _a.length) >= 1) {
472
- replyId = this.stack[0].fakeMessageMap[quote.attrs.id][0].messageId;
473
- channelId = this.stack[0].fakeMessageMap[quote.attrs.id][0].channelId;
474
- }
475
- const quoted = await this.bot.getMessage(channelId, replyId);
476
- this.addition.embeds = [{
477
- description: [
478
- sanitize(parse(quoted.elements.filter((v) => v.type === "text").join("")).slice(0, 30)),
479
- `<t:${Math.ceil(quoted.timestamp / 1e3)}:R> [[ ↑ ]](https://discord.com/channels/${this.guildId}/${channelId}/${replyId})`
480
- ].join("\n\n"),
481
- author: {
482
- name: quoted.author.nickname || quoted.author.username,
483
- icon_url: quoted.author.avatar
484
- }
485
- }];
486
- }
487
- }
488
- await this.render(children);
489
- await this.flush();
490
- const newLength = +this.results.length;
491
- const sentMessages = this.results.slice(resultLength, newLength);
492
- if (this.stack[0].type === "forward" && attrs.id) {
493
- this.stack[0].fakeMessageMap[attrs.id] = sentMessages;
494
- }
495
- if (this.stack[0].type === "message") {
496
- this.stack[0].author = {};
497
- }
498
- if (this.stack[0].type === "forward") {
499
- this.stack[1].author = {};
500
- }
501
- }
502
- } else if (type === "message" && attrs.forward) {
503
- this.stack.unshift(new State("forward"));
504
- await this.render(children);
505
- await this.flush();
506
- await this.bot.internal.modifyChannel(this.stack[0].channel.id, {
507
- archived: true,
508
- locked: true
509
- });
510
- this.stack.shift();
511
- } else {
512
- await this.render(children);
513
- }
514
- }
515
- };
516
- __name(DiscordMessageEncoder, "DiscordMessageEncoder");
517
- ((DiscordMessageEncoder2) => {
518
- DiscordMessageEncoder2.Config = import_satori2.Schema.object({
519
- handleExternalAsset: import_satori2.Schema.union([
520
- import_satori2.Schema.const("download").description("先下载后发送"),
521
- import_satori2.Schema.const("direct").description("直接发送链接"),
522
- import_satori2.Schema.const("auto").description("发送一个 HEAD 请求,根据返回的 Content-Type 决定发送方式")
523
- ]).role("radio").description("发送外链资源时采用的方式。").default("auto"),
524
- handleMixedContent: import_satori2.Schema.union([
525
- import_satori2.Schema.const("separate").description("将每个不同形式的内容分开发送"),
526
- import_satori2.Schema.const("attach").description("图片前如果有文本内容,则将文本作为图片的附带信息进行发送"),
527
- import_satori2.Schema.const("auto").description("如果图片本身采用直接发送则与前面的文本分开,否则将文本作为图片的附带信息发送")
528
- ]).role("radio").description("发送图文等混合内容时采用的方式。").default("auto")
529
- }).description("发送设置");
530
- })(DiscordMessageEncoder || (DiscordMessageEncoder = {}));
531
-
532
- // satori/adapters/discord/src/types/index.ts
533
- var types_exports = {};
534
- __export(types_exports, {
535
- ActivityFlag: () => ActivityFlag,
536
- ActivityType: () => ActivityType,
537
- AllowedMentionType: () => AllowedMentionType,
538
- ApplicationCommand: () => ApplicationCommand2,
539
- ApplicationFlag: () => ApplicationFlag,
540
- ApplicationRoleConnection: () => ApplicationRoleConnection,
541
- AuditLog: () => AuditLog,
542
- AutoModerationAction: () => AutoModerationAction,
543
- AutoModerationRule: () => AutoModerationRule2,
544
- ButtonStyles: () => ButtonStyles,
545
- Channel: () => Channel2,
546
- ComponentType: () => ComponentType,
547
- DeviceType: () => DeviceType,
548
- GatewayIntent: () => GatewayIntent,
549
- GatewayOpcode: () => GatewayOpcode,
550
- Guild: () => Guild3,
551
- GuildFeature: () => GuildFeature,
552
- GuildScheduledEvent: () => GuildScheduledEvent3,
553
- IntegrationExpireBehavior: () => IntegrationExpireBehavior,
554
- InteractionCallbackType: () => InteractionCallbackType,
555
- InteractionType: () => InteractionType,
556
- Internal: () => Internal,
557
- Invite: () => Invite,
558
- MembershipState: () => MembershipState,
559
- Message: () => Message2,
560
- OverwriteType: () => OverwriteType,
561
- Permission: () => Permission,
562
- PremiumType: () => PremiumType,
563
- StatusType: () => StatusType2,
564
- Sticker: () => Sticker3,
565
- SystemChannelFlag: () => SystemChannelFlag,
566
- TextInputStyles: () => TextInputStyles,
567
- UserFlag: () => UserFlag,
568
- VisibilityType: () => VisibilityType,
569
- Webhook: () => Webhook2
570
- });
571
-
572
- // satori/adapters/discord/src/types/internal.ts
573
- var import_satori3 = require("@satorijs/satori");
574
- var Internal = class {
575
- constructor(http) {
576
- this.http = http;
577
- }
578
- static define(routes) {
579
- for (const path in routes) {
580
- for (const key in routes[path]) {
581
- const method = key;
582
- for (const name of (0, import_satori3.makeArray)(routes[path][method])) {
583
- Internal.prototype[name] = function(...args) {
584
- const raw = args.join(", ");
585
- const url = path.replace(/\{([^}]+)\}/g, () => {
586
- if (!args.length)
587
- throw new Error(`too few arguments for ${path}, received ${raw}`);
588
- return args.shift();
589
- });
590
- const config = {};
591
- if (args.length === 1) {
592
- if (method === "GET" || method === "DELETE") {
593
- config.params = args[0];
594
- } else {
595
- config.data = args[0];
596
- }
597
- } else if (args.length === 2 && method !== "GET" && method !== "DELETE") {
598
- config.data = args[0];
599
- config.params = args[1];
600
- } else if (args.length > 1) {
601
- throw new Error(`too many arguments for ${path}, received ${raw}`);
602
- }
603
- return this.http(method, url, config);
604
- };
605
- }
606
- }
607
- }
608
- }
609
- };
610
- __name(Internal, "Internal");
611
-
612
- // satori/adapters/discord/src/types/application.ts
613
- var ApplicationFlag = /* @__PURE__ */ ((ApplicationFlag2) => {
614
- ApplicationFlag2[ApplicationFlag2["GATEWAY_PRESENCE"] = 4096] = "GATEWAY_PRESENCE";
615
- ApplicationFlag2[ApplicationFlag2["GATEWAY_PRESENCE_LIMITED"] = 8192] = "GATEWAY_PRESENCE_LIMITED";
616
- ApplicationFlag2[ApplicationFlag2["GATEWAY_GUILD_MEMBERS"] = 16384] = "GATEWAY_GUILD_MEMBERS";
617
- ApplicationFlag2[ApplicationFlag2["GATEWAY_GUILD_MEMBERS_LIMITED"] = 32768] = "GATEWAY_GUILD_MEMBERS_LIMITED";
618
- ApplicationFlag2[ApplicationFlag2["VERIFICATION_PENDING_GUILD_LIMIT"] = 65536] = "VERIFICATION_PENDING_GUILD_LIMIT";
619
- ApplicationFlag2[ApplicationFlag2["EMBEDDED"] = 131072] = "EMBEDDED";
620
- ApplicationFlag2[ApplicationFlag2["GATEWAY_MESSAGE_CONTENT"] = 262144] = "GATEWAY_MESSAGE_CONTENT";
621
- ApplicationFlag2[ApplicationFlag2["GATEWAY_MESSAGE_CONTENT_LIMITED"] = 524288] = "GATEWAY_MESSAGE_CONTENT_LIMITED";
622
- ApplicationFlag2[ApplicationFlag2["APPLICATION_COMMAND_BADGE"] = 8388608] = "APPLICATION_COMMAND_BADGE";
623
- return ApplicationFlag2;
624
- })(ApplicationFlag || {});
625
- Internal.define({
626
- "/oauth2/applications/@me": {
627
- GET: "getCurrentBotApplicationInformation"
628
- },
629
- "/oauth2/@me": {
630
- GET: "getCurrentAuthorizationInformation"
631
- }
632
- });
633
-
634
- // satori/adapters/discord/src/types/application-role-connection.ts
635
- var ApplicationRoleConnection;
636
- ((ApplicationRoleConnection2) => {
637
- let MetadataType;
638
- ((MetadataType2) => {
639
- MetadataType2[MetadataType2["INTEGER_LESS_THAN_OR_EQUAL"] = 1] = "INTEGER_LESS_THAN_OR_EQUAL";
640
- MetadataType2[MetadataType2["INTEGER_GREATER_THAN_OR_EQUAL"] = 2] = "INTEGER_GREATER_THAN_OR_EQUAL";
641
- MetadataType2[MetadataType2["INTEGER_EQUAL"] = 3] = "INTEGER_EQUAL";
642
- MetadataType2[MetadataType2["INTEGER_NOT_EQUAL"] = 4] = "INTEGER_NOT_EQUAL";
643
- MetadataType2[MetadataType2["DATETIME_LESS_THAN_OR_EQUAL"] = 5] = "DATETIME_LESS_THAN_OR_EQUAL";
644
- MetadataType2[MetadataType2["DATETIME_GREATER_THAN_OR_EQUAL"] = 6] = "DATETIME_GREATER_THAN_OR_EQUAL";
645
- MetadataType2[MetadataType2["BOOLEAN_EQUAL"] = 7] = "BOOLEAN_EQUAL";
646
- MetadataType2[MetadataType2["BOOLEAN_NOT_EQUAL"] = 8] = "BOOLEAN_NOT_EQUAL";
647
- })(MetadataType = ApplicationRoleConnection2.MetadataType || (ApplicationRoleConnection2.MetadataType = {}));
648
- })(ApplicationRoleConnection || (ApplicationRoleConnection = {}));
649
- Internal.define({
650
- "/applications/{application.id}/role-connections/metadata": {
651
- GET: "getApplicationRoleConnectionMetadataRecords",
652
- PUT: "updateApplicationRoleConnectionMetadataRecords"
653
- }
654
- });
184
+ });
655
185
 
656
186
  // satori/adapters/discord/src/types/audit-log.ts
657
187
  var AuditLog;
@@ -947,42 +477,45 @@ Internal.define({
947
477
  });
948
478
 
949
479
  // satori/adapters/discord/src/types/gateway.ts
950
- var GatewayOpcode = /* @__PURE__ */ ((GatewayOpcode2) => {
951
- GatewayOpcode2[GatewayOpcode2["DISPATCH"] = 0] = "DISPATCH";
952
- GatewayOpcode2[GatewayOpcode2["HEARTBEAT"] = 1] = "HEARTBEAT";
953
- GatewayOpcode2[GatewayOpcode2["IDENTIFY"] = 2] = "IDENTIFY";
954
- GatewayOpcode2[GatewayOpcode2["PRESENCE_UPDATE"] = 3] = "PRESENCE_UPDATE";
955
- GatewayOpcode2[GatewayOpcode2["VOICE_STATE_UPDATE"] = 4] = "VOICE_STATE_UPDATE";
956
- GatewayOpcode2[GatewayOpcode2["RESUME"] = 6] = "RESUME";
957
- GatewayOpcode2[GatewayOpcode2["RECONNECT"] = 7] = "RECONNECT";
958
- GatewayOpcode2[GatewayOpcode2["REQUEST_GUILD_MEMBERS"] = 8] = "REQUEST_GUILD_MEMBERS";
959
- GatewayOpcode2[GatewayOpcode2["INVALID_SESSION"] = 9] = "INVALID_SESSION";
960
- GatewayOpcode2[GatewayOpcode2["HELLO"] = 10] = "HELLO";
961
- GatewayOpcode2[GatewayOpcode2["HEARTBEAT_ACK"] = 11] = "HEARTBEAT_ACK";
962
- return GatewayOpcode2;
963
- })(GatewayOpcode || {});
964
- var GatewayIntent = /* @__PURE__ */ ((GatewayIntent2) => {
965
- GatewayIntent2[GatewayIntent2["GUILDS"] = 1] = "GUILDS";
966
- GatewayIntent2[GatewayIntent2["GUILD_MEMBERS"] = 2] = "GUILD_MEMBERS";
967
- GatewayIntent2[GatewayIntent2["GUILD_BANS"] = 4] = "GUILD_BANS";
968
- GatewayIntent2[GatewayIntent2["GUILD_EMOJIS_AND_STICKERS"] = 8] = "GUILD_EMOJIS_AND_STICKERS";
969
- GatewayIntent2[GatewayIntent2["GUILD_INTEGRATIONS"] = 16] = "GUILD_INTEGRATIONS";
970
- GatewayIntent2[GatewayIntent2["GUILD_WEBHOOKS"] = 32] = "GUILD_WEBHOOKS";
971
- GatewayIntent2[GatewayIntent2["GUILD_INVITES"] = 64] = "GUILD_INVITES";
972
- GatewayIntent2[GatewayIntent2["GUILD_VOICE_STATES"] = 128] = "GUILD_VOICE_STATES";
973
- GatewayIntent2[GatewayIntent2["GUILD_PRESENCES"] = 256] = "GUILD_PRESENCES";
974
- GatewayIntent2[GatewayIntent2["GUILD_MESSAGES"] = 512] = "GUILD_MESSAGES";
975
- GatewayIntent2[GatewayIntent2["GUILD_MESSAGE_REACTIONS"] = 1024] = "GUILD_MESSAGE_REACTIONS";
976
- GatewayIntent2[GatewayIntent2["GUILD_MESSAGE_TYPING"] = 2048] = "GUILD_MESSAGE_TYPING";
977
- GatewayIntent2[GatewayIntent2["DIRECT_MESSAGES"] = 4096] = "DIRECT_MESSAGES";
978
- GatewayIntent2[GatewayIntent2["DIRECT_MESSAGE_REACTIONS"] = 8192] = "DIRECT_MESSAGE_REACTIONS";
979
- GatewayIntent2[GatewayIntent2["DIRECT_MESSAGE_TYPING"] = 16384] = "DIRECT_MESSAGE_TYPING";
980
- GatewayIntent2[GatewayIntent2["MESSAGE_CONTENT"] = 32768] = "MESSAGE_CONTENT";
981
- GatewayIntent2[GatewayIntent2["GUILD_SCHEDULED_EVENTS"] = 65536] = "GUILD_SCHEDULED_EVENTS";
982
- GatewayIntent2[GatewayIntent2["AUTO_MODERATION_CONFIGURATION"] = 1048576] = "AUTO_MODERATION_CONFIGURATION";
983
- GatewayIntent2[GatewayIntent2["AUTO_MODERATION_EXECUTION"] = 2097152] = "AUTO_MODERATION_EXECUTION";
984
- return GatewayIntent2;
985
- })(GatewayIntent || {});
480
+ var Gateway;
481
+ ((Gateway3) => {
482
+ let Opcode;
483
+ ((Opcode2) => {
484
+ Opcode2[Opcode2["DISPATCH"] = 0] = "DISPATCH";
485
+ Opcode2[Opcode2["HEARTBEAT"] = 1] = "HEARTBEAT";
486
+ Opcode2[Opcode2["IDENTIFY"] = 2] = "IDENTIFY";
487
+ Opcode2[Opcode2["PRESENCE_UPDATE"] = 3] = "PRESENCE_UPDATE";
488
+ Opcode2[Opcode2["VOICE_STATE_UPDATE"] = 4] = "VOICE_STATE_UPDATE";
489
+ Opcode2[Opcode2["RESUME"] = 6] = "RESUME";
490
+ Opcode2[Opcode2["RECONNECT"] = 7] = "RECONNECT";
491
+ Opcode2[Opcode2["REQUEST_GUILD_MEMBERS"] = 8] = "REQUEST_GUILD_MEMBERS";
492
+ Opcode2[Opcode2["INVALID_SESSION"] = 9] = "INVALID_SESSION";
493
+ Opcode2[Opcode2["HELLO"] = 10] = "HELLO";
494
+ Opcode2[Opcode2["HEARTBEAT_ACK"] = 11] = "HEARTBEAT_ACK";
495
+ })(Opcode = Gateway3.Opcode || (Gateway3.Opcode = {}));
496
+ let Intent;
497
+ ((Intent2) => {
498
+ Intent2[Intent2["GUILDS"] = 1] = "GUILDS";
499
+ Intent2[Intent2["GUILD_MEMBERS"] = 2] = "GUILD_MEMBERS";
500
+ Intent2[Intent2["GUILD_BANS"] = 4] = "GUILD_BANS";
501
+ Intent2[Intent2["GUILD_EMOJIS_AND_STICKERS"] = 8] = "GUILD_EMOJIS_AND_STICKERS";
502
+ Intent2[Intent2["GUILD_INTEGRATIONS"] = 16] = "GUILD_INTEGRATIONS";
503
+ Intent2[Intent2["GUILD_WEBHOOKS"] = 32] = "GUILD_WEBHOOKS";
504
+ Intent2[Intent2["GUILD_INVITES"] = 64] = "GUILD_INVITES";
505
+ Intent2[Intent2["GUILD_VOICE_STATES"] = 128] = "GUILD_VOICE_STATES";
506
+ Intent2[Intent2["GUILD_PRESENCES"] = 256] = "GUILD_PRESENCES";
507
+ Intent2[Intent2["GUILD_MESSAGES"] = 512] = "GUILD_MESSAGES";
508
+ Intent2[Intent2["GUILD_MESSAGE_REACTIONS"] = 1024] = "GUILD_MESSAGE_REACTIONS";
509
+ Intent2[Intent2["GUILD_MESSAGE_TYPING"] = 2048] = "GUILD_MESSAGE_TYPING";
510
+ Intent2[Intent2["DIRECT_MESSAGES"] = 4096] = "DIRECT_MESSAGES";
511
+ Intent2[Intent2["DIRECT_MESSAGE_REACTIONS"] = 8192] = "DIRECT_MESSAGE_REACTIONS";
512
+ Intent2[Intent2["DIRECT_MESSAGE_TYPING"] = 16384] = "DIRECT_MESSAGE_TYPING";
513
+ Intent2[Intent2["MESSAGE_CONTENT"] = 32768] = "MESSAGE_CONTENT";
514
+ Intent2[Intent2["GUILD_SCHEDULED_EVENTS"] = 65536] = "GUILD_SCHEDULED_EVENTS";
515
+ Intent2[Intent2["AUTO_MODERATION_CONFIGURATION"] = 1048576] = "AUTO_MODERATION_CONFIGURATION";
516
+ Intent2[Intent2["AUTO_MODERATION_EXECUTION"] = 2097152] = "AUTO_MODERATION_EXECUTION";
517
+ })(Intent = Gateway3.Intent || (Gateway3.Intent = {}));
518
+ })(Gateway || (Gateway = {}));
986
519
  Internal.define({
987
520
  "/gateway": {
988
521
  GET: "getGateway"
@@ -1140,24 +673,29 @@ Internal.define({
1140
673
  });
1141
674
 
1142
675
  // satori/adapters/discord/src/types/interaction.ts
1143
- var InteractionType = /* @__PURE__ */ ((InteractionType2) => {
1144
- InteractionType2[InteractionType2["PING"] = 1] = "PING";
1145
- InteractionType2[InteractionType2["APPLICATION_COMMAND"] = 2] = "APPLICATION_COMMAND";
1146
- InteractionType2[InteractionType2["MESSAGE_COMPONENT"] = 3] = "MESSAGE_COMPONENT";
1147
- InteractionType2[InteractionType2["APPLICATION_COMMAND_AUTOCOMPLETE"] = 4] = "APPLICATION_COMMAND_AUTOCOMPLETE";
1148
- InteractionType2[InteractionType2["MODAL_SUBMIT"] = 5] = "MODAL_SUBMIT";
1149
- return InteractionType2;
1150
- })(InteractionType || {});
1151
- var InteractionCallbackType = /* @__PURE__ */ ((InteractionCallbackType2) => {
1152
- InteractionCallbackType2[InteractionCallbackType2["PONG"] = 1] = "PONG";
1153
- InteractionCallbackType2[InteractionCallbackType2["CHANNEL_MESSAGE_WITH_SOURCE"] = 4] = "CHANNEL_MESSAGE_WITH_SOURCE";
1154
- InteractionCallbackType2[InteractionCallbackType2["DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE"] = 5] = "DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE";
1155
- InteractionCallbackType2[InteractionCallbackType2["DEFERRED_UPDATE_MESSAGE"] = 6] = "DEFERRED_UPDATE_MESSAGE";
1156
- InteractionCallbackType2[InteractionCallbackType2["UPDATE_MESSAGE"] = 7] = "UPDATE_MESSAGE";
1157
- InteractionCallbackType2[InteractionCallbackType2["APPLICATION_COMMAND_AUTOCOMPLETE_RESULT"] = 8] = "APPLICATION_COMMAND_AUTOCOMPLETE_RESULT";
1158
- InteractionCallbackType2[InteractionCallbackType2["MODAL"] = 9] = "MODAL";
1159
- return InteractionCallbackType2;
1160
- })(InteractionCallbackType || {});
676
+ var Interaction;
677
+ ((Interaction2) => {
678
+ let Type;
679
+ ((Type2) => {
680
+ Type2[Type2["PING"] = 1] = "PING";
681
+ Type2[Type2["APPLICATION_COMMAND"] = 2] = "APPLICATION_COMMAND";
682
+ Type2[Type2["MESSAGE_COMPONENT"] = 3] = "MESSAGE_COMPONENT";
683
+ Type2[Type2["APPLICATION_COMMAND_AUTOCOMPLETE"] = 4] = "APPLICATION_COMMAND_AUTOCOMPLETE";
684
+ Type2[Type2["MODAL_SUBMIT"] = 5] = "MODAL_SUBMIT";
685
+ })(Type = Interaction2.Type || (Interaction2.Type = {}));
686
+ })(Interaction || (Interaction = {}));
687
+ ((Interaction2) => {
688
+ let CallbackType;
689
+ ((CallbackType2) => {
690
+ CallbackType2[CallbackType2["PONG"] = 1] = "PONG";
691
+ CallbackType2[CallbackType2["CHANNEL_MESSAGE_WITH_SOURCE"] = 4] = "CHANNEL_MESSAGE_WITH_SOURCE";
692
+ CallbackType2[CallbackType2["DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE"] = 5] = "DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE";
693
+ CallbackType2[CallbackType2["DEFERRED_UPDATE_MESSAGE"] = 6] = "DEFERRED_UPDATE_MESSAGE";
694
+ CallbackType2[CallbackType2["UPDATE_MESSAGE"] = 7] = "UPDATE_MESSAGE";
695
+ CallbackType2[CallbackType2["APPLICATION_COMMAND_AUTOCOMPLETE_RESULT"] = 8] = "APPLICATION_COMMAND_AUTOCOMPLETE_RESULT";
696
+ CallbackType2[CallbackType2["MODAL"] = 9] = "MODAL";
697
+ })(CallbackType = Interaction2.CallbackType || (Interaction2.CallbackType = {}));
698
+ })(Interaction || (Interaction = {}));
1161
699
  Internal.define({
1162
700
  "/interactions/{interaction.id}/{interaction.token}/callback": {
1163
701
  POST: "createInteractionResponse"
@@ -1311,302 +849,923 @@ var ActivityFlag = /* @__PURE__ */ ((ActivityFlag2) => {
1311
849
  return ActivityFlag2;
1312
850
  })(ActivityFlag || {});
1313
851
 
1314
- // satori/adapters/discord/src/types/reaction.ts
852
+ // satori/adapters/discord/src/types/reaction.ts
853
+ Internal.define({
854
+ "/channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me": {
855
+ PUT: "createReaction",
856
+ DELETE: "deleteOwnReaction"
857
+ },
858
+ "/channels/{channel.id}/messages/{message.id}/reactions/{emoji}/{user.id}": {
859
+ DELETE: "deleteUserReaction"
860
+ },
861
+ "/channels/{channel.id}/messages/{message.id}/reactions/{emoji}": {
862
+ GET: "getReactions",
863
+ DELETE: "deleteAllReactionsforEmoji"
864
+ },
865
+ "/channels/{channel.id}/messages/{message.id}/reactions": {
866
+ DELETE: "deleteAllReactions"
867
+ }
868
+ });
869
+
870
+ // satori/adapters/discord/src/types/role.ts
871
+ var Permission = /* @__PURE__ */ ((Permission2) => {
872
+ Permission2[Permission2["CREATE_INSTANT_INVITE"] = 1] = "CREATE_INSTANT_INVITE";
873
+ Permission2[Permission2["KICK_MEMBERS"] = 2] = "KICK_MEMBERS";
874
+ Permission2[Permission2["BAN_MEMBERS"] = 4] = "BAN_MEMBERS";
875
+ Permission2[Permission2["ADMINISTRATOR"] = 8] = "ADMINISTRATOR";
876
+ Permission2[Permission2["MANAGE_CHANNELS"] = 16] = "MANAGE_CHANNELS";
877
+ Permission2[Permission2["MANAGE_GUILD"] = 32] = "MANAGE_GUILD";
878
+ Permission2[Permission2["ADD_REACTIONS"] = 64] = "ADD_REACTIONS";
879
+ Permission2[Permission2["VIEW_AUDIT_LOG"] = 128] = "VIEW_AUDIT_LOG";
880
+ Permission2[Permission2["PRIORITY_SPEAKER"] = 256] = "PRIORITY_SPEAKER";
881
+ Permission2[Permission2["STREAM"] = 512] = "STREAM";
882
+ Permission2[Permission2["VIEW_CHANNEL"] = 1024] = "VIEW_CHANNEL";
883
+ Permission2[Permission2["SEND_MESSAGES"] = 2048] = "SEND_MESSAGES";
884
+ Permission2[Permission2["SEND_TTS_MESSAGES"] = 4096] = "SEND_TTS_MESSAGES";
885
+ Permission2[Permission2["MANAGE_MESSAGES"] = 8192] = "MANAGE_MESSAGES";
886
+ Permission2[Permission2["EMBED_LINKS"] = 16384] = "EMBED_LINKS";
887
+ Permission2[Permission2["ATTACH_FILES"] = 32768] = "ATTACH_FILES";
888
+ Permission2[Permission2["READ_MESSAGE_HISTORY"] = 65536] = "READ_MESSAGE_HISTORY";
889
+ Permission2[Permission2["MENTION_EVERYONE"] = 131072] = "MENTION_EVERYONE";
890
+ Permission2[Permission2["USE_EXTERNAL_EMOJIS"] = 262144] = "USE_EXTERNAL_EMOJIS";
891
+ Permission2[Permission2["VIEW_GUILD_INSIGHTS"] = 524288] = "VIEW_GUILD_INSIGHTS";
892
+ Permission2[Permission2["CONNECT"] = 1048576] = "CONNECT";
893
+ Permission2[Permission2["SPEAK"] = 2097152] = "SPEAK";
894
+ Permission2[Permission2["MUTE_MEMBERS"] = 4194304] = "MUTE_MEMBERS";
895
+ Permission2[Permission2["DEAFEN_MEMBERS"] = 8388608] = "DEAFEN_MEMBERS";
896
+ Permission2[Permission2["MOVE_MEMBERS"] = 16777216] = "MOVE_MEMBERS";
897
+ Permission2[Permission2["USE_VAD"] = 33554432] = "USE_VAD";
898
+ Permission2[Permission2["CHANGE_NICKNAME"] = 67108864] = "CHANGE_NICKNAME";
899
+ Permission2[Permission2["MANAGE_NICKNAMES"] = 134217728] = "MANAGE_NICKNAMES";
900
+ Permission2[Permission2["MANAGE_ROLES"] = 268435456] = "MANAGE_ROLES";
901
+ Permission2[Permission2["MANAGE_WEBHOOKS"] = 536870912] = "MANAGE_WEBHOOKS";
902
+ Permission2[Permission2["MANAGE_EMOJIS_AND_STICKERS"] = 1073741824] = "MANAGE_EMOJIS_AND_STICKERS";
903
+ Permission2[Permission2["USE_APPLICATION_COMMANDS"] = -2147483648] = "USE_APPLICATION_COMMANDS";
904
+ Permission2[Permission2["REQUEST_TO_SPEAK"] = 1] = "REQUEST_TO_SPEAK";
905
+ Permission2[Permission2["MANAGE_THREADS"] = 4] = "MANAGE_THREADS";
906
+ Permission2[Permission2["CREATE_PUBLIC_THREADS"] = 8] = "CREATE_PUBLIC_THREADS";
907
+ Permission2[Permission2["CREATE_PRIVATE_THREADS"] = 16] = "CREATE_PRIVATE_THREADS";
908
+ Permission2[Permission2["USE_EXTERNAL_STICKERS"] = 32] = "USE_EXTERNAL_STICKERS";
909
+ Permission2[Permission2["SEND_MESSAGES_IN_THREADS"] = 64] = "SEND_MESSAGES_IN_THREADS";
910
+ Permission2[Permission2["START_EMBEDDED_ACTIVITIES"] = 128] = "START_EMBEDDED_ACTIVITIES";
911
+ Permission2[Permission2["MODERATE_MEMBERS"] = 256] = "MODERATE_MEMBERS";
912
+ return Permission2;
913
+ })(Permission || {});
914
+ Internal.define({
915
+ "/guilds/{guild.id}/roles": {
916
+ GET: "getGuildRoles",
917
+ POST: "createGuildRole",
918
+ PATCH: "modifyGuildRolePositions"
919
+ },
920
+ "/guilds/{guild.id}/roles/{role.id}": {
921
+ PATCH: "modifyGuildRole",
922
+ DELETE: "deleteGuildRole"
923
+ }
924
+ });
925
+
926
+ // satori/adapters/discord/src/types/scheduled-event.ts
927
+ var GuildScheduledEvent3;
928
+ ((GuildScheduledEvent4) => {
929
+ let PrivacyLevel;
930
+ ((PrivacyLevel2) => {
931
+ PrivacyLevel2[PrivacyLevel2["GUILD_ONLY"] = 2] = "GUILD_ONLY";
932
+ })(PrivacyLevel = GuildScheduledEvent4.PrivacyLevel || (GuildScheduledEvent4.PrivacyLevel = {}));
933
+ let EntityType;
934
+ ((EntityType2) => {
935
+ EntityType2[EntityType2["STAGE_INSTANCE"] = 1] = "STAGE_INSTANCE";
936
+ EntityType2[EntityType2["VOICE"] = 2] = "VOICE";
937
+ EntityType2[EntityType2["EXTERNAL"] = 3] = "EXTERNAL";
938
+ })(EntityType = GuildScheduledEvent4.EntityType || (GuildScheduledEvent4.EntityType = {}));
939
+ let Status;
940
+ ((Status2) => {
941
+ Status2[Status2["SCHEDULED"] = 1] = "SCHEDULED";
942
+ Status2[Status2["ACTIVE"] = 2] = "ACTIVE";
943
+ Status2[Status2["COMPLETED"] = 3] = "COMPLETED";
944
+ Status2[Status2["CANCELLED"] = 4] = "CANCELLED";
945
+ })(Status = GuildScheduledEvent4.Status || (GuildScheduledEvent4.Status = {}));
946
+ })(GuildScheduledEvent3 || (GuildScheduledEvent3 = {}));
947
+ Internal.define({
948
+ "/guilds/{guild.id}/scheduled-events": {
949
+ GET: "listScheduledEventsforGuild",
950
+ POST: "createGuildScheduledEvent"
951
+ },
952
+ "/guilds/{guild.id}/scheduled-events/{guild_scheduled_event.id}": {
953
+ GET: "getGuildScheduledEvent",
954
+ PATCH: "modifyGuildScheduledEvent",
955
+ DELETE: "deleteGuildScheduledEvent"
956
+ },
957
+ "/guilds/{guild.id}/scheduled-events/{guild_scheduled_event.id}/users": {
958
+ GET: "getGuildScheduledEventUsers"
959
+ }
960
+ });
961
+
962
+ // satori/adapters/discord/src/types/stage-instance.ts
963
+ Internal.define({
964
+ "/stage-instances": {
965
+ POST: "createStageInstance"
966
+ },
967
+ "/stage-instances/{channel.id}": {
968
+ GET: "getStageInstance",
969
+ PATCH: "modifyStageInstance",
970
+ DELETE: "deleteStageInstance"
971
+ }
972
+ });
973
+
974
+ // satori/adapters/discord/src/types/sticker.ts
975
+ var Sticker3;
976
+ ((Sticker4) => {
977
+ let Type;
978
+ ((Type2) => {
979
+ Type2[Type2["STANDARD"] = 1] = "STANDARD";
980
+ Type2[Type2["GUILD"] = 2] = "GUILD";
981
+ })(Type = Sticker4.Type || (Sticker4.Type = {}));
982
+ let FormatType;
983
+ ((FormatType2) => {
984
+ FormatType2[FormatType2["PNG"] = 1] = "PNG";
985
+ FormatType2[FormatType2["APNG"] = 2] = "APNG";
986
+ FormatType2[FormatType2["LOTTIE"] = 3] = "LOTTIE";
987
+ FormatType2[FormatType2["GIF"] = 4] = "GIF";
988
+ })(FormatType = Sticker4.FormatType || (Sticker4.FormatType = {}));
989
+ })(Sticker3 || (Sticker3 = {}));
990
+ Internal.define({
991
+ "/stickers/{sticker.id}": {
992
+ GET: "getSticker"
993
+ },
994
+ "/sticker-packs": {
995
+ GET: "listNitroStickerPacks"
996
+ },
997
+ "/guilds/{guild.id}/stickers": {
998
+ GET: "listGuildStickers",
999
+ POST: "createGuildSticker"
1000
+ },
1001
+ "/guilds/{guild.id}/stickers/{sticker.id}": {
1002
+ GET: "getGuildSticker",
1003
+ PATCH: "modifyGuildSticker",
1004
+ DELETE: "deleteGuildSticker"
1005
+ }
1006
+ });
1007
+
1008
+ // satori/adapters/discord/src/types/team.ts
1009
+ var MembershipState = /* @__PURE__ */ ((MembershipState2) => {
1010
+ MembershipState2[MembershipState2["INVITED"] = 1] = "INVITED";
1011
+ MembershipState2[MembershipState2["ACCEPTED"] = 2] = "ACCEPTED";
1012
+ return MembershipState2;
1013
+ })(MembershipState || {});
1014
+
1015
+ // satori/adapters/discord/src/types/thread.ts
1016
+ Internal.define({
1017
+ "/channels/{channel.id}/messages/{message.id}/threads": {
1018
+ POST: "startThreadFromMessage"
1019
+ },
1020
+ "/channels/{channel.id}/threads": {
1021
+ POST: ["startThreadWithoutMessage", "startThreadInForumChannel"]
1022
+ },
1023
+ "/channels/{channel.id}/thread-members/@me": {
1024
+ PUT: "joinThread",
1025
+ DELETE: "leaveThread"
1026
+ },
1027
+ "/channels/{channel.id}/thread-members/{user.id}": {
1028
+ PUT: "addThreadMember",
1029
+ DELETE: "removeThreadMember",
1030
+ GET: "getThreadMember"
1031
+ },
1032
+ "/channels/{channel.id}/thread-members": {
1033
+ GET: "listThreadMembers"
1034
+ },
1035
+ "/channels/{channel.id}/threads/archived/public": {
1036
+ GET: "listPublicArchivedThreads"
1037
+ },
1038
+ "/channels/{channel.id}/threads/archived/private": {
1039
+ GET: "listPrivateArchivedThreads"
1040
+ },
1041
+ "/channels/{channel.id}/users/@me/threads/archived/private": {
1042
+ GET: "listJoinedPrivateArchivedThreads"
1043
+ }
1044
+ });
1045
+
1046
+ // satori/adapters/discord/src/types/user.ts
1047
+ var UserFlag = /* @__PURE__ */ ((UserFlag2) => {
1048
+ UserFlag2[UserFlag2["NONE"] = 0] = "NONE";
1049
+ UserFlag2[UserFlag2["DISCORD_EMPLOYEE"] = 1] = "DISCORD_EMPLOYEE";
1050
+ UserFlag2[UserFlag2["PARTNERED_SERVER_OWNER"] = 2] = "PARTNERED_SERVER_OWNER";
1051
+ UserFlag2[UserFlag2["HYPESQUAD_EVENTS"] = 4] = "HYPESQUAD_EVENTS";
1052
+ UserFlag2[UserFlag2["BUG_HUNTER_LEVEL_1"] = 8] = "BUG_HUNTER_LEVEL_1";
1053
+ UserFlag2[UserFlag2["HOUSE_BRAVERY"] = 64] = "HOUSE_BRAVERY";
1054
+ UserFlag2[UserFlag2["HOUSE_BRILLIANCE"] = 128] = "HOUSE_BRILLIANCE";
1055
+ UserFlag2[UserFlag2["HOUSE_BALANCE"] = 256] = "HOUSE_BALANCE";
1056
+ UserFlag2[UserFlag2["EARLY_SUPPORTER"] = 512] = "EARLY_SUPPORTER";
1057
+ UserFlag2[UserFlag2["TEAM_USER"] = 1024] = "TEAM_USER";
1058
+ UserFlag2[UserFlag2["BUG_HUNTER_LEVEL_2"] = 16384] = "BUG_HUNTER_LEVEL_2";
1059
+ UserFlag2[UserFlag2["VERIFIED_BOT"] = 65536] = "VERIFIED_BOT";
1060
+ UserFlag2[UserFlag2["EARLY_VERIFIED_BOT_DEVELOPER"] = 131072] = "EARLY_VERIFIED_BOT_DEVELOPER";
1061
+ UserFlag2[UserFlag2["DISCORD_CERTIFIED_MODERATOR"] = 262144] = "DISCORD_CERTIFIED_MODERATOR";
1062
+ UserFlag2[UserFlag2["BOT_HTTP_INTERACTIONS"] = 524288] = "BOT_HTTP_INTERACTIONS";
1063
+ UserFlag2[UserFlag2["ACTIVE_DEVELOPER"] = 4194304] = "ACTIVE_DEVELOPER";
1064
+ return UserFlag2;
1065
+ })(UserFlag || {});
1066
+ var PremiumType = /* @__PURE__ */ ((PremiumType2) => {
1067
+ PremiumType2[PremiumType2["NONE"] = 0] = "NONE";
1068
+ PremiumType2[PremiumType2["NITRO_CLASSIC"] = 1] = "NITRO_CLASSIC";
1069
+ PremiumType2[PremiumType2["NITRO"] = 2] = "NITRO";
1070
+ PremiumType2[PremiumType2["NITRO_BASIC"] = 3] = "NITRO_BASIC";
1071
+ return PremiumType2;
1072
+ })(PremiumType || {});
1073
+ var VisibilityType = /* @__PURE__ */ ((VisibilityType2) => {
1074
+ VisibilityType2[VisibilityType2["NONE"] = 0] = "NONE";
1075
+ VisibilityType2[VisibilityType2["EVERYONE"] = 1] = "EVERYONE";
1076
+ return VisibilityType2;
1077
+ })(VisibilityType || {});
1078
+ Internal.define({
1079
+ "/users/@me": {
1080
+ GET: "getCurrentUser",
1081
+ PATCH: "modifyCurrentUser"
1082
+ },
1083
+ "/users/{user.id}": {
1084
+ GET: "getUser"
1085
+ },
1086
+ "/users/@me/connections": {
1087
+ GET: "getUserConnections"
1088
+ }
1089
+ });
1090
+
1091
+ // satori/adapters/discord/src/types/voice.ts
1315
1092
  Internal.define({
1316
- "/channels/{channel.id}/messages/{message.id}/reactions/{emoji}/@me": {
1317
- PUT: "createReaction",
1318
- DELETE: "deleteOwnReaction"
1093
+ "/voice/regions": {
1094
+ GET: "listVoiceRegions"
1319
1095
  },
1320
- "/channels/{channel.id}/messages/{message.id}/reactions/{emoji}/{user.id}": {
1321
- DELETE: "deleteUserReaction"
1096
+ "/guilds/{guild.id}/regions": {
1097
+ GET: "getGuildVoiceRegions"
1322
1098
  },
1323
- "/channels/{channel.id}/messages/{message.id}/reactions/{emoji}": {
1324
- GET: "getReactions",
1325
- DELETE: "deleteAllReactionsforEmoji"
1099
+ "/guilds/{guild.id}/voice-states/@me": {
1100
+ PATCH: "modifyCurrentUserVoiceState"
1326
1101
  },
1327
- "/channels/{channel.id}/messages/{message.id}/reactions": {
1328
- DELETE: "deleteAllReactions"
1102
+ "/guilds/{guild.id}/voice-states/{user.id}": {
1103
+ PATCH: "modifyUserVoiceState"
1329
1104
  }
1330
1105
  });
1331
1106
 
1332
- // satori/adapters/discord/src/types/role.ts
1333
- var Permission = /* @__PURE__ */ ((Permission2) => {
1334
- Permission2[Permission2["CREATE_INSTANT_INVITE"] = 1] = "CREATE_INSTANT_INVITE";
1335
- Permission2[Permission2["KICK_MEMBERS"] = 2] = "KICK_MEMBERS";
1336
- Permission2[Permission2["BAN_MEMBERS"] = 4] = "BAN_MEMBERS";
1337
- Permission2[Permission2["ADMINISTRATOR"] = 8] = "ADMINISTRATOR";
1338
- Permission2[Permission2["MANAGE_CHANNELS"] = 16] = "MANAGE_CHANNELS";
1339
- Permission2[Permission2["MANAGE_GUILD"] = 32] = "MANAGE_GUILD";
1340
- Permission2[Permission2["ADD_REACTIONS"] = 64] = "ADD_REACTIONS";
1341
- Permission2[Permission2["VIEW_AUDIT_LOG"] = 128] = "VIEW_AUDIT_LOG";
1342
- Permission2[Permission2["PRIORITY_SPEAKER"] = 256] = "PRIORITY_SPEAKER";
1343
- Permission2[Permission2["STREAM"] = 512] = "STREAM";
1344
- Permission2[Permission2["VIEW_CHANNEL"] = 1024] = "VIEW_CHANNEL";
1345
- Permission2[Permission2["SEND_MESSAGES"] = 2048] = "SEND_MESSAGES";
1346
- Permission2[Permission2["SEND_TTS_MESSAGES"] = 4096] = "SEND_TTS_MESSAGES";
1347
- Permission2[Permission2["MANAGE_MESSAGES"] = 8192] = "MANAGE_MESSAGES";
1348
- Permission2[Permission2["EMBED_LINKS"] = 16384] = "EMBED_LINKS";
1349
- Permission2[Permission2["ATTACH_FILES"] = 32768] = "ATTACH_FILES";
1350
- Permission2[Permission2["READ_MESSAGE_HISTORY"] = 65536] = "READ_MESSAGE_HISTORY";
1351
- Permission2[Permission2["MENTION_EVERYONE"] = 131072] = "MENTION_EVERYONE";
1352
- Permission2[Permission2["USE_EXTERNAL_EMOJIS"] = 262144] = "USE_EXTERNAL_EMOJIS";
1353
- Permission2[Permission2["VIEW_GUILD_INSIGHTS"] = 524288] = "VIEW_GUILD_INSIGHTS";
1354
- Permission2[Permission2["CONNECT"] = 1048576] = "CONNECT";
1355
- Permission2[Permission2["SPEAK"] = 2097152] = "SPEAK";
1356
- Permission2[Permission2["MUTE_MEMBERS"] = 4194304] = "MUTE_MEMBERS";
1357
- Permission2[Permission2["DEAFEN_MEMBERS"] = 8388608] = "DEAFEN_MEMBERS";
1358
- Permission2[Permission2["MOVE_MEMBERS"] = 16777216] = "MOVE_MEMBERS";
1359
- Permission2[Permission2["USE_VAD"] = 33554432] = "USE_VAD";
1360
- Permission2[Permission2["CHANGE_NICKNAME"] = 67108864] = "CHANGE_NICKNAME";
1361
- Permission2[Permission2["MANAGE_NICKNAMES"] = 134217728] = "MANAGE_NICKNAMES";
1362
- Permission2[Permission2["MANAGE_ROLES"] = 268435456] = "MANAGE_ROLES";
1363
- Permission2[Permission2["MANAGE_WEBHOOKS"] = 536870912] = "MANAGE_WEBHOOKS";
1364
- Permission2[Permission2["MANAGE_EMOJIS_AND_STICKERS"] = 1073741824] = "MANAGE_EMOJIS_AND_STICKERS";
1365
- Permission2[Permission2["USE_APPLICATION_COMMANDS"] = -2147483648] = "USE_APPLICATION_COMMANDS";
1366
- Permission2[Permission2["REQUEST_TO_SPEAK"] = 1] = "REQUEST_TO_SPEAK";
1367
- Permission2[Permission2["MANAGE_THREADS"] = 4] = "MANAGE_THREADS";
1368
- Permission2[Permission2["CREATE_PUBLIC_THREADS"] = 8] = "CREATE_PUBLIC_THREADS";
1369
- Permission2[Permission2["CREATE_PRIVATE_THREADS"] = 16] = "CREATE_PRIVATE_THREADS";
1370
- Permission2[Permission2["USE_EXTERNAL_STICKERS"] = 32] = "USE_EXTERNAL_STICKERS";
1371
- Permission2[Permission2["SEND_MESSAGES_IN_THREADS"] = 64] = "SEND_MESSAGES_IN_THREADS";
1372
- Permission2[Permission2["START_EMBEDDED_ACTIVITIES"] = 128] = "START_EMBEDDED_ACTIVITIES";
1373
- Permission2[Permission2["MODERATE_MEMBERS"] = 256] = "MODERATE_MEMBERS";
1374
- return Permission2;
1375
- })(Permission || {});
1107
+ // satori/adapters/discord/src/types/webhook.ts
1108
+ var Webhook2;
1109
+ ((Webhook4) => {
1110
+ let Type;
1111
+ ((Type2) => {
1112
+ Type2[Type2["INCOMING"] = 1] = "INCOMING";
1113
+ Type2[Type2["CHANNEL_FOLLOWER"] = 2] = "CHANNEL_FOLLOWER";
1114
+ Type2[Type2["APPLICATION"] = 3] = "APPLICATION";
1115
+ })(Type = Webhook4.Type || (Webhook4.Type = {}));
1116
+ })(Webhook2 || (Webhook2 = {}));
1376
1117
  Internal.define({
1377
- "/guilds/{guild.id}/roles": {
1378
- GET: "getGuildRoles",
1379
- POST: "createGuildRole",
1380
- PATCH: "modifyGuildRolePositions"
1118
+ "/channels/{channel.id}/webhooks": {
1119
+ POST: "createWebhook",
1120
+ GET: "getChannelWebhooks"
1381
1121
  },
1382
- "/guilds/{guild.id}/roles/{role.id}": {
1383
- PATCH: "modifyGuildRole",
1384
- DELETE: "deleteGuildRole"
1122
+ "/guilds/{guild.id}/webhooks": {
1123
+ GET: "getGuildWebhooks"
1124
+ },
1125
+ "/webhooks/{webhook.id}": {
1126
+ GET: "getWebhook",
1127
+ PATCH: "modifyWebhook",
1128
+ DELETE: "deleteWebhook"
1129
+ },
1130
+ "/webhooks/{webhook.id}/{webhook.token}": {
1131
+ GET: "getWebhookwithToken",
1132
+ PATCH: "modifyWebhookwithToken",
1133
+ DELETE: "deleteWebhookwithToken",
1134
+ POST: "executeWebhook"
1135
+ },
1136
+ "/webhooks/{webhook.id}/{webhook.token}/slack": {
1137
+ POST: "executeSlackCompatibleWebhook"
1138
+ },
1139
+ "/webhooks/{webhook.id}/{webhook.token}/github": {
1140
+ POST: "executeGitHubCompatibleWebhook"
1141
+ },
1142
+ "/webhooks/{webhook.id}/{webhook.token}/messages/{message.id}": {
1143
+ GET: "getWebhookMessage",
1144
+ PATCH: "editWebhookMessage",
1145
+ DELETE: "deleteWebhookMessage"
1146
+ }
1147
+ });
1148
+
1149
+ // satori/adapters/discord/src/types/index.ts
1150
+ var Locale3 = [
1151
+ "da",
1152
+ "de",
1153
+ "en-GB",
1154
+ "en-US",
1155
+ "es-ES",
1156
+ "fr",
1157
+ "hr",
1158
+ "it",
1159
+ "lt",
1160
+ "hu",
1161
+ "nl",
1162
+ "no",
1163
+ "pl",
1164
+ "pt-BR",
1165
+ "ro",
1166
+ "fi",
1167
+ "sv-SE",
1168
+ "vi",
1169
+ "tr",
1170
+ "cs",
1171
+ "el",
1172
+ "bg",
1173
+ "ru",
1174
+ "uk",
1175
+ "hi",
1176
+ "th",
1177
+ "zh-CN",
1178
+ "ja",
1179
+ "zh-TW",
1180
+ "ko"
1181
+ ];
1182
+
1183
+ // satori/adapters/discord/src/utils.ts
1184
+ var sanitize = /* @__PURE__ */ __name((val) => val.replace(/[\\*_`~|()\[\]]/g, "\\$&").replace(/@everyone/g, () => "\\@everyone").replace(/@here/g, () => "\\@here"), "sanitize");
1185
+ var decodeUser = /* @__PURE__ */ __name((user) => ({
1186
+ userId: user.id,
1187
+ avatar: `https://cdn.discordapp.com/avatars/${user.id}/${user.avatar}.png`,
1188
+ username: user.username,
1189
+ discriminator: user.discriminator,
1190
+ isBot: user.bot || false
1191
+ }), "decodeUser");
1192
+ var decodeGuild = /* @__PURE__ */ __name((data) => ({
1193
+ guildId: data.id,
1194
+ guildName: data.name
1195
+ }), "decodeGuild");
1196
+ var decodeChannel = /* @__PURE__ */ __name((data) => ({
1197
+ channelId: data.id,
1198
+ channelName: data.name
1199
+ }), "decodeChannel");
1200
+ var decodeAuthor = /* @__PURE__ */ __name((author) => ({
1201
+ ...decodeUser(author),
1202
+ nickname: author.username
1203
+ }), "decodeAuthor");
1204
+ var decodeRole = /* @__PURE__ */ __name((role) => ({
1205
+ ...role,
1206
+ permissions: BigInt(role.permissions)
1207
+ }), "decodeRole");
1208
+ var encodeRole = /* @__PURE__ */ __name((role) => ({
1209
+ ...role,
1210
+ permissions: role.permissions && "" + role.permissions
1211
+ }), "encodeRole");
1212
+ async function decodeMessage(bot, meta, session = {}) {
1213
+ var _a, _b, _c;
1214
+ const { platform } = bot;
1215
+ setupMessage(session, meta);
1216
+ session.messageId = meta.id;
1217
+ session.timestamp = new Date(meta.timestamp).valueOf() || Date.now();
1218
+ if (meta.author) {
1219
+ session.author = decodeAuthor(meta.author);
1220
+ session.userId = meta.author.id;
1221
+ }
1222
+ if ((_a = meta.member) == null ? void 0 : _a.nick) {
1223
+ session.author.nickname = (_b = meta.member) == null ? void 0 : _b.nick;
1224
+ }
1225
+ session.content = "";
1226
+ if (meta.content) {
1227
+ session.content = meta.content.replace(/<@[!&]?(.+?)>/g, (_, id) => {
1228
+ var _a2;
1229
+ if (meta.mention_roles.includes(id)) {
1230
+ return (0, import_satori2.h)("at", { role: id }).toString();
1231
+ } else {
1232
+ const user = (_a2 = meta.mentions) == null ? void 0 : _a2.find((u) => u.id === id || `${u.username}#${u.discriminator}` === id);
1233
+ return import_satori2.h.at(id, { name: user == null ? void 0 : user.username }).toString();
1234
+ }
1235
+ }).replace(/<a?:(.*):(.+?)>/g, (_, name, id) => {
1236
+ const animated = _[1] === "a";
1237
+ return (0, import_satori2.h)("face", { id, name, animated, platform }, [
1238
+ import_satori2.h.image(`https://cdn.discordapp.com/emojis/${id}.gif?quality=lossless`)
1239
+ ]).toString();
1240
+ }).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) => {
1241
+ var _a2;
1242
+ const channel = (_a2 = meta.mention_channels) == null ? void 0 : _a2.find((c) => c.id === id);
1243
+ return import_satori2.h.sharp(id, { name: channel == null ? void 0 : channel.name }).toString();
1244
+ });
1245
+ }
1246
+ if ((_c = meta.attachments) == null ? void 0 : _c.length) {
1247
+ if (session.content)
1248
+ session.content += " ";
1249
+ session.content += meta.attachments.map((v) => {
1250
+ var _a2, _b2, _c2;
1251
+ if (v.height && v.width && ((_a2 = v.content_type) == null ? void 0 : _a2.startsWith("image/"))) {
1252
+ return (0, import_satori2.h)("image", {
1253
+ url: v.url,
1254
+ proxy_url: v.proxy_url,
1255
+ file: v.filename
1256
+ });
1257
+ } else if (v.height && v.width && ((_b2 = v.content_type) == null ? void 0 : _b2.startsWith("video/"))) {
1258
+ return (0, import_satori2.h)("video", {
1259
+ url: v.url,
1260
+ proxy_url: v.proxy_url,
1261
+ file: v.filename
1262
+ });
1263
+ } else if ((_c2 = v.content_type) == null ? void 0 : _c2.startsWith("audio/")) {
1264
+ return (0, import_satori2.h)("record", {
1265
+ url: v.url,
1266
+ proxy_url: v.proxy_url,
1267
+ file: v.filename
1268
+ });
1269
+ } else {
1270
+ return (0, import_satori2.h)("file", {
1271
+ url: v.url,
1272
+ proxy_url: v.proxy_url,
1273
+ file: v.filename
1274
+ });
1275
+ }
1276
+ }).join("");
1277
+ }
1278
+ for (const embed of meta.embeds) {
1279
+ if (embed.image) {
1280
+ session.content += (0, import_satori2.h)("image", { url: embed.image.url, proxy_url: embed.image.proxy_url });
1281
+ }
1282
+ if (embed.thumbnail) {
1283
+ session.content += (0, import_satori2.h)("image", { url: embed.thumbnail.url, proxy_url: embed.thumbnail.proxy_url });
1284
+ }
1285
+ if (embed.video) {
1286
+ session.content += (0, import_satori2.h)("video", { url: embed.video.url, proxy_url: embed.video.proxy_url });
1287
+ }
1288
+ }
1289
+ session.elements = import_satori2.h.parse(session.content);
1290
+ if (meta.message_reference) {
1291
+ const { message_id, channel_id } = meta.message_reference;
1292
+ session.quote = await bot.getMessage(channel_id, message_id);
1293
+ }
1294
+ return session;
1295
+ }
1296
+ __name(decodeMessage, "decodeMessage");
1297
+ function setupMessage(session, data) {
1298
+ session.guildId = data.guild_id;
1299
+ session.isDirect = !data.guild_id;
1300
+ session.subtype = data.guild_id ? "group" : "private";
1301
+ session.channelId = data.channel_id;
1302
+ }
1303
+ __name(setupMessage, "setupMessage");
1304
+ function setupReaction(session, data) {
1305
+ session.userId = data.user_id;
1306
+ session.messageId = data.message_id;
1307
+ session.guildId = data.guild_id;
1308
+ session.channelId = data.channel_id;
1309
+ session.isDirect = !data.guild_id;
1310
+ session.subtype = data.guild_id ? "group" : "private";
1311
+ if (!data.emoji)
1312
+ return;
1313
+ const { id, name } = data.emoji;
1314
+ session.content = id ? `${name}:${id}` : name;
1315
+ }
1316
+ __name(setupReaction, "setupReaction");
1317
+ async function adaptSession(bot, input) {
1318
+ const session = bot.session();
1319
+ if (input.t === "MESSAGE_CREATE") {
1320
+ if (input.d.webhook_id) {
1321
+ const webhook = await bot.ensureWebhook(input.d.channel_id);
1322
+ if (webhook.id === input.d.webhook_id) {
1323
+ return;
1324
+ }
1325
+ }
1326
+ session.type = "message";
1327
+ await decodeMessage(bot, input.d, session);
1328
+ } else if (input.t === "MESSAGE_UPDATE") {
1329
+ session.type = "message-updated";
1330
+ const msg = await bot.internal.getChannelMessage(input.d.channel_id, input.d.id);
1331
+ await decodeMessage(bot, msg, session);
1332
+ } else if (input.t === "MESSAGE_DELETE") {
1333
+ session.type = "message-deleted";
1334
+ session.messageId = input.d.id;
1335
+ setupMessage(session, input.d);
1336
+ } else if (input.t === "MESSAGE_REACTION_ADD") {
1337
+ session.type = "reaction-added";
1338
+ setupReaction(session, input.d);
1339
+ } else if (input.t === "MESSAGE_REACTION_REMOVE") {
1340
+ session.type = "reaction-deleted";
1341
+ session.subtype = "one";
1342
+ setupReaction(session, input.d);
1343
+ } else if (input.t === "MESSAGE_REACTION_REMOVE_ALL") {
1344
+ session.type = "reaction-deleted";
1345
+ session.subtype = "all";
1346
+ setupReaction(session, input.d);
1347
+ } else if (input.t === "MESSAGE_REACTION_REMOVE_EMOJI") {
1348
+ session.type = "reaction-deleted";
1349
+ session.subtype = "emoji";
1350
+ setupReaction(session, input.d);
1351
+ } else if (input.t === "GUILD_ROLE_CREATE") {
1352
+ session.type = "guild-role-added";
1353
+ session.guildId = input.d.guild_id;
1354
+ session.roleId = input.d.role.id;
1355
+ session.data.role = decodeRole(input.d.role);
1356
+ } else if (input.t === "GUILD_ROLE_UPDATE") {
1357
+ session.type = "guild-role-updated";
1358
+ session.guildId = input.d.guild_id;
1359
+ session.roleId = input.d.role.id;
1360
+ session.data.role = decodeRole(input.d.role);
1361
+ } else if (input.t === "GUILD_ROLE_DELETE") {
1362
+ session.type = "guild-role-added";
1363
+ session.guildId = input.d.guild_id;
1364
+ session.roleId = input.d.role_id;
1365
+ } else if (input.t === "INTERACTION_CREATE" && input.d.type === Interaction.Type.APPLICATION_COMMAND) {
1366
+ const data = input.d.data;
1367
+ const command = bot.commands.find((cmd) => cmd.name === data.name);
1368
+ if (!command)
1369
+ return;
1370
+ await bot.internal.createInteractionResponse(input.d.id, input.d.token, {
1371
+ type: Interaction.CallbackType.DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE
1372
+ });
1373
+ session.type = "interaction/command";
1374
+ session.isDirect = !input.d.guild_id;
1375
+ session.subtype = input.d.guild_id ? "group" : "private";
1376
+ session.channelId = input.d.channel_id;
1377
+ session.guildId = input.d.guild_id;
1378
+ session.userId = input.d.member.user.id;
1379
+ session.messageId = input.d.id;
1380
+ session.content = "";
1381
+ session.data.argv = decodeArgv(data, command);
1382
+ } else if (input.t === "CHANNEL_UPDATE") {
1383
+ session.type = "channel-updated";
1384
+ session.guildId = input.d.guild_id;
1385
+ session.subtype = input.d.guild_id ? "group" : "private";
1386
+ session.channelId = input.d.id;
1387
+ } else {
1388
+ return;
1385
1389
  }
1386
- });
1387
-
1388
- // satori/adapters/discord/src/types/scheduled-event.ts
1389
- var GuildScheduledEvent3;
1390
- ((GuildScheduledEvent4) => {
1391
- let PrivacyLevel;
1392
- ((PrivacyLevel2) => {
1393
- PrivacyLevel2[PrivacyLevel2["GUILD_ONLY"] = 2] = "GUILD_ONLY";
1394
- })(PrivacyLevel = GuildScheduledEvent4.PrivacyLevel || (GuildScheduledEvent4.PrivacyLevel = {}));
1395
- let EntityType;
1396
- ((EntityType2) => {
1397
- EntityType2[EntityType2["STAGE_INSTANCE"] = 1] = "STAGE_INSTANCE";
1398
- EntityType2[EntityType2["VOICE"] = 2] = "VOICE";
1399
- EntityType2[EntityType2["EXTERNAL"] = 3] = "EXTERNAL";
1400
- })(EntityType = GuildScheduledEvent4.EntityType || (GuildScheduledEvent4.EntityType = {}));
1401
- let Status;
1402
- ((Status2) => {
1403
- Status2[Status2["SCHEDULED"] = 1] = "SCHEDULED";
1404
- Status2[Status2["ACTIVE"] = 2] = "ACTIVE";
1405
- Status2[Status2["COMPLETED"] = 3] = "COMPLETED";
1406
- Status2[Status2["CANCELLED"] = 4] = "CANCELLED";
1407
- })(Status = GuildScheduledEvent4.Status || (GuildScheduledEvent4.Status = {}));
1408
- })(GuildScheduledEvent3 || (GuildScheduledEvent3 = {}));
1409
- Internal.define({
1410
- "/guilds/{guild.id}/scheduled-events": {
1411
- GET: "listScheduledEventsforGuild",
1412
- POST: "createGuildScheduledEvent"
1413
- },
1414
- "/guilds/{guild.id}/scheduled-events/{guild_scheduled_event.id}": {
1415
- GET: "getGuildScheduledEvent",
1416
- PATCH: "modifyGuildScheduledEvent",
1417
- DELETE: "deleteGuildScheduledEvent"
1418
- },
1419
- "/guilds/{guild.id}/scheduled-events/{guild_scheduled_event.id}/users": {
1420
- GET: "getGuildScheduledEventUsers"
1390
+ return session;
1391
+ }
1392
+ __name(adaptSession, "adaptSession");
1393
+ var types = {
1394
+ text: ApplicationCommand2.OptionType.STRING,
1395
+ string: ApplicationCommand2.OptionType.STRING,
1396
+ boolean: ApplicationCommand2.OptionType.BOOLEAN,
1397
+ number: ApplicationCommand2.OptionType.NUMBER,
1398
+ integer: ApplicationCommand2.OptionType.INTEGER,
1399
+ posint: ApplicationCommand2.OptionType.INTEGER,
1400
+ user: ApplicationCommand2.OptionType.STRING,
1401
+ channel: ApplicationCommand2.OptionType.STRING,
1402
+ guild: ApplicationCommand2.OptionType.STRING
1403
+ };
1404
+ var encodeCommand = /* @__PURE__ */ __name((cmd) => ({
1405
+ name: cmd.name,
1406
+ type: ApplicationCommand2.Type.CHAT_INPUT,
1407
+ description: cmd.description[""] || cmd.name,
1408
+ description_localizations: (0, import_satori2.pick)(cmd.description, Locale3),
1409
+ options: encodeCommandOptions(cmd)
1410
+ }), "encodeCommand");
1411
+ var decodeArgv = /* @__PURE__ */ __name((data, command) => {
1412
+ var _a, _b, _c, _d;
1413
+ const result = { name: data.name, arguments: [], options: {} };
1414
+ for (const argument of command.arguments) {
1415
+ const value = (_b = (_a = data.options) == null ? void 0 : _a.find((opt) => opt.name === argument.name)) == null ? void 0 : _b.value;
1416
+ if (value !== void 0)
1417
+ result.arguments.push(value);
1418
+ }
1419
+ for (const option of command.options) {
1420
+ const value = (_d = (_c = data.options) == null ? void 0 : _c.find((opt) => opt.name === option.name)) == null ? void 0 : _d.value;
1421
+ if (value !== void 0)
1422
+ result.options[option.name] = value;
1423
+ }
1424
+ return result;
1425
+ }, "decodeArgv");
1426
+ function encodeCommandOptions(cmd) {
1427
+ var _a, _b, _c, _d;
1428
+ const result = [];
1429
+ if (cmd.children.length) {
1430
+ result.push(...cmd.children.map((child) => ({
1431
+ name: child.name.slice(cmd.name.length + 1),
1432
+ type: child.children.length ? ApplicationCommand2.OptionType.SUB_COMMAND_GROUP : ApplicationCommand2.OptionType.SUB_COMMAND,
1433
+ options: encodeCommandOptions(child),
1434
+ description: cmd.description[""] || child.name,
1435
+ description_localizations: (0, import_satori2.pick)(cmd.description, Locale3)
1436
+ })));
1437
+ } else {
1438
+ for (const arg of cmd.arguments) {
1439
+ result.push({
1440
+ name: arg.name.toLowerCase().replace(/[^a-z0-9]/g, ""),
1441
+ description: arg.description[""] || arg.name,
1442
+ description_localizations: (0, import_satori2.pick)(arg.description, Locale3),
1443
+ type: (_a = types[arg.type]) != null ? _a : types.text,
1444
+ required: (_b = arg.required) != null ? _b : false
1445
+ });
1446
+ }
1447
+ for (const option of cmd.options) {
1448
+ result.push({
1449
+ name: option.name.toLowerCase(),
1450
+ description: option.description[""] || option.name,
1451
+ description_localizations: (0, import_satori2.pick)(option.description, Locale3),
1452
+ type: (_c = types[option.type]) != null ? _c : types.text,
1453
+ required: (_d = option.required) != null ? _d : false,
1454
+ min_value: option.type === "posint" ? 1 : void 0
1455
+ });
1456
+ }
1421
1457
  }
1422
- });
1458
+ return result.sort((a, b) => +b.required - +a.required);
1459
+ }
1460
+ __name(encodeCommandOptions, "encodeCommandOptions");
1423
1461
 
1424
- // satori/adapters/discord/src/types/stage-instance.ts
1425
- Internal.define({
1426
- "/stage-instances": {
1427
- POST: "createStageInstance"
1428
- },
1429
- "/stage-instances/{channel.id}": {
1430
- GET: "getStageInstance",
1431
- PATCH: "modifyStageInstance",
1432
- DELETE: "deleteStageInstance"
1462
+ // satori/adapters/discord/src/message.ts
1463
+ var import_satori3 = require("@satorijs/satori");
1464
+ var import_form_data = __toESM(require("form-data"));
1465
+ var logger = new import_satori3.Logger("discord");
1466
+ var State = class {
1467
+ // forward: send the first message and create a thread
1468
+ constructor(type) {
1469
+ this.type = type;
1470
+ this.author = {};
1471
+ this.quote = {};
1472
+ this.channel = {};
1473
+ this.fakeMessageMap = {};
1474
+ // [userInput] = discord messages
1475
+ this.threadCreated = false;
1433
1476
  }
1434
- });
1435
-
1436
- // satori/adapters/discord/src/types/sticker.ts
1437
- var Sticker3;
1438
- ((Sticker4) => {
1439
- let Type;
1440
- ((Type2) => {
1441
- Type2[Type2["STANDARD"] = 1] = "STANDARD";
1442
- Type2[Type2["GUILD"] = 2] = "GUILD";
1443
- })(Type = Sticker4.Type || (Sticker4.Type = {}));
1444
- let FormatType;
1445
- ((FormatType2) => {
1446
- FormatType2[FormatType2["PNG"] = 1] = "PNG";
1447
- FormatType2[FormatType2["APNG"] = 2] = "APNG";
1448
- FormatType2[FormatType2["LOTTIE"] = 3] = "LOTTIE";
1449
- FormatType2[FormatType2["GIF"] = 4] = "GIF";
1450
- })(FormatType = Sticker4.FormatType || (Sticker4.FormatType = {}));
1451
- })(Sticker3 || (Sticker3 = {}));
1452
- Internal.define({
1453
- "/stickers/{sticker.id}": {
1454
- GET: "getSticker"
1455
- },
1456
- "/sticker-packs": {
1457
- GET: "listNitroStickerPacks"
1458
- },
1459
- "/guilds/{guild.id}/stickers": {
1460
- GET: "listGuildStickers",
1461
- POST: "createGuildSticker"
1462
- },
1463
- "/guilds/{guild.id}/stickers/{sticker.id}": {
1464
- GET: "getGuildSticker",
1465
- PATCH: "modifyGuildSticker",
1466
- DELETE: "deleteGuildSticker"
1477
+ };
1478
+ __name(State, "State");
1479
+ var DiscordMessageEncoder = class extends import_satori3.MessageEncoder {
1480
+ constructor() {
1481
+ super(...arguments);
1482
+ this.stack = [new State("message")];
1483
+ this.buffer = "";
1484
+ this.addition = {};
1485
+ this.figure = null;
1486
+ this.mode = "default";
1467
1487
  }
1468
- });
1469
-
1470
- // satori/adapters/discord/src/types/team.ts
1471
- var MembershipState = /* @__PURE__ */ ((MembershipState2) => {
1472
- MembershipState2[MembershipState2["INVITED"] = 1] = "INVITED";
1473
- MembershipState2[MembershipState2["ACCEPTED"] = 2] = "ACCEPTED";
1474
- return MembershipState2;
1475
- })(MembershipState || {});
1476
-
1477
- // satori/adapters/discord/src/types/thread.ts
1478
- Internal.define({
1479
- "/channels/{channel.id}/messages/{message.id}/threads": {
1480
- POST: "startThreadFromMessage"
1481
- },
1482
- "/channels/{channel.id}/threads": {
1483
- POST: ["startThreadWithoutMessage", "startThreadInForumChannel"]
1484
- },
1485
- "/channels/{channel.id}/thread-members/@me": {
1486
- PUT: "joinThread",
1487
- DELETE: "leaveThread"
1488
- },
1489
- "/channels/{channel.id}/thread-members/{user.id}": {
1490
- PUT: "addThreadMember",
1491
- DELETE: "removeThreadMember",
1492
- GET: "getThreadMember"
1493
- },
1494
- "/channels/{channel.id}/thread-members": {
1495
- GET: "listThreadMembers"
1496
- },
1497
- "/channels/{channel.id}/threads/archived/public": {
1498
- GET: "listPublicArchivedThreads"
1499
- },
1500
- "/channels/{channel.id}/threads/archived/private": {
1501
- GET: "listPrivateArchivedThreads"
1502
- },
1503
- "/channels/{channel.id}/users/@me/threads/archived/private": {
1504
- GET: "listJoinedPrivateArchivedThreads"
1488
+ async getUrl() {
1489
+ var _a, _b;
1490
+ const input = this.options.session.discord;
1491
+ if ((input == null ? void 0 : input.t) === "INTERACTION_CREATE") {
1492
+ return `/webhooks/${input.d.application_id}/${input.d.token}`;
1493
+ } else if (this.stack[0].type === "forward" && ((_a = this.stack[0].channel) == null ? void 0 : _a.id)) {
1494
+ if (this.stack[1].author.nickname || this.stack[1].author.avatar) {
1495
+ const webhook = await this.ensureWebhook();
1496
+ return `/webhooks/${webhook.id}/${webhook.token}?wait=true&thread_id=${(_b = this.stack[0].channel) == null ? void 0 : _b.id}`;
1497
+ } else {
1498
+ return `/channels/${this.stack[0].channel.id}/messages`;
1499
+ }
1500
+ } else {
1501
+ if (this.stack[0].author.nickname || this.stack[0].author.avatar || this.stack[0].type === "forward" && !this.stack[0].threadCreated) {
1502
+ const webhook = await this.ensureWebhook();
1503
+ return `/webhooks/${webhook.id}/${webhook.token}?wait=true`;
1504
+ } else {
1505
+ return `/channels/${this.channelId}/messages`;
1506
+ }
1507
+ }
1505
1508
  }
1506
- });
1507
-
1508
- // satori/adapters/discord/src/types/user.ts
1509
- var UserFlag = /* @__PURE__ */ ((UserFlag2) => {
1510
- UserFlag2[UserFlag2["NONE"] = 0] = "NONE";
1511
- UserFlag2[UserFlag2["DISCORD_EMPLOYEE"] = 1] = "DISCORD_EMPLOYEE";
1512
- UserFlag2[UserFlag2["PARTNERED_SERVER_OWNER"] = 2] = "PARTNERED_SERVER_OWNER";
1513
- UserFlag2[UserFlag2["HYPESQUAD_EVENTS"] = 4] = "HYPESQUAD_EVENTS";
1514
- UserFlag2[UserFlag2["BUG_HUNTER_LEVEL_1"] = 8] = "BUG_HUNTER_LEVEL_1";
1515
- UserFlag2[UserFlag2["HOUSE_BRAVERY"] = 64] = "HOUSE_BRAVERY";
1516
- UserFlag2[UserFlag2["HOUSE_BRILLIANCE"] = 128] = "HOUSE_BRILLIANCE";
1517
- UserFlag2[UserFlag2["HOUSE_BALANCE"] = 256] = "HOUSE_BALANCE";
1518
- UserFlag2[UserFlag2["EARLY_SUPPORTER"] = 512] = "EARLY_SUPPORTER";
1519
- UserFlag2[UserFlag2["TEAM_USER"] = 1024] = "TEAM_USER";
1520
- UserFlag2[UserFlag2["BUG_HUNTER_LEVEL_2"] = 16384] = "BUG_HUNTER_LEVEL_2";
1521
- UserFlag2[UserFlag2["VERIFIED_BOT"] = 65536] = "VERIFIED_BOT";
1522
- UserFlag2[UserFlag2["EARLY_VERIFIED_BOT_DEVELOPER"] = 131072] = "EARLY_VERIFIED_BOT_DEVELOPER";
1523
- UserFlag2[UserFlag2["DISCORD_CERTIFIED_MODERATOR"] = 262144] = "DISCORD_CERTIFIED_MODERATOR";
1524
- UserFlag2[UserFlag2["BOT_HTTP_INTERACTIONS"] = 524288] = "BOT_HTTP_INTERACTIONS";
1525
- UserFlag2[UserFlag2["ACTIVE_DEVELOPER"] = 4194304] = "ACTIVE_DEVELOPER";
1526
- return UserFlag2;
1527
- })(UserFlag || {});
1528
- var PremiumType = /* @__PURE__ */ ((PremiumType2) => {
1529
- PremiumType2[PremiumType2["NONE"] = 0] = "NONE";
1530
- PremiumType2[PremiumType2["NITRO_CLASSIC"] = 1] = "NITRO_CLASSIC";
1531
- PremiumType2[PremiumType2["NITRO"] = 2] = "NITRO";
1532
- PremiumType2[PremiumType2["NITRO_BASIC"] = 3] = "NITRO_BASIC";
1533
- return PremiumType2;
1534
- })(PremiumType || {});
1535
- var VisibilityType = /* @__PURE__ */ ((VisibilityType2) => {
1536
- VisibilityType2[VisibilityType2["NONE"] = 0] = "NONE";
1537
- VisibilityType2[VisibilityType2["EVERYONE"] = 1] = "EVERYONE";
1538
- return VisibilityType2;
1539
- })(VisibilityType || {});
1540
- Internal.define({
1541
- "/users/@me": {
1542
- GET: "getCurrentUser",
1543
- PATCH: "modifyCurrentUser"
1544
- },
1545
- "/users/{user.id}": {
1546
- GET: "getUser"
1547
- },
1548
- "/users/@me/connections": {
1549
- GET: "getUserConnections"
1509
+ async post(data, headers) {
1510
+ var _a;
1511
+ try {
1512
+ const url = await this.getUrl();
1513
+ const result = await this.bot.http.post(url, data, { headers });
1514
+ const session = this.bot.session();
1515
+ const message = await decodeMessage(this.bot, result, session);
1516
+ session.app.emit(session, "send", session);
1517
+ this.results.push(session);
1518
+ if (this.stack[0].type === "forward" && !this.stack[0].threadCreated) {
1519
+ this.stack[0].threadCreated = true;
1520
+ const thread = await this.bot.internal.startThreadFromMessage(this.channelId, result.id, {
1521
+ name: "Forward",
1522
+ auto_archive_duration: 60
1523
+ });
1524
+ this.stack[0].channel = thread;
1525
+ }
1526
+ return message;
1527
+ } catch (e) {
1528
+ if (import_satori3.Quester.isAxiosError(e) && ((_a = e.response) == null ? void 0 : _a.data.code) === 10015) {
1529
+ logger.debug("webhook has been deleted, recreating..., %o", e.response.data);
1530
+ if (!this.bot.webhookLock[this.channelId])
1531
+ this.bot.webhooks[this.channelId] = null;
1532
+ await this.ensureWebhook();
1533
+ return this.post(data, headers);
1534
+ }
1535
+ this.errors.push(e);
1536
+ }
1537
+ }
1538
+ async sendEmbed(attrs, payload) {
1539
+ const { filename, data, mime } = await this.bot.ctx.http.file(attrs.url, attrs);
1540
+ const form = new import_form_data.default();
1541
+ const value = process.env.KOISHI_ENV === "browser" ? new Blob([data], { type: mime }) : Buffer.from(data);
1542
+ form.append("file", value, attrs.file || filename);
1543
+ form.append("payload_json", JSON.stringify(payload));
1544
+ return this.post(form, form.getHeaders());
1545
+ }
1546
+ async sendAsset(type, attrs, addition) {
1547
+ const { handleMixedContent, handleExternalAsset } = this.bot.config;
1548
+ if (handleMixedContent === "separate" && addition.content) {
1549
+ await this.post(addition);
1550
+ addition.content = "";
1551
+ }
1552
+ const sendDirect = /* @__PURE__ */ __name(async () => {
1553
+ if (addition.content) {
1554
+ await this.post(addition);
1555
+ }
1556
+ return this.post({ ...addition, content: attrs.url });
1557
+ }, "sendDirect");
1558
+ const sendDownload = /* @__PURE__ */ __name(() => this.sendEmbed(attrs, addition), "sendDownload");
1559
+ if (["file:", "data:", "base64:"].some((prefix) => attrs.url.startsWith(prefix))) {
1560
+ return await sendDownload();
1561
+ }
1562
+ const mode = attrs.mode || handleExternalAsset;
1563
+ if (mode === "download" || handleMixedContent === "attach" && addition.content || type === "file") {
1564
+ return sendDownload();
1565
+ } else if (mode === "direct") {
1566
+ return sendDirect();
1567
+ }
1568
+ return await this.bot.ctx.http.head(attrs.url, {
1569
+ headers: { accept: type + "/*" },
1570
+ timeout: +attrs.timeout || void 0
1571
+ }).then((headers) => {
1572
+ if (headers["content-type"].startsWith(type)) {
1573
+ return sendDirect();
1574
+ } else {
1575
+ return sendDownload();
1576
+ }
1577
+ }, sendDownload);
1550
1578
  }
1551
- });
1552
-
1553
- // satori/adapters/discord/src/types/voice.ts
1554
- Internal.define({
1555
- "/voice/regions": {
1556
- GET: "listVoiceRegions"
1557
- },
1558
- "/guilds/{guild.id}/regions": {
1559
- GET: "getGuildVoiceRegions"
1560
- },
1561
- "/guilds/{guild.id}/voice-states/@me": {
1562
- PATCH: "modifyCurrentUserVoiceState"
1563
- },
1564
- "/guilds/{guild.id}/voice-states/{user.id}": {
1565
- PATCH: "modifyUserVoiceState"
1579
+ async ensureWebhook() {
1580
+ return this.bot.ensureWebhook(this.channelId);
1566
1581
  }
1567
- });
1568
-
1569
- // satori/adapters/discord/src/types/webhook.ts
1570
- var Webhook2;
1571
- ((Webhook4) => {
1572
- let Type;
1573
- ((Type2) => {
1574
- Type2[Type2["INCOMING"] = 1] = "INCOMING";
1575
- Type2[Type2["CHANNEL_FOLLOWER"] = 2] = "CHANNEL_FOLLOWER";
1576
- Type2[Type2["APPLICATION"] = 3] = "APPLICATION";
1577
- })(Type = Webhook4.Type || (Webhook4.Type = {}));
1578
- })(Webhook2 || (Webhook2 = {}));
1579
- Internal.define({
1580
- "/channels/{channel.id}/webhooks": {
1581
- POST: "createWebhook",
1582
- GET: "getChannelWebhooks"
1583
- },
1584
- "/guilds/{guild.id}/webhooks": {
1585
- GET: "getGuildWebhooks"
1586
- },
1587
- "/webhooks/{webhook.id}": {
1588
- GET: "getWebhook",
1589
- PATCH: "modifyWebhook",
1590
- DELETE: "deleteWebhook"
1591
- },
1592
- "/webhooks/{webhook.id}/{webhook.token}": {
1593
- GET: "getWebhookwithToken",
1594
- PATCH: "modifyWebhookwithToken",
1595
- DELETE: "deleteWebhookwithToken",
1596
- POST: "executeWebhook"
1597
- },
1598
- "/webhooks/{webhook.id}/{webhook.token}/slack": {
1599
- POST: "executeSlackCompatibleWebhook"
1600
- },
1601
- "/webhooks/{webhook.id}/{webhook.token}/github": {
1602
- POST: "executeGitHubCompatibleWebhook"
1603
- },
1604
- "/webhooks/{webhook.id}/{webhook.token}/messages/{message.id}": {
1605
- GET: "getWebhookMessage",
1606
- PATCH: "editWebhookMessage",
1607
- DELETE: "deleteWebhookMessage"
1582
+ async flush() {
1583
+ const content = this.buffer.trim();
1584
+ if (!content)
1585
+ return;
1586
+ await this.post({ ...this.addition, content });
1587
+ this.buffer = "";
1588
+ this.addition = {};
1608
1589
  }
1609
- });
1590
+ async visit(element) {
1591
+ var _a;
1592
+ const { type, attrs, children } = element;
1593
+ if (type === "text") {
1594
+ this.buffer += sanitize(attrs.content);
1595
+ } else if (type === "b" || type === "strong") {
1596
+ this.buffer += "**";
1597
+ await this.render(children);
1598
+ this.buffer += "**";
1599
+ } else if (type === "i" || type === "em") {
1600
+ this.buffer += "*";
1601
+ await this.render(children);
1602
+ this.buffer += "*";
1603
+ } else if (type === "u" || type === "ins") {
1604
+ this.buffer += "__";
1605
+ await this.render(children);
1606
+ this.buffer += "__";
1607
+ } else if (type === "s" || type === "del") {
1608
+ this.buffer += "~~";
1609
+ await this.render(children);
1610
+ this.buffer += "~~";
1611
+ } else if (type === "spl") {
1612
+ this.buffer += "||";
1613
+ await this.render(children);
1614
+ this.buffer += "||";
1615
+ } else if (type === "code") {
1616
+ this.buffer += "`";
1617
+ await this.render(children);
1618
+ this.buffer += "`";
1619
+ } else if (type === "a") {
1620
+ await this.render(children);
1621
+ if (this.options.linkPreview) {
1622
+ this.buffer += ` (${attrs.href}) `;
1623
+ } else {
1624
+ this.buffer += ` (<${attrs.href}>) `;
1625
+ }
1626
+ } else if (type === "p") {
1627
+ await this.render(children);
1628
+ this.buffer += "\n";
1629
+ } else if (type === "at") {
1630
+ if (attrs.id) {
1631
+ this.buffer += `<@${attrs.id}>`;
1632
+ } else if (attrs.type === "all") {
1633
+ this.buffer += `@everyone`;
1634
+ } else if (attrs.type === "here") {
1635
+ this.buffer += `@here`;
1636
+ }
1637
+ } else if (type === "sharp" && attrs.id) {
1638
+ this.buffer += `<#${attrs.id}>`;
1639
+ } else if (type === "face") {
1640
+ if (attrs.platform && attrs.platform !== this.bot.platform) {
1641
+ return this.render(children);
1642
+ } else {
1643
+ this.buffer += `<${attrs.animated ? "a" : ""}:${attrs.name}:${attrs.id}>`;
1644
+ }
1645
+ } else if ((type === "image" || type === "video") && attrs.url) {
1646
+ if (this.mode === "figure") {
1647
+ this.figure = element;
1648
+ } else {
1649
+ await this.sendAsset(type, attrs, {
1650
+ ...this.addition,
1651
+ content: this.buffer.trim()
1652
+ });
1653
+ this.buffer = "";
1654
+ }
1655
+ } else if (type === "share") {
1656
+ await this.flush();
1657
+ await this.post({
1658
+ ...this.addition,
1659
+ embeds: [{ ...attrs }]
1660
+ });
1661
+ } else if (type === "audio") {
1662
+ await this.sendAsset("file", attrs, {
1663
+ ...this.addition,
1664
+ content: this.buffer.trim()
1665
+ });
1666
+ this.buffer = "";
1667
+ } else if (type === "figure") {
1668
+ await this.flush();
1669
+ this.mode = "figure";
1670
+ await this.render(children);
1671
+ await this.sendAsset(this.figure.type, this.figure.attrs, {
1672
+ ...this.addition,
1673
+ content: this.buffer.trim()
1674
+ });
1675
+ this.buffer = "";
1676
+ this.mode = "default";
1677
+ } else if (type === "message" && !attrs.forward) {
1678
+ if (this.mode === "figure") {
1679
+ await this.render(children);
1680
+ this.buffer += "\n";
1681
+ } else {
1682
+ const resultLength = +this.results.length;
1683
+ await this.flush();
1684
+ const [author] = import_satori3.segment.select(children, "author");
1685
+ if (author) {
1686
+ const { avatar, nickname } = author.attrs;
1687
+ if (avatar)
1688
+ this.addition.avatar_url = avatar;
1689
+ if (nickname)
1690
+ this.addition.username = nickname;
1691
+ if (this.stack[0].type === "message") {
1692
+ this.stack[0].author = author.attrs;
1693
+ }
1694
+ if (this.stack[0].type === "forward") {
1695
+ this.stack[1].author = author.attrs;
1696
+ }
1697
+ }
1698
+ const [quote] = import_satori3.segment.select(children, "quote");
1699
+ if (quote) {
1700
+ const parse = /* @__PURE__ */ __name((val) => val.replace(/\\([\\*_`~|()\[\]])/g, "$1"), "parse");
1701
+ const message = this.stack[this.stack[0].type === "forward" ? 1 : 0];
1702
+ if (!message.author.avatar && !message.author.nickname && this.stack[0].type !== "forward") {
1703
+ await this.flush();
1704
+ this.addition.message_reference = {
1705
+ message_id: quote.attrs.id
1706
+ };
1707
+ } else {
1708
+ let replyId = quote.attrs.id, channelId = this.channelId;
1709
+ if (this.stack[0].type === "forward" && ((_a = this.stack[0].fakeMessageMap[quote.attrs.id]) == null ? void 0 : _a.length) >= 1) {
1710
+ replyId = this.stack[0].fakeMessageMap[quote.attrs.id][0].messageId;
1711
+ channelId = this.stack[0].fakeMessageMap[quote.attrs.id][0].channelId;
1712
+ }
1713
+ const quoted = await this.bot.getMessage(channelId, replyId);
1714
+ this.addition.embeds = [{
1715
+ description: [
1716
+ sanitize(parse(quoted.elements.filter((v) => v.type === "text").join("")).slice(0, 30)),
1717
+ `<t:${Math.ceil(quoted.timestamp / 1e3)}:R> [[ ↑ ]](https://discord.com/channels/${this.guildId}/${channelId}/${replyId})`
1718
+ ].join("\n\n"),
1719
+ author: {
1720
+ name: quoted.author.nickname || quoted.author.username,
1721
+ icon_url: quoted.author.avatar
1722
+ }
1723
+ }];
1724
+ }
1725
+ }
1726
+ await this.render(children);
1727
+ await this.flush();
1728
+ const newLength = +this.results.length;
1729
+ const sentMessages = this.results.slice(resultLength, newLength);
1730
+ if (this.stack[0].type === "forward" && attrs.id) {
1731
+ this.stack[0].fakeMessageMap[attrs.id] = sentMessages;
1732
+ }
1733
+ if (this.stack[0].type === "message") {
1734
+ this.stack[0].author = {};
1735
+ }
1736
+ if (this.stack[0].type === "forward") {
1737
+ this.stack[1].author = {};
1738
+ }
1739
+ }
1740
+ } else if (type === "message" && attrs.forward) {
1741
+ this.stack.unshift(new State("forward"));
1742
+ await this.render(children);
1743
+ await this.flush();
1744
+ await this.bot.internal.modifyChannel(this.stack[0].channel.id, {
1745
+ archived: true,
1746
+ locked: true
1747
+ });
1748
+ this.stack.shift();
1749
+ } else {
1750
+ await this.render(children);
1751
+ }
1752
+ }
1753
+ };
1754
+ __name(DiscordMessageEncoder, "DiscordMessageEncoder");
1755
+ ((DiscordMessageEncoder2) => {
1756
+ DiscordMessageEncoder2.Config = import_satori3.Schema.object({
1757
+ handleExternalAsset: import_satori3.Schema.union([
1758
+ import_satori3.Schema.const("download").description("先下载后发送"),
1759
+ import_satori3.Schema.const("direct").description("直接发送链接"),
1760
+ import_satori3.Schema.const("auto").description("发送一个 HEAD 请求,根据返回的 Content-Type 决定发送方式")
1761
+ ]).role("radio").description("发送外链资源时采用的方式。").default("auto"),
1762
+ handleMixedContent: import_satori3.Schema.union([
1763
+ import_satori3.Schema.const("separate").description("将每个不同形式的内容分开发送"),
1764
+ import_satori3.Schema.const("attach").description("图片前如果有文本内容,则将文本作为图片的附带信息进行发送"),
1765
+ import_satori3.Schema.const("auto").description("如果图片本身采用直接发送则与前面的文本分开,否则将文本作为图片的附带信息发送")
1766
+ ]).role("radio").description("发送图文等混合内容时采用的方式。").default("auto")
1767
+ }).description("发送设置");
1768
+ })(DiscordMessageEncoder || (DiscordMessageEncoder = {}));
1610
1769
 
1611
1770
  // satori/adapters/discord/src/ws.ts
1612
1771
  var import_satori4 = require("@satorijs/satori");
@@ -1627,7 +1786,7 @@ var WsClient = class extends import_satori4.Adapter.WsClient {
1627
1786
  heartbeat() {
1628
1787
  logger2.debug(`heartbeat d ${this._d}`);
1629
1788
  this.bot.socket.send(JSON.stringify({
1630
- op: 1 /* HEARTBEAT */,
1789
+ op: Gateway.Opcode.HEARTBEAT,
1631
1790
  d: this._d
1632
1791
  }));
1633
1792
  }
@@ -1644,12 +1803,12 @@ var WsClient = class extends import_satori4.Adapter.WsClient {
1644
1803
  if (parsed.s) {
1645
1804
  this._d = parsed.s;
1646
1805
  }
1647
- if (parsed.op === 10 /* HELLO */) {
1806
+ if (parsed.op === Gateway.Opcode.HELLO) {
1648
1807
  this._ping = setInterval(() => this.heartbeat(), parsed.d.heartbeat_interval);
1649
1808
  if (this._sessionId) {
1650
1809
  logger2.debug("resuming");
1651
1810
  this.bot.socket.send(JSON.stringify({
1652
- op: 6 /* RESUME */,
1811
+ op: Gateway.Opcode.RESUME,
1653
1812
  d: {
1654
1813
  token: this.bot.config.token,
1655
1814
  session_id: this._sessionId,
@@ -1658,7 +1817,7 @@ var WsClient = class extends import_satori4.Adapter.WsClient {
1658
1817
  }));
1659
1818
  } else {
1660
1819
  this.bot.socket.send(JSON.stringify({
1661
- op: 2 /* IDENTIFY */,
1820
+ op: Gateway.Opcode.IDENTIFY,
1662
1821
  d: {
1663
1822
  token: this.bot.config.token,
1664
1823
  properties: {},
@@ -1668,7 +1827,7 @@ var WsClient = class extends import_satori4.Adapter.WsClient {
1668
1827
  }));
1669
1828
  }
1670
1829
  }
1671
- if (parsed.op === 9 /* INVALID_SESSION */) {
1830
+ if (parsed.op === Gateway.Opcode.INVALID_SESSION) {
1672
1831
  if (parsed.d)
1673
1832
  return;
1674
1833
  this._sessionId = "";
@@ -1676,11 +1835,12 @@ var WsClient = class extends import_satori4.Adapter.WsClient {
1676
1835
  this.bot.offline();
1677
1836
  (_a = this.bot.socket) == null ? void 0 : _a.close();
1678
1837
  }
1679
- if (parsed.op === 0 /* DISPATCH */) {
1838
+ if (parsed.op === Gateway.Opcode.DISPATCH) {
1839
+ this.bot.ctx.emit("discord/" + parsed.t.toLowerCase().replace(/_/g, "-"), parsed);
1680
1840
  if (parsed.t === "READY") {
1681
1841
  this._sessionId = parsed.d.session_id;
1682
1842
  this._resumeUrl = parsed.d.resume_gateway_url;
1683
- const self = adaptUser(parsed.d.user);
1843
+ const self = decodeUser(parsed.d.user);
1684
1844
  self.selfId = self.userId;
1685
1845
  delete self.userId;
1686
1846
  Object.assign(this.bot, self);
@@ -1694,7 +1854,7 @@ var WsClient = class extends import_satori4.Adapter.WsClient {
1694
1854
  if (session)
1695
1855
  this.bot.dispatch(session);
1696
1856
  }
1697
- if (parsed.op === 7 /* RECONNECT */) {
1857
+ if (parsed.op === Gateway.Opcode.RECONNECT) {
1698
1858
  this.bot.offline();
1699
1859
  logger2.warn("offline: discord request reconnect");
1700
1860
  (_b = this.bot.socket) == null ? void 0 : _b.close();
@@ -1709,7 +1869,7 @@ __name(WsClient, "WsClient");
1709
1869
  ((WsClient2) => {
1710
1870
  WsClient2.Config = import_satori4.Schema.intersect([
1711
1871
  import_satori4.Schema.object({
1712
- intents: import_satori4.Schema.bitset(GatewayIntent).description("需要订阅的机器人事件。").default(0 | 512 /* GUILD_MESSAGES */ | 1024 /* GUILD_MESSAGE_REACTIONS */ | 4096 /* DIRECT_MESSAGES */ | 8192 /* DIRECT_MESSAGE_REACTIONS */ | 32768 /* MESSAGE_CONTENT */)
1872
+ 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)
1713
1873
  }).description("推送设置"),
1714
1874
  import_satori4.Adapter.WsClient.Config
1715
1875
  ]);
@@ -1717,11 +1877,13 @@ __name(WsClient, "WsClient");
1717
1877
 
1718
1878
  // satori/adapters/discord/src/bot.ts
1719
1879
  var import_package = require("../package.json");
1880
+ var logger3 = new import_satori5.Logger("discord");
1720
1881
  var DiscordBot = class extends import_satori5.Bot {
1721
1882
  constructor(ctx, config) {
1722
1883
  super(ctx, config);
1723
1884
  this.webhooks = {};
1724
1885
  this.webhookLock = {};
1886
+ this.commands = [];
1725
1887
  this.http = ctx.http.extend({
1726
1888
  ...config,
1727
1889
  headers: {
@@ -1733,6 +1895,9 @@ var DiscordBot = class extends import_satori5.Bot {
1733
1895
  this.internal = new Internal(this.http);
1734
1896
  ctx.plugin(WsClient, this);
1735
1897
  }
1898
+ session(payload = {}) {
1899
+ return (0, import_satori5.defineProperty)(super.session(), "discord", Object.assign(Object.create(this.internal), payload));
1900
+ }
1736
1901
  async _ensureWebhook(channelId) {
1737
1902
  let webhook;
1738
1903
  const webhooks = await this.internal.getChannelWebhooks(channelId);
@@ -1760,7 +1925,7 @@ var DiscordBot = class extends import_satori5.Bot {
1760
1925
  }
1761
1926
  async getSelf() {
1762
1927
  const data = await this.internal.getCurrentUser();
1763
- return adaptUser(data);
1928
+ return decodeUser(data);
1764
1929
  }
1765
1930
  async deleteMessage(channelId, messageId) {
1766
1931
  await this.internal.deleteMessage(channelId, messageId);
@@ -1778,28 +1943,28 @@ var DiscordBot = class extends import_satori5.Bot {
1778
1943
  }
1779
1944
  async getMessage(channelId, messageId) {
1780
1945
  const data = await this.internal.getChannelMessage(channelId, messageId);
1781
- return await adaptMessage(this, data);
1946
+ return await decodeMessage(this, data);
1782
1947
  }
1783
1948
  async getMessageList(channelId, before) {
1784
1949
  const data = (await this.internal.getChannelMessages(channelId, { before, limit: 50 })).reverse();
1785
- return await Promise.all(data.map((data2) => adaptMessage(this, data2)));
1950
+ return await Promise.all(data.map((data2) => decodeMessage(this, data2)));
1786
1951
  }
1787
1952
  async getUser(userId) {
1788
1953
  const data = await this.internal.getUser(userId);
1789
- return adaptUser(data);
1954
+ return decodeUser(data);
1790
1955
  }
1791
1956
  async getGuildMemberList(guildId) {
1792
1957
  const data = await this.internal.listGuildMembers(guildId);
1793
- return data.map((v) => adaptUser(v.user));
1958
+ return data.map((v) => decodeUser(v.user));
1794
1959
  }
1795
1960
  async getChannel(channelId) {
1796
1961
  const data = await this.internal.getChannel(channelId);
1797
- return adaptChannel(data);
1962
+ return decodeChannel(data);
1798
1963
  }
1799
1964
  async getGuildMember(guildId, userId) {
1800
1965
  const member = await this.internal.getGuildMember(guildId, userId);
1801
1966
  return {
1802
- ...adaptUser(member.user),
1967
+ ...decodeUser(member.user),
1803
1968
  nickname: member.nick
1804
1969
  };
1805
1970
  }
@@ -1808,15 +1973,15 @@ var DiscordBot = class extends import_satori5.Bot {
1808
1973
  }
1809
1974
  async getGuild(guildId) {
1810
1975
  const data = await this.internal.getGuild(guildId);
1811
- return adaptGuild(data);
1976
+ return decodeGuild(data);
1812
1977
  }
1813
1978
  async getGuildList() {
1814
1979
  const data = await this.internal.getCurrentUserGuilds();
1815
- return data.map(adaptGuild);
1980
+ return data.map(decodeGuild);
1816
1981
  }
1817
1982
  async getChannelList(guildId) {
1818
1983
  const data = await this.internal.getGuildChannels(guildId);
1819
- return data.map(adaptChannel);
1984
+ return data.map(decodeChannel);
1820
1985
  }
1821
1986
  createReaction(channelId, messageId, emoji) {
1822
1987
  return this.internal.createReaction(channelId, messageId, emoji);
@@ -1837,7 +2002,7 @@ var DiscordBot = class extends import_satori5.Bot {
1837
2002
  }
1838
2003
  async getReactions(channelId, messageId, emoji) {
1839
2004
  const data = await this.internal.getReactions(channelId, messageId, emoji);
1840
- return data.map(adaptUser);
2005
+ return data.map(decodeUser);
1841
2006
  }
1842
2007
  setGuildMemberRole(guildId, userId, roleId) {
1843
2008
  return this.internal.addGuildMemberRole(guildId, userId, roleId);
@@ -1859,9 +2024,57 @@ var DiscordBot = class extends import_satori5.Bot {
1859
2024
  deleteGuildRole(guildId, roleId) {
1860
2025
  return this.internal.deleteGuildRole(guildId, roleId);
1861
2026
  }
2027
+ async sendPrivateMessage(userId, content, options) {
2028
+ const channel = await this.internal.createDM({
2029
+ recipient_id: userId
2030
+ });
2031
+ return this.sendMessage(channel.id, content, null, options);
2032
+ }
2033
+ async updateCommands(commands) {
2034
+ this.commands = commands;
2035
+ const local = Object.fromEntries(commands.map((cmd) => [cmd.name, cmd]));
2036
+ const remote = Object.fromEntries((await this.internal.getGlobalApplicationCommands(this.selfId)).filter((cmd) => cmd.type === ApplicationCommand2.Type.CHAT_INPUT).map((cmd) => [cmd.name, cmd]));
2037
+ for (const key in { ...local, ...remote }) {
2038
+ if (!local[key]) {
2039
+ logger3.debug("delete command %s", key);
2040
+ await this.internal.deleteGlobalApplicationCommand(this.selfId, remote[key].id);
2041
+ continue;
2042
+ }
2043
+ const data = encodeCommand(local[key]);
2044
+ logger3.debug(data, remote[key]);
2045
+ if (!remote[key]) {
2046
+ logger3.debug("create command: %s", local[key].name);
2047
+ await this.internal.createGlobalApplicationCommand(this.selfId, data);
2048
+ } else if (shapeEqual(data, remote[key])) {
2049
+ logger3.debug("edit command: %s", local[key].name);
2050
+ await this.internal.editGlobalApplicationCommand(this.selfId, remote[key].id, data);
2051
+ }
2052
+ }
2053
+ }
1862
2054
  };
1863
2055
  __name(DiscordBot, "DiscordBot");
1864
2056
  DiscordBot.MessageEncoder = DiscordMessageEncoder;
2057
+ function shapeEqual(a, b, strict = false) {
2058
+ if (a === b)
2059
+ return true;
2060
+ if (!strict && (0, import_satori5.isNullable)(a) && (0, import_satori5.isNullable)(b))
2061
+ return true;
2062
+ if (typeof a !== typeof b)
2063
+ return false;
2064
+ if (typeof a !== "object")
2065
+ return false;
2066
+ if (!a || !b)
2067
+ return false;
2068
+ if (Array.isArray(a)) {
2069
+ if (!Array.isArray(b) || a.length !== b.length)
2070
+ return false;
2071
+ return a.every((item, index) => shapeEqual(item, b[index]));
2072
+ } else if (Array.isArray(b)) {
2073
+ return false;
2074
+ }
2075
+ return Object.keys(a).every((key) => shapeEqual(a[key], b[key], strict));
2076
+ }
2077
+ __name(shapeEqual, "shapeEqual");
1865
2078
  ((DiscordBot2) => {
1866
2079
  DiscordBot2.Config = import_satori5.Schema.intersect([
1867
2080
  import_satori5.Schema.object({
@@ -1881,16 +2094,6 @@ var src_default = DiscordBot;
1881
2094
  Discord,
1882
2095
  DiscordBot,
1883
2096
  DiscordMessageEncoder,
1884
- WsClient,
1885
- adaptAuthor,
1886
- adaptChannel,
1887
- adaptGuild,
1888
- adaptMessage,
1889
- adaptSession,
1890
- adaptUser,
1891
- decodeRole,
1892
- encodeRole,
1893
- prepareMessage,
1894
- sanitize
2097
+ WsClient
1895
2098
  });
1896
2099
  //# sourceMappingURL=index.js.map