feat: cleaned node

This commit is contained in:
TresAbhi committed 2023-06-27 17:22:27 +00:00
1 parent 01ed20941d
commit ab5061ba99
28 files changed
+35 -37

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
import { Client, GatewayIntentBits } from 'discord.js';
import { DISCORD_TOKEN } from './core/node/args.js';
import { DISCORD_TOKEN } from './core/node/arguments.js';
import { registerErrorHandlers } from './events/error.js';
import guildMemberAdd from './events/guildMemberAdd.js';
import interactionCreate from './events/interactionCreate/index.js';
+1 -1
View File
@@ -12,7 +12,7 @@ import embedNegative from '../core/discord/embedNegative.js';
import embedPositive from '../core/discord/embedPositive.js';
import markdownTable, { TableInput } from '../core/discord/markdownTable.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountInfo } from '../types/accountInfo.js';
+1 -1
View File
@@ -9,7 +9,7 @@ import getBlitzClan from '../core/blitz/getBlitzClan.js';
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import addClanChoices from '../core/discord/addClanChoices.js';
import autocompleteClan from '../core/discord/autocompleteClan.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountInfo } from '../types/accountInfo.js';
import { ClanInfo } from '../types/clanInfo.js';
+1 -1
View File
@@ -15,7 +15,7 @@ import {
import addUsernameChoices from '../core/discord/addUsernameChoices.js';
import autocompleteUsername from '../core/discord/autocompleteUsername.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountInfo } from '../types/accountInfo.js';
import { PlayerClanData } from '../types/playerClanData.js';
+1 -1
View File
@@ -9,7 +9,7 @@ import markdownTable, {
TableInputEntry,
} from '../core/discord/markdownTable.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountAchievements } from '../types/accountAchievements.js';
import { AccountInfo } from '../types/accountInfo.js';
+1 -1
View File
@@ -6,7 +6,7 @@ import autocompleteUsername from '../core/discord/autocompleteUsername.js';
import embedInfo from '../core/discord/embedInfo.js';
import markdownTable from '../core/discord/markdownTable.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountInfo } from '../types/accountInfo.js';
+1 -1
View File
@@ -5,7 +5,7 @@ import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import addClanChoices from '../core/discord/addClanChoices.js';
import addServerChoices from '../core/discord/addServerChoices.js';
import embedInfo from '../core/discord/embedInfo.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
import { CommandRegistry } from '../events/interactionCreate/index.js';
import { ClanList } from '../types/clanList.js';
+1 -1
View File
@@ -6,7 +6,7 @@ import { usernamePattern } from '../core/blitz/listPlayers.js';
import addServerChoices from '../core/discord/addServerChoices.js';
import addUsernameChoices from '../core/discord/addUsernameChoices.js';
import embedInfo from '../core/discord/embedInfo.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountList } from '../types/accountList.js';
+1 -1
View File
@@ -7,7 +7,7 @@ import autocompleteUsername from '../core/discord/autocompleteUsername.js';
import embedNegative from '../core/discord/embedNegative.js';
import embedPositive from '../core/discord/embedPositive.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountInfo } from '../types/accountInfo.js';
import { PlayerClanData } from '../types/playerClanData.js';
+2 -2
View File
@@ -1,6 +1,6 @@
import { BlitzServer } from '../../constants/servers.js';
import { serverAndIdPattern } from '../discord/resolvePlayerFromCommand.js';
import errorWithCause from '../node/errorWithCause.js';
import throwError from '../node/throwError.js';
import listClans from './listClans.js';
export default async function getBlitzClan(clan: string) {
@@ -13,7 +13,7 @@ export default async function getBlitzClan(clan: string) {
if (accounts[0]) {
return { server: accounts[0].server, id: accounts[0].clan_id };
} else {
throw errorWithCause(
throw throwError(
'Could not find clan',
`I couldn't find clan \`${clan}\`. Try selecting a username from the search result.`,
);
+3 -3
View File
@@ -1,7 +1,7 @@
import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js';
import { TanksStats } from '../../types/tanksStats.js';
import { WARGAMING_APPLICATION_ID } from '../node/args.js';
import errorWithCause from '../node/errorWithCause.js';
import { WARGAMING_APPLICATION_ID } from '../node/arguments.js';
import throwError from '../node/throwError.js';
import getWargamingResponse from './getWargamingResponse.js';
export default async function getTankStats(server: BlitzServer, id: number) {
@@ -10,7 +10,7 @@ export default async function getTankStats(server: BlitzServer, id: number) {
);
if (tankStats[id] === null) {
throw errorWithCause(
throw throwError(
'No tank stats available',
`Wargaming says there is no tank stats for this account. This account may not have any battles/tanks or exist in the ${BLITZ_SERVERS[server]} server.`,
);
+2 -2
View File
@@ -1,4 +1,4 @@
import errorWithCause from '../node/errorWithCause.js';
import throwError from '../node/throwError.js';
export type WargamingResponse<Data extends object> =
| {
@@ -21,7 +21,7 @@ export default async function getWargamingResponse<Data extends object>(
if (parsed.status === 'ok') {
return parsed.data;
} else {
throw errorWithCause(
throw throwError(
`Wargaming response error status:"${parsed.status}"`,
`Message: "${parsed.error.message}"\nURL: "${url}"`,
);
+1 -1
View File
@@ -1,6 +1,6 @@
import { BlitzServer } from '../../constants/servers.js';
import { Clan, ClanList } from '../../types/clanList.js';
import { WARGAMING_APPLICATION_ID } from '../node/args.js';
import { WARGAMING_APPLICATION_ID } from '../node/arguments.js';
import getWargamingResponse from './getWargamingResponse.js';
export type ClanListWithServer = (Clan & {
+1 -1
View File
@@ -1,6 +1,6 @@
import { BlitzServer } from '../../constants/servers.js';
import { Account, AccountList } from '../../types/accountList.js';
import { WARGAMING_APPLICATION_ID } from '../node/args.js';
import { WARGAMING_APPLICATION_ID } from '../node/arguments.js';
import getWargamingResponse from './getWargamingResponse.js';
export type AccountListWithServer = (Account & {
+3 -3
View File
@@ -1,5 +1,5 @@
import { go } from 'fuzzysort';
import errorWithCause from '../node/errorWithCause.js';
import throwError from '../node/throwError.js';
import { TANKS, tankopedia } from './tankopedia.js';
export default function resolveTankId(tank: string) {
@@ -9,7 +9,7 @@ export default function resolveTankId(tank: string) {
const searchResult = go(tank, TANKS, { keys: ['name'], limit: 1 });
if (searchResult.length === 0) {
throw errorWithCause(
throw throwError(
'Tank not found',
`Could not find tank by the name "${tank}".`,
);
@@ -20,7 +20,7 @@ export default function resolveTankId(tank: string) {
if (tankopedia[number]) {
return number;
} else {
throw errorWithCause(
throw throwError(
'Tank not found',
`Could not find tank by the ID "${number}".`,
);
+1 -1
View File
@@ -7,7 +7,7 @@ import {
getHistoriesDefaultOptions,
} from '../../types/histories.js';
import getWargamingResponse from '../blitz/getWargamingResponse.js';
import { WARGAMING_APPLICATION_ID } from '../node/args.js';
import { WARGAMING_APPLICATION_ID } from '../node/arguments.js';
import { emptyAllStats } from './getTankStatsDiffed.js';
export interface PlayerHistoryRaw {
File renamed without changes.
+3 -3
View File
@@ -3,7 +3,7 @@ import { BlitzServer } from '../../constants/servers.js';
import listPlayers, {
usernamePatternWithoutPosition,
} from '../blitz/listPlayers.js';
import errorWithCause from '../node/errorWithCause.js';
import throwError from '../node/throwError.js';
export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
@@ -22,7 +22,7 @@ export default async function resolvePlayerFromCommand(
const username = commandUsername ?? displayName;
if (username === undefined) {
throw errorWithCause(
throw throwError(
'Username could not be inferred',
"You didn't provide me a username in the command nor was I able to infer your Blitz username from your Discord nickname. Try providing a username manually in the command or using the `/verify` command to set your Discord nickname to your Blitz username.",
);
@@ -43,7 +43,7 @@ export default async function resolvePlayerFromCommand(
id: accounts[0].account_id,
} satisfies ResolvedPlayer;
} else {
throw errorWithCause(
throw throwError(
'Could not find user',
`I couldn't find user \`${username}\`. Try providing a valid username manually or using the \`/verify\` command to set your Discord nickname to your Blitz username.`,
);
File renamed without changes.
-3
View File
@@ -1,3 +0,0 @@
export default function errorWithCause(message: string, cause: string) {
return new Error(message, { cause });
}
+1 -3
View File
@@ -1,5 +1,3 @@
const isDevBoolean = process.env.NODE_ENV === 'development';
export default function isDev() {
return isDevBoolean;
return process.env.NODE_ENV === 'development';
}
+1 -1
View File
@@ -1,3 +1,3 @@
export default function isNumber(value: any) {
return typeof value === 'number' && !isNaN(value) && isFinite(value);
return typeof value === 'number' && isFinite(value);
}
+3
View File
@@ -0,0 +1,3 @@
export default function throwError(message: string, cause: string) {
return new Error(message, { cause });
}
@@ -8,7 +8,7 @@ import {
import embedNegative from '../../../core/discord/embedNegative.js';
import normalizeInteractionReturnable from '../../../core/discord/normalizeInteractionReturnable.js';
import embedWarning from '../../../core/discord/embedWarning.js';
import { psa } from '../../../core/node/psa.js';
import { psa } from '../../../core/discord/psa.js';
import { handleError } from '../../error.js';
import { commands } from '../index.js';
+1 -1
View File
@@ -28,7 +28,7 @@ import searchtanks from '../../commands/searchtanks.js';
import stats from '../../commands/stats.js';
import today from '../../commands/today.js';
import verify from '../../commands/verify.js';
import { DISCORD_TOKEN } from '../../core/node/args.js';
import { DISCORD_TOKEN } from '../../core/node/arguments.js';
import getClientId from '../../core/node/getClientId.js';
import isDev from '../../core/node/isDev.js';
import handleAutocomplete from './handlers/autocomplete.js';
+1 -1
View File
@@ -11,7 +11,7 @@ import getPlayerHistories from '../core/blitzstars/getPlayerHistories.js';
import getTankHistories from '../core/blitzstars/getTankHistories.js';
import { ResolvedPeriod } from '../core/discord/resolvePeriodFromCommand.js';
import { ResolvedPlayer } from '../core/discord/resolvePlayerFromCommand.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
import { AccountInfo } from '../types/accountInfo.js';
import { Histories } from '../types/histories.js';
import { PlayerClanData } from '../types/playerClanData.js';
+1 -1
View File
@@ -14,7 +14,7 @@ import getTankStatsDiffed from '../core/blitzstars/getTankStatsDiffed.js';
import { tankAverages } from '../core/blitzstars/tankAverages.js';
import { ResolvedPeriod } from '../core/discord/resolvePeriodFromCommand.js';
import { ResolvedPlayer } from '../core/discord/resolvePlayerFromCommand.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
import {
AccountInfo,
AllStats,
+1 -1
View File
@@ -15,7 +15,7 @@ import getTankStatsDiffed from '../core/blitzstars/getTankStatsDiffed.js';
import getTimeDaysAgo from '../core/blitzstars/getTimeDaysAgo.js';
import { tankAverages } from '../core/blitzstars/tankAverages.js';
import { ResolvedPlayer } from '../core/discord/resolvePlayerFromCommand.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/arguments.js';
import { AccountInfo, AllStats } from '../types/accountInfo.js';
import { PlayerClanData } from '../types/playerClanData.js';