diff --git a/src/app.ts b/src/app.ts index 63b4802..50ac32c 100644 --- a/src/app.ts +++ b/src/app.ts @@ -30,29 +30,31 @@ client.on("shardError", err => { }); process.on("unhandledRejection", (reason, promise) => { - log(new Error("Unhandled Rejection:"), reason, promise); - - let message: string | Error; + let message: string; if (reason instanceof Error) { - message = reason; - } else if (typeof reason == "string") { - message = reason; + message = `${reason.name}: ${reason.message}\n${reason.stack}`; } else { message = String(reason); } + if (message.includes("Connect Timeout Error") && message.includes("10000ms")) { + // Klasika + log(new Error("Discord timeout...")); + return; + } + + log(new Error("Unhandled Rejection in app:"), reason, promise); + adminLog(client, "Unhandled Rejection", message); }); process.on("uncaughtException", (err) => { - log(new Error("Uncaught Exception:"), err); + log(new Error("Uncaught Exception in app:"), err); let message: string | Error; if (err instanceof Error) { message = err; - } else if (typeof err == "string") { - message = err; } else { message = String(err); } diff --git a/src/utils/utils.ts b/src/utils/utils.ts index c1137be..43c66b2 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -113,8 +113,12 @@ export function log(...content: unknown[]) { } export async function sendDM(user: User, txt: string) { - await sendWithoutReply(await user.createDM(), txt) - .catch(() => log(new Error(`dementovi ${user} nejde poslat DM ${txt}`))); + try { + const channel = await user.createDM(); + await sendWithoutReply(channel, txt); + } catch (e) { + log(new Error(`dementovi ${user} nejde poslat DM ${txt}`)); + } } export const rand = (max: number) => Math.floor(Math.random() * max); @@ -257,7 +261,7 @@ export async function messageReply(mes: SMessage, co: string | MessageCreateOpti } /** - * Slouží k odeslání zprávy bez odpovědi na jinou zprávu a zajistí, anti-spam mechanismus bude fungovat. + * Slouží k odeslání zprávy bez odpovědi na jinou zprávu a zajistí, že anti-spam mechanismus bude fungovat. * @param channel Kanál, kam se má zpráva odeslat * @param co Obsah zprávy, který se má odeslat */ diff --git a/src/utils/voice.ts b/src/utils/voice.ts index 1f9b047..390a5fc 100644 --- a/src/utils/voice.ts +++ b/src/utils/voice.ts @@ -72,7 +72,6 @@ export const novejJoin = (guild: Guild, channelId: string) => new Promise