feat: set up analytics
Node.js CI / Lint and Test (push) Successful in 42s

This commit is contained in:
2025-10-07 17:51:48 -07:00
parent c72cbcbf1d
commit 71f11bfe37
5 changed files with 71 additions and 6 deletions
+6
View File
@@ -0,0 +1,6 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
"eslint.validate": ["typescript"]
}
+2 -1
View File
@@ -22,7 +22,8 @@
"typescript": "5.9.2" "typescript": "5.9.2"
}, },
"dependencies": { "dependencies": {
"@nhcarrigan/logger": "1.0.0", "@nhcarrigan/discord-analytics": "0.0.3",
"@nhcarrigan/logger": "1.1.1",
"discord.js": "14.21.0", "discord.js": "14.21.0",
"fastify": "5.5.0" "fastify": "5.5.0"
} }
+54 -5
View File
@@ -8,9 +8,12 @@ importers:
.: .:
dependencies: dependencies:
'@nhcarrigan/discord-analytics':
specifier: 0.0.3
version: 0.0.3(@nhcarrigan/logger@1.1.1)(discord.js@14.21.0)
'@nhcarrigan/logger': '@nhcarrigan/logger':
specifier: 1.0.0 specifier: 1.1.1
version: 1.0.0 version: 1.1.1
discord.js: discord.js:
specifier: 14.21.0 specifier: 14.21.0
version: 14.21.0 version: 14.21.0
@@ -334,6 +337,12 @@ packages:
'@jridgewell/sourcemap-codec@1.5.5': '@jridgewell/sourcemap-codec@1.5.5':
resolution: {integrity: sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==} resolution: {integrity: sha512-cYQ9310grqxueWbl+WuIUIaiUaDcj7WOq5fVhEljNVgRfOUhY9fy2zTvfoqWsnebh8Sl70VScFbICvJnLKB0Og==}
'@nhcarrigan/discord-analytics@0.0.3':
resolution: {integrity: sha512-XUHcvS3ZbuwVpztHH7pC0T/C8nOJt/T5qz7pDKp3/4Kvlbg0UdeVSZio27QkLqRtB/CvNUS78xM3k9odwN1M7A==}
peerDependencies:
'@nhcarrigan/logger': '>=1.1.0-hotfix'
discord.js: ^14.0.0
'@nhcarrigan/eslint-config@5.2.0': '@nhcarrigan/eslint-config@5.2.0':
resolution: {integrity: sha512-YpTTqhviKMlRwKF+RC/GYiA5i2jTCmg8uftuiufldneNV5HMbGpTfBbV7tpa8++5mpYJc4+eZaf40QbDiz84dQ==} resolution: {integrity: sha512-YpTTqhviKMlRwKF+RC/GYiA5i2jTCmg8uftuiufldneNV5HMbGpTfBbV7tpa8++5mpYJc4+eZaf40QbDiz84dQ==}
engines: {node: '>=22', pnpm: '>=9'} engines: {node: '>=22', pnpm: '>=9'}
@@ -344,8 +353,8 @@ packages:
typescript: '>=5' typescript: '>=5'
vitest: '>=2' vitest: '>=2'
'@nhcarrigan/logger@1.0.0': '@nhcarrigan/logger@1.1.1':
resolution: {integrity: sha512-2e19Bie+ZKb6yKPKjhawqsENkhHatYkvBAmFZx9eToOXdOca+CYi51tldRMtejg6e0+4hOOf2bo5zdBQKmH0dw==} resolution: {integrity: sha512-P6OEQFHDtf6psybYGljuCxkSW6DLQCsx1aZZ3w4YKBXHBFjDbhuvpM9K1kPhVN48hakitx2WPLEoIFr6YZELYw==}
'@nhcarrigan/typescript-config@4.0.0': '@nhcarrigan/typescript-config@4.0.0':
resolution: {integrity: sha512-969HVha7A/Sg77fuMwOm6p14a+7C5iE6g55OD71srqwKIgksQl+Ex/hAI/pyzTQFDQ/FBJbpnHlR4Ov25QV/rw==} resolution: {integrity: sha512-969HVha7A/Sg77fuMwOm6p14a+7C5iE6g55OD71srqwKIgksQl+Ex/hAI/pyzTQFDQ/FBJbpnHlR4Ov25QV/rw==}
@@ -855,6 +864,10 @@ packages:
core-js-compat@3.45.0: core-js-compat@3.45.0:
resolution: {integrity: sha512-gRoVMBawZg0OnxaVv3zpqLLxaHmsubEGyTnqdpI/CEBvX4JadI1dMSHxagThprYRtSVbuQxvi6iUatdPxohHpA==} resolution: {integrity: sha512-gRoVMBawZg0OnxaVv3zpqLLxaHmsubEGyTnqdpI/CEBvX4JadI1dMSHxagThprYRtSVbuQxvi6iUatdPxohHpA==}
cron-parser@4.9.0:
resolution: {integrity: sha512-p0SaNjrHOnQeR8/VnfGbmg9te2kfyYSQ7Sc/j/6DtPL3JQvKxmjO9TSjNFpujqV3vEYYBvNNvXSxzyksBWAx1Q==}
engines: {node: '>=12.0.0'}
cross-spawn@7.0.6: cross-spawn@7.0.6:
resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==} resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==}
engines: {node: '>= 8'} engines: {node: '>= 8'}
@@ -1500,6 +1513,9 @@ packages:
lodash@4.17.21: lodash@4.17.21:
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==} resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
long-timeout@0.1.1:
resolution: {integrity: sha512-BFRuQUqc7x2NWxfJBCyUrN8iYUYznzL9JROmRz1gZ6KlOIgmoD+njPVbb+VNn2nGMKggMsK79iUNErillsrx7w==}
loose-envify@1.4.0: loose-envify@1.4.0:
resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==} resolution: {integrity: sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==}
hasBin: true hasBin: true
@@ -1507,6 +1523,10 @@ packages:
loupe@3.2.0: loupe@3.2.0:
resolution: {integrity: sha512-2NCfZcT5VGVNX9mSZIxLRkEAegDGBpuQZBy13desuHeVORmBDyAET4TkJr4SjqQy3A8JDofMN6LpkK8Xcm/dlw==} resolution: {integrity: sha512-2NCfZcT5VGVNX9mSZIxLRkEAegDGBpuQZBy13desuHeVORmBDyAET4TkJr4SjqQy3A8JDofMN6LpkK8Xcm/dlw==}
luxon@3.7.2:
resolution: {integrity: sha512-vtEhXh/gNjI9Yg1u4jX/0YVPMvxzHuGgCm6tC5kZyb08yjGWGnqAjGJvcXbqQR2P3MyMEFnRbpcdFS6PBcLqew==}
engines: {node: '>=12'}
magic-bytes.js@1.12.1: magic-bytes.js@1.12.1:
resolution: {integrity: sha512-ThQLOhN86ZkJ7qemtVRGYM+gRgR8GEXNli9H/PMvpnZsE44Xfh3wx9kGJaldg314v85m+bFW6WBMaVHJc/c3zA==} resolution: {integrity: sha512-ThQLOhN86ZkJ7qemtVRGYM+gRgR8GEXNli9H/PMvpnZsE44Xfh3wx9kGJaldg314v85m+bFW6WBMaVHJc/c3zA==}
@@ -1553,6 +1573,10 @@ packages:
node-releases@2.0.19: node-releases@2.0.19:
resolution: {integrity: sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==} resolution: {integrity: sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==}
node-schedule@2.1.1:
resolution: {integrity: sha512-OXdegQq03OmXEjt2hZP33W2YPs/E5BcFQks46+G2gAxs4gHOIVD1u7EqlYLYSKsaIpyKCK9Gbk0ta1/gjRSMRQ==}
engines: {node: '>=6'}
normalize-package-data@2.5.0: normalize-package-data@2.5.0:
resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==} resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==}
@@ -1882,6 +1906,9 @@ packages:
sonic-boom@4.2.0: sonic-boom@4.2.0:
resolution: {integrity: sha512-INb7TM37/mAcsGmc9hyyI6+QR3rR1zVRu36B0NeGXKnOOLiZOfER5SA+N7X7k3yUYRzLWafduTDvJAfDswwEww==} resolution: {integrity: sha512-INb7TM37/mAcsGmc9hyyI6+QR3rR1zVRu36B0NeGXKnOOLiZOfER5SA+N7X7k3yUYRzLWafduTDvJAfDswwEww==}
sorted-array-functions@1.3.0:
resolution: {integrity: sha512-2sqgzeFlid6N4Z2fUQ1cvFmTOLRi/sEDzSQ0OKYchqgoPmQBVyM3959qYx3fpS6Esef80KjmpgPeEr028dP3OA==}
source-map-js@1.2.1: source-map-js@1.2.1:
resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==}
engines: {node: '>=0.10.0'} engines: {node: '>=0.10.0'}
@@ -2443,6 +2470,12 @@ snapshots:
'@jridgewell/sourcemap-codec@1.5.5': {} '@jridgewell/sourcemap-codec@1.5.5': {}
'@nhcarrigan/discord-analytics@0.0.3(@nhcarrigan/logger@1.1.1)(discord.js@14.21.0)':
dependencies:
'@nhcarrigan/logger': 1.1.1
discord.js: 14.21.0
node-schedule: 2.1.1
'@nhcarrigan/eslint-config@5.2.0(@typescript-eslint/utils@8.39.1(eslint@9.33.0)(typescript@5.9.2))(eslint@9.33.0)(playwright@1.54.2)(react@19.1.1)(typescript@5.9.2)(vitest@3.2.4(@types/node@24.2.1))': '@nhcarrigan/eslint-config@5.2.0(@typescript-eslint/utils@8.39.1(eslint@9.33.0)(typescript@5.9.2))(eslint@9.33.0)(playwright@1.54.2)(react@19.1.1)(typescript@5.9.2)(vitest@3.2.4(@types/node@24.2.1))':
dependencies: dependencies:
'@eslint-community/eslint-plugin-eslint-comments': 4.4.1(eslint@9.33.0) '@eslint-community/eslint-plugin-eslint-comments': 4.4.1(eslint@9.33.0)
@@ -2472,7 +2505,7 @@ snapshots:
- eslint-import-resolver-webpack - eslint-import-resolver-webpack
- supports-color - supports-color
'@nhcarrigan/logger@1.0.0': {} '@nhcarrigan/logger@1.1.1': {}
'@nhcarrigan/typescript-config@4.0.0(typescript@5.9.2)': '@nhcarrigan/typescript-config@4.0.0(typescript@5.9.2)':
dependencies: dependencies:
@@ -3024,6 +3057,10 @@ snapshots:
dependencies: dependencies:
browserslist: 4.25.2 browserslist: 4.25.2
cron-parser@4.9.0:
dependencies:
luxon: 3.7.2
cross-spawn@7.0.6: cross-spawn@7.0.6:
dependencies: dependencies:
path-key: 3.1.1 path-key: 3.1.1
@@ -3872,12 +3909,16 @@ snapshots:
lodash@4.17.21: {} lodash@4.17.21: {}
long-timeout@0.1.1: {}
loose-envify@1.4.0: loose-envify@1.4.0:
dependencies: dependencies:
js-tokens: 4.0.0 js-tokens: 4.0.0
loupe@3.2.0: {} loupe@3.2.0: {}
luxon@3.7.2: {}
magic-bytes.js@1.12.1: {} magic-bytes.js@1.12.1: {}
magic-string@0.30.17: magic-string@0.30.17:
@@ -3913,6 +3954,12 @@ snapshots:
node-releases@2.0.19: {} node-releases@2.0.19: {}
node-schedule@2.1.1:
dependencies:
cron-parser: 4.9.0
long-timeout: 0.1.1
sorted-array-functions: 1.3.0
normalize-package-data@2.5.0: normalize-package-data@2.5.0:
dependencies: dependencies:
hosted-git-info: 2.8.9 hosted-git-info: 2.8.9
@@ -4287,6 +4334,8 @@ snapshots:
dependencies: dependencies:
atomic-sleep: 1.0.0 atomic-sleep: 1.0.0
sorted-array-functions@1.3.0: {}
source-map-js@1.2.1: {} source-map-js@1.2.1: {}
spdx-correct@3.2.0: spdx-correct@3.2.0:
+6
View File
@@ -4,6 +4,7 @@
* @author Naomi Carrigan * @author Naomi Carrigan
*/ */
import { DiscordAnalytics } from "@nhcarrigan/discord-analytics";
import { Client, GatewayIntentBits, Events, MessageFlags } from "discord.js"; import { Client, GatewayIntentBits, Events, MessageFlags } from "discord.js";
import { blocks } from "./config/blocks.js"; import { blocks } from "./config/blocks.js";
import { checkAltText } from "./modules/checkAltText.js"; import { checkAltText } from "./modules/checkAltText.js";
@@ -18,18 +19,23 @@ const client = new Client({
], ],
}); });
const analytics = new DiscordAnalytics(client, logger);
client.once(Events.ClientReady, () => { client.once(Events.ClientReady, () => {
void logger.log( void logger.log(
"info", "info",
`Logged in as ${client.user?.username ?? "unknown user"}`, `Logged in as ${client.user?.username ?? "unknown user"}`,
); );
analytics.startCron();
}); });
client.on(Events.MessageCreate, (message) => { client.on(Events.MessageCreate, (message) => {
void analytics.logGatewayEvent(Events.MessageCreate, { ...message });
void checkAltText(message); void checkAltText(message);
}); });
client.on(Events.InteractionCreate, (interaction) => { client.on(Events.InteractionCreate, (interaction) => {
void analytics.logGatewayEvent(Events.InteractionCreate, { ...interaction });
if (!interaction.isChatInputCommand()) { if (!interaction.isChatInputCommand()) {
return; return;
} }
+3
View File
@@ -6,6 +6,7 @@
import { reminders } from "../config/reminders.js"; import { reminders } from "../config/reminders.js";
import { getRandomValue } from "../utils/getRandomValue.js"; import { getRandomValue } from "../utils/getRandomValue.js";
import { logger } from "../utils/logger.js";
import type { Message } from "discord.js"; import type { Message } from "discord.js";
/** /**
@@ -32,5 +33,7 @@ export const checkAltText = async(message: Message): Promise<void> => {
}).catch(() => { }).catch(() => {
return null; return null;
}); });
await logger.metric("alt_text_missing", 1, {});
} }
}; };