feat: core chunk 8

This commit is contained in:
TrèsAbhi committed 2023-10-14 11:36:48 -05:00
1 parent 01dd7ad9c6
commit ec00bdf9de
14 files changed
+14 -14

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
import throwError from '../../LEGACY_core/node/throwError';
import throwError from '../blitzkrieg/throwError';
export type BlitzResponse<Data extends object> =
| {
+1 -1
View File
@@ -1,7 +1,7 @@
import { Region } from '../../constants/regions';
import { WARGAMING_APPLICATION_ID } from '../../constants/wargamingApplicationID';
import throwError from '../../LEGACY_core/node/throwError';
import { TanksStats } from '../../types/tanksStats';
import throwError from '../blitzkrieg/throwError';
import fetchBlitz from './fetchWargaming';
export default async function getTankStats(region: Region, id: number) {
+1 -1
View File
@@ -1,5 +1,5 @@
import { go } from 'fuzzysort';
import throwError from '../../LEGACY_core/node/throwError';
import throwError from '../blitzkrieg/throwError';
import { TANKS, tankopedia } from '../blitzstars/tankopedia';
export default async function resolveTankId(tank: string | number) {
@@ -1,8 +1,8 @@
import throwError from '../../LEGACY_core/node/throwError';
import { RatingsInfo } from '../../commands/ratings';
import { Region } from '../../constants/regions';
import { DATABASE_REPO } from './getMidnightLeaderboard';
import { octokit } from './octokit';
import throwError from './throwError';
const ARCHIVED_RATINGS_CACHE: Record<
Region,
+1 -1
View File
@@ -1,4 +1,4 @@
import { Octokit } from '@octokit/rest';
import { secrets } from '../../LEGACY_core/node/secrets';
import { secrets } from './secrets';
export const octokit = new Octokit({ auth: secrets.GH_TOKEN });
+29
View File
@@ -0,0 +1,29 @@
import { client } from '../discord/client';
import { discordBlitzDB } from './discordBlitz';
const EXIT_EVENTS = [
'beforeExit',
'exit',
'SIGINT',
'SIGTERM',
'SIGUSR1',
'SIGUSR2',
];
async function cleanup() {
console.log('Cleaning up...');
await Promise.all([discordBlitzDB.$disconnect(), client.destroy()]);
console.log('Gracefully exiting...');
EXIT_EVENTS.forEach((event) => process.off(event, cleanup));
process.exit(0);
}
export function registerProcesses() {
process.on('uncaughtException', console.error);
client.on('error', console.error);
EXIT_EVENTS.forEach((event) => process.on(event, cleanup));
}
+25
View File
@@ -0,0 +1,25 @@
import { config } from 'dotenv';
config();
export const SECRET_KEYS = [
'DISCORD_TOKEN',
'GH_TOKEN',
'DISCORD_BLITZ_DB',
] as const;
export type SECRET = typeof SECRET_KEYS extends readonly (infer T)[]
? T
: never;
export const secrets = SECRET_KEYS.reduce<Partial<Record<SECRET, string>>>(
(accumulator, key) => ({
...accumulator,
get [key](): string {
if (!(key in process.env)) throw new Error(`Secret ${key} not provided`);
return process.env[key]!;
},
}),
{},
) as Record<SECRET, string>;
+3
View File
@@ -0,0 +1,3 @@
export default function throwError(message: string, cause?: string) {
return new Error(message, { cause });
}
+1 -1
View File
@@ -1,7 +1,7 @@
import { ChatInputCommandInteraction } from 'discord.js';
import throwError from '../../LEGACY_core/node/throwError';
import { Region } from '../../constants/regions';
import searchClansAcrossRegions from '../blitz/searchClansAcrossRegions';
import throwError from '../blitzkrieg/throwError';
import { serverAndIdPattern } from './resolvePlayerFromCommand';
export default async function resolveClanFromCommand(
+1 -1
View File
@@ -1,9 +1,9 @@
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
import markdownEscape from 'markdown-escape';
import throwError from '../../LEGACY_core/node/throwError';
import { Region } from '../../constants/regions';
import searchPlayersAcrossRegions from '../blitz/searchPlayersAcrossRegions';
import { getBlitzFromDiscord } from '../blitzkrieg/discordBlitz';
import throwError from '../blitzkrieg/throwError';
export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;