Skip to content

Commit

Permalink
Merge remote-tracking branch 'topple/update-dependencies'
Browse files Browse the repository at this point in the history
  • Loading branch information
emallson committed Apr 3, 2024
2 parents 3d9dd2e + fc64bfd commit f43af12
Show file tree
Hide file tree
Showing 11 changed files with 852 additions and 1,929 deletions.
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = null

[*.json]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = null
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: '17.x'
node-version: '20.x'
- run: yarn install
- run: yarn run test
- run: yarn run build
Expand Down
3 changes: 1 addition & 2 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:17-alpine
FROM node:20-alpine

# To get the latest version this requires having run `npm install`, `npm run build` prior to building the container

Expand Down
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@
"start": "nodemon --ext ts --watch src --exec \"yarn build && yarn prod\"",
"test": "jest",
"build": "tsc",
"prod": "node build/commands/registerCommands.js && NODE_ENV=production node --harmony build/index.js"
"prod": "node build/commands/registerCommands.js && NODE_ENV=production node build/index.js"
},
"dependencies": {
"@discordjs/rest": "^1.1.0",
"discord.js": "^14.3",
"dotenv": "^6.0.0",
"prom-client": "^11.1.3",
"raven": "^2.6.3",
"@discordjs/rest": "^2.2.0",
"@sentry/node": "^7.83.0",
"discord-api-types": "^0.37.65",
"discord.js": "^14.14.1",
"dotenv": "^16.3.1",
"prom-client": "^15.0.0",
"request": "^2.87.0",
"request-promise-native": "^1.0.4",
"uws": "10.148.1"
"uws": "200.0.0"
},
"devDependencies": {
"@types/jest": "^28",
"@types/raven": "^2.5.4",
"@types/request-promise-native": "^1.0.18",
"jest": "^28",
"nodemon": "^1.17.5",
"ts-jest": "^28",
"typescript": "^4.7.4"
"@tsconfig/node20": "^20.1.2",
"@types/jest": "^29.5.10",
"@types/request-promise-native": "^1.0.21",
"jest": "^29.7.0",
"nodemon": "^3.0.1",
"ts-jest": "^29.1.1",
"typescript": "^5.3.2"
}
}
3 changes: 2 additions & 1 deletion src/commands/registerCommands.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { REST } from "@discordjs/rest";
import { Routes, SlashCommandBuilder } from "discord.js";
import { SlashCommandBuilder } from "discord.js";
import { Routes } from 'discord-api-types/v10';

import "../init";

Expand Down
16 changes: 8 additions & 8 deletions src/init.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import * as Sentry from '@sentry/node';
import fs from 'fs';
import Raven from 'raven';

import loadDotEnv from './env';
import './metrics';

process.env.NODE_ENV = process.env.NODE_ENV || 'development';
process.env.NODE_ENV = process.env.NODE_ENV ?? 'development';
const appDirectory = fs.realpathSync(process.cwd());

loadDotEnv(appDirectory);

if (process.env.NODE_ENV === 'production') {
console.log('Sentry is ENABLED');
// I thought Sentry caught unhandled rejections by default now, but not so according to https://docs.sentry.io/clients/node/usage/#promises + it didn't catch some rejections
Raven.config('https://[email protected]/253783', {
captureUnhandledRejections: true
}).install();
} else {
console.log('Sentry is DISABLED');
Sentry.init({
dsn: 'https://[email protected]/253783',
tracesSampleRate: 1.0,
});

Sentry.enableAnrDetection({ captureStackTrace: true }).catch(console.error);
}
11 changes: 4 additions & 7 deletions src/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import http from 'http';
import { collectDefaultMetrics, Gauge, Counter, Histogram, register } from "prom-client";

const Prometheus = require('prom-client');

const collectDefaultMetrics = Prometheus.collectDefaultMetrics;
collectDefaultMetrics();

export const guildGauge = new Prometheus.Gauge({
export const guildGauge = new Gauge({
name: 'bot_guild_gauge',
help: 'The amount of guilds the bot is in',
});

export const messagesSentCounter = new Prometheus.Counter({
export const messagesSentCounter = new Counter({
name: 'bot_messages_sent',
help: 'The amount of messages the bot has sent',
labelNames: ['server'],
});

export const reportResponseLatencyHistogram = new Prometheus.Histogram({
export const reportResponseLatencyHistogram = new Histogram({
name: 'bot_report_response_latency',
help: 'The time it took to respond to a report',
buckets: [5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000],
Expand All @@ -26,7 +24,6 @@ export function createServer() {
const port = process.env.METRICS_PORT || 3000;
http.createServer((req, res) => {
if (req.url === '/metrics') {
const register = Prometheus.register;
res.setHeader('Connection', 'close');
res.setHeader('Content-Type', register.contentType);
res.write(register.metrics());
Expand Down
5 changes: 2 additions & 3 deletions src/onMessage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Sentry from "@sentry/node";
import { URL } from "url";
import Raven from "raven";

import parseHash from "./common/parseHash";
import extractUrls from "./extractUrls";
Expand All @@ -14,7 +14,6 @@ import * as metrics from "./metrics";
import {
ChatInputCommandInteraction,
Client,
Interaction,
Message,
PermissionsBitField,
} from "discord.js";
Expand Down Expand Up @@ -80,7 +79,7 @@ function handleReject(error: Error & { statusCode: number }): void {
debug && console.log("400 response: report does not exist or is private.");
return;
}
Raven.captureException(error);
Sentry.captureException(error);
console.error(error);
}

Expand Down
8 changes: 2 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
{
"extends": "@tsconfig/node20/tsconfig.json",
"include": ["src/**/*"],
"exclude": ["**/*.test.*", "src/__mocks__/**/*.js", "scripts"],
"compilerOptions": {
"target": "es2016",
"module": "commonjs",
"rootDir": "./src",
"allowJs": true,
"checkJs": true,
"outDir": "./build",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
"baseUrl": "."
}
}
Loading

0 comments on commit f43af12

Please sign in to comment.