generated from nhcarrigan/template
feat: analytics
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
import { DiscordAnalytics } from "@nhcarrigan/discord-analytics";
|
||||
import { Client, Events } from "discord.js";
|
||||
import { about } from "./modules/about.js";
|
||||
import { translate } from "./modules/translate.js";
|
||||
@@ -29,7 +30,10 @@ const client = new Client({
|
||||
intents: [],
|
||||
});
|
||||
|
||||
const analytics = new DiscordAnalytics(client, logger);
|
||||
|
||||
client.on(Events.InteractionCreate, (interaction) => {
|
||||
void analytics.logGatewayEvent(Events.InteractionCreate, { ...interaction });
|
||||
if (interaction.isMessageContextMenuCommand()) {
|
||||
void translate(interaction);
|
||||
}
|
||||
@@ -48,6 +52,7 @@ client.on(Events.EntitlementDelete, (entitlement) => {
|
||||
|
||||
client.on(Events.ClientReady, () => {
|
||||
void logger.log("debug", "Bot is ready.");
|
||||
analytics.startCron();
|
||||
});
|
||||
|
||||
instantiateServer();
|
||||
|
||||
@@ -111,6 +111,11 @@ export const translate = async(
|
||||
translation: translation.translatedText,
|
||||
}),
|
||||
});
|
||||
await logger.metric("translation", 1, {
|
||||
locale: targetLocale,
|
||||
sourceLocale: sourceLocale?.language ?? "default to en",
|
||||
user: interaction.user.id,
|
||||
});
|
||||
} catch (error) {
|
||||
const targetLocale = getLocale(interaction);
|
||||
await replyToError(interaction, targetLocale);
|
||||
|
||||
Reference in New Issue
Block a user