@satorijs/adapter-discord 3.5.1 → 3.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -214,7 +214,6 @@ __name(adaptSession, "adaptSession");
214
214
 
215
215
  // satori/adapters/discord/src/message.ts
216
216
  var import_satori2 = require("@satorijs/satori");
217
- var import_file_type = require("file-type");
218
217
  var import_form_data = __toESM(require("form-data"));
219
218
  var DiscordMessenger = class extends import_satori2.Messenger {
220
219
  constructor() {
@@ -235,46 +234,41 @@ var DiscordMessenger = class extends import_satori2.Messenger {
235
234
  this.errors.push(e);
236
235
  }
237
236
  }
238
- async sendEmbed(fileBuffer, payload_json, filename) {
237
+ async sendEmbed(buffer, payload, filename) {
239
238
  const fd = new import_form_data.default();
240
- filename || (filename = "file." + (await (0, import_file_type.fromBuffer)(fileBuffer)).ext);
241
- fd.append("file", Buffer.from(fileBuffer), filename);
242
- fd.append("payload_json", JSON.stringify(payload_json));
239
+ fd.append("file", buffer, filename);
240
+ fd.append("payload_json", JSON.stringify(payload));
243
241
  return this.post(fd, fd.getHeaders());
244
242
  }
245
243
  async sendContent(content, addition) {
246
244
  return this.post({ ...addition, content });
247
245
  }
248
- async sendAsset(type, data, addition) {
246
+ async sendAsset(type, attrs, addition) {
249
247
  const { handleMixedContent, handleExternalAsset } = this.bot.config;
250
248
  if (handleMixedContent === "separate" && addition.content) {
251
249
  await this.post(addition);
252
250
  addition.content = "";
253
251
  }
254
- if (["file:", "data:", "base64:"].some((prefix) => data.url.startsWith(prefix))) {
255
- const result = await this.bot.ctx.http.file(data.url);
256
- return await this.sendEmbed(result.data, addition, data.file || result.filename);
257
- }
258
252
  const sendDirect = /* @__PURE__ */ __name(async () => {
259
253
  if (addition.content) {
260
254
  await this.post(addition);
261
255
  }
262
- return this.post({ ...addition, content: data.url });
256
+ return this.post({ ...addition, content: attrs.url });
263
257
  }, "sendDirect");
264
258
  const sendDownload = /* @__PURE__ */ __name(async () => {
265
- const buffer = await this.bot.ctx.http.get(data.url, {
266
- headers: { accept: type + "/*" },
267
- responseType: "arraybuffer"
268
- });
269
- return this.sendEmbed(buffer, addition, data.file);
259
+ const { filename, data } = await this.bot.ctx.http.file(attrs.url);
260
+ return this.sendEmbed(data, addition, attrs.file || filename);
270
261
  }, "sendDownload");
271
- const mode = data.mode || handleExternalAsset;
262
+ if (["file:", "data:", "base64:"].some((prefix) => attrs.url.startsWith(prefix))) {
263
+ return await sendDownload();
264
+ }
265
+ const mode = attrs.mode || handleExternalAsset;
272
266
  if (mode === "download" || handleMixedContent === "attach" && addition.content || type === "file") {
273
267
  return sendDownload();
274
268
  } else if (mode === "direct") {
275
269
  return sendDirect();
276
270
  }
277
- return await this.bot.ctx.http.head(data.url, {
271
+ return await this.bot.ctx.http.head(attrs.url, {
278
272
  headers: { accept: type + "/*" }
279
273
  }).then((headers) => {
280
274
  if (headers["content-type"].startsWith(type)) {