mirror of
https://github.com/xHyroM/roles-bot.git
synced 2024-11-23 08:51:04 +01:00
feat: upload debug files
This commit is contained in:
parent
b18eff081c
commit
791a779715
3 changed files with 62 additions and 25 deletions
|
@ -6,7 +6,7 @@ import {
|
|||
RouteBases,
|
||||
Routes,
|
||||
} from "discord-api-types/v10";
|
||||
import respond from "../../utils/respond";
|
||||
import respond, { respondAttachments } from "../../utils/respond";
|
||||
import { Env } from "../../types";
|
||||
|
||||
export class Context {
|
||||
|
@ -23,6 +23,7 @@ export class Context {
|
|||
}
|
||||
|
||||
public respond = respond;
|
||||
public respondAttachments = respondAttachments;
|
||||
|
||||
public async editReply(content: APIInteractionResponseCallbackData) {
|
||||
return await fetch(
|
||||
|
|
|
@ -5,3 +5,23 @@ export default function (response: APIInteractionResponse) {
|
|||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
}
|
||||
|
||||
export function respondAttachments(
|
||||
response: APIInteractionResponse,
|
||||
attachments: Record<string, string>,
|
||||
) {
|
||||
const body = new FormData();
|
||||
body.append("payload_json", JSON.stringify(response));
|
||||
|
||||
let i = 0;
|
||||
for (const [name, content] of Object.entries(attachments)) {
|
||||
body.append(
|
||||
`files[${i}]`,
|
||||
new Blob([content], { type: "text/plain" }),
|
||||
name,
|
||||
);
|
||||
i++;
|
||||
}
|
||||
|
||||
return new Response(body);
|
||||
}
|
||||
|
|
|
@ -161,7 +161,8 @@ export default async function (ctx: Context, data: Data) {
|
|||
} = await res.json();
|
||||
const errors = parseErrors(json?.errors ?? {});
|
||||
|
||||
return ctx.respond({
|
||||
return ctx.respondAttachments(
|
||||
{
|
||||
type: InteractionResponseType.ChannelMessageWithSource,
|
||||
data: {
|
||||
content: `Error: ${json.message} (${json.code})${
|
||||
|
@ -173,7 +174,12 @@ export default async function (ctx: Context, data: Data) {
|
|||
}`,
|
||||
flags: MessageFlags.Ephemeral,
|
||||
},
|
||||
});
|
||||
},
|
||||
{
|
||||
"data.json": JSON.stringify(data, null, "\t"),
|
||||
"payload.json": JSON.stringify(payload, null, "\t"),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return ctx.respond({
|
||||
|
@ -221,7 +227,12 @@ export default async function (ctx: Context, data: Data) {
|
|||
} = await res.json();
|
||||
const errors = parseErrors(json?.errors ?? {});
|
||||
|
||||
return ctx.respond({
|
||||
// @ts-expect-error
|
||||
// rome-ignore lint/performance/noDelete: <explanation>
|
||||
delete data.webhook;
|
||||
|
||||
return ctx.respondAttachments(
|
||||
{
|
||||
type: InteractionResponseType.ChannelMessageWithSource,
|
||||
data: {
|
||||
content: `Error: ${json.message} (${json.code})${
|
||||
|
@ -233,7 +244,12 @@ export default async function (ctx: Context, data: Data) {
|
|||
}`,
|
||||
flags: MessageFlags.Ephemeral,
|
||||
},
|
||||
});
|
||||
},
|
||||
{
|
||||
"data.json": JSON.stringify(data, null, "\t"),
|
||||
"payload.json": JSON.stringify(payload, null, "\t"),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return ctx.respond({
|
||||
|
|
Loading…
Reference in a new issue