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

+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 });
}