mirror of
https://github.com/artiemis/artemis.js.git
synced 2026-02-14 10:21:54 +00:00
improve errors
This commit is contained in:
parent
a59dd8a32a
commit
1568439a42
@ -5,7 +5,9 @@ import {
|
|||||||
Collection,
|
Collection,
|
||||||
GatewayIntentBits,
|
GatewayIntentBits,
|
||||||
InteractionContextType,
|
InteractionContextType,
|
||||||
|
lazy,
|
||||||
Partials,
|
Partials,
|
||||||
|
TextChannel,
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
import { REST } from "@discordjs/rest";
|
import { REST } from "@discordjs/rest";
|
||||||
import { env } from "./env";
|
import { env } from "./env";
|
||||||
@ -56,6 +58,19 @@ export class ArtemisClient extends Client {
|
|||||||
return this.users.fetch(this.ownerId);
|
return this.users.fetch(this.ownerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getDevWebhook = lazy(async () => {
|
||||||
|
const channel = (await client.channels.fetch(
|
||||||
|
env.DEV_CHANNEL_ID
|
||||||
|
)) as TextChannel;
|
||||||
|
return channel
|
||||||
|
.fetchWebhooks()
|
||||||
|
.then(
|
||||||
|
webhooks =>
|
||||||
|
webhooks.find(wh => wh.applicationId === env.APPLICATION_ID) ??
|
||||||
|
channel.createWebhook({ name: "artemis" })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
async loadCommands() {
|
async loadCommands() {
|
||||||
const commandsDir = path.join(import.meta.dir, "commands");
|
const commandsDir = path.join(import.meta.dir, "commands");
|
||||||
const categories = await fs
|
const categories = await fs
|
||||||
|
|||||||
@ -52,7 +52,7 @@ export async function translateImpl(
|
|||||||
target
|
target
|
||||||
).catch(err => {
|
).catch(err => {
|
||||||
logger.error(err, "DeepL error, falling back to Google Translate");
|
logger.error(err, "DeepL error, falling back to Google Translate");
|
||||||
sendErrorAlert(err);
|
sendErrorAlert(err, { source, target, ocrModel });
|
||||||
return translateGoogle(text, "auto", "en");
|
return translateGoogle(text, "auto", "en");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -88,7 +88,7 @@ export async function ocrImpl(url: string) {
|
|||||||
const result = await lensOcr(compressed)
|
const result = await lensOcr(compressed)
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
logger.error(err, "Google Lens error, falling back to Yandex");
|
logger.error(err, "Google Lens error, falling back to Yandex");
|
||||||
sendErrorAlert(err);
|
sendErrorAlert(err, { mime: type.mime });
|
||||||
return yandexOcr(compressed, type.mime);
|
return yandexOcr(compressed, type.mime);
|
||||||
})
|
})
|
||||||
.catch(() => abort("Failed to OCR the image"));
|
.catch(() => abort("Failed to OCR the image"));
|
||||||
|
|||||||
@ -75,7 +75,11 @@ async function handleChatInputCommand(
|
|||||||
const trace = nanoid();
|
const trace = nanoid();
|
||||||
content += `\ntrace: ${inlineCode(trace)}`;
|
content += `\ntrace: ${inlineCode(trace)}`;
|
||||||
logger.error({ trace, err });
|
logger.error({ trace, err });
|
||||||
sendErrorAlert(err, trace);
|
sendErrorAlert(err, {
|
||||||
|
trace,
|
||||||
|
command: command.data.name,
|
||||||
|
user: `${interaction.user.id} (${interaction.user.tag})`,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
await interaction[
|
await interaction[
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { codeBlock } from "discord.js";
|
import { bold, codeBlock } from "discord.js";
|
||||||
import { client } from "../client";
|
import { client } from "../client";
|
||||||
|
|
||||||
export class ExplicitCommandError extends Error {}
|
export class ExplicitCommandError extends Error {}
|
||||||
@ -13,10 +13,25 @@ export function isExplicitCommandError(
|
|||||||
return error instanceof ExplicitCommandError;
|
return error instanceof ExplicitCommandError;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function sendErrorAlert(error: any, trace?: string) {
|
export async function sendErrorAlert(
|
||||||
return client.getOwner().then(owner =>
|
error: any,
|
||||||
owner.send({
|
meta?: Record<string, string | null | undefined>
|
||||||
content: trace,
|
) {
|
||||||
|
const owner = await client.getOwner();
|
||||||
|
const webhook = await client.getDevWebhook();
|
||||||
|
|
||||||
|
return webhook.send({
|
||||||
|
username: "artemis error",
|
||||||
|
avatarURL: "https://files.catbox.moe/g52ano.png",
|
||||||
|
allowedMentions: { users: [owner.id] },
|
||||||
|
content:
|
||||||
|
`${owner}\n` +
|
||||||
|
(meta
|
||||||
|
? Object.entries(meta)
|
||||||
|
.filter(([_, value]) => value)
|
||||||
|
.map(([key, value]) => `${bold(key)}: ${value}`)
|
||||||
|
.join("\n")
|
||||||
|
: ""),
|
||||||
embeds: [
|
embeds: [
|
||||||
{
|
{
|
||||||
title: "Unhandled Error",
|
title: "Unhandled Error",
|
||||||
@ -24,6 +39,5 @@ export async function sendErrorAlert(error: any, trace?: string) {
|
|||||||
color: 0xff0000,
|
color: 0xff0000,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user