feat: enhance logging for Discord interactions with detailed user information
This commit is contained in:
parent
fa0584c550
commit
de09a84daa
@ -1,10 +1,11 @@
|
||||
import { Config } from "../config";
|
||||
import { logger } from "../logger";
|
||||
|
||||
export const fetchDiscord = async (
|
||||
path: string,
|
||||
init?: RequestInit,
|
||||
): Promise<Response> => {
|
||||
const response = await fetch(`${Config.DISCORD_API}${path}`, {
|
||||
let response = await fetch(`${Config.DISCORD_API}${path}`, {
|
||||
...init,
|
||||
headers: {
|
||||
Authorization: `Bot ${Config.BOT_TOKEN}`,
|
||||
@ -12,10 +13,22 @@ export const fetchDiscord = async (
|
||||
...(init?.headers || {}),
|
||||
},
|
||||
});
|
||||
|
||||
if (response.status === 429) {
|
||||
const data = await response.json().catch(() => ({}) as any);
|
||||
const retry = (data?.retry_after ? Number(data.retry_after) : 1) * 1000;
|
||||
logger.warn({ path, retry }, `Rate limited. Retrying after ${retry}ms.`);
|
||||
await new Promise((r) => setTimeout(r, retry));
|
||||
|
||||
response = await fetch(`${Config.DISCORD_API}${path}`, {
|
||||
...init,
|
||||
headers: {
|
||||
Authorization: `Bot ${Config.BOT_TOKEN}`,
|
||||
"Content-Type": "application/json",
|
||||
...(init?.headers || {}),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
10
src/index.ts
10
src/index.ts
@ -132,7 +132,15 @@ app.post("/interactions", async (c) => {
|
||||
}
|
||||
|
||||
const interaction = JSON.parse(raw);
|
||||
logger.info({ interaction }, "Received interaction");
|
||||
logger.info(
|
||||
{
|
||||
user: interaction.user.id,
|
||||
name: interaction.name,
|
||||
guideId: interaction.channel.guild_id,
|
||||
channelId: interaction.channel_id,
|
||||
},
|
||||
"Received interaction",
|
||||
);
|
||||
const { type } = interaction;
|
||||
|
||||
if (type === 1) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user