Merge pull request #6 from tresabhi/1.7.0

This commit is contained in:
TrèsAbhi authored and GitHub committed 2023-06-09 20:33:42 -05:00
commit fe2f9c34f8
27 files changed
+205 -226

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
name: CI Build
on: [push, pull_request]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18.x]
steps:
- name: Get code
uses: actions/checkout@v3
- name: Use node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install Yarn
run: npm install --location=global yarn
- name: Use node_modules cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
run: yarn
- name: Build
run: yarn build
- name: Archive build
uses: actions/upload-artifact@v3
with:
name: dist
path: dist
+1 -1
View File
@@ -44,4 +44,4 @@ jobs:
run: yarn
- name: Host
run: yarn run start discord-token=${{ secrets.DISCORD_TOKEN }} wargaming-application-id=${{ secrets.WARGAMING_APPLICATION_ID }}
run: yarn dev discord-token=${{ secrets.DISCORD_TOKEN }} wargaming-application-id=${{ secrets.WARGAMING_APPLICATION_ID }}
+1
View File
@@ -4,3 +4,4 @@ package-lock.json
/test-results/
/playwright-report/
/playwright/.cache/
dist/
+5 -3
View File
@@ -5,7 +5,9 @@
"main": "index.js",
"type": "module",
"scripts": {
"start": "vite-node src/index.ts --script",
"dev": "yarn build && yarn start",
"start": "node --enable-source-maps dist/index.cjs",
"build": "rm -rf dist && esbuild src/index.ts --outfile=dist/index.cjs --bundle --platform=node --loader:.node=copy --minify --sourcemap",
"lint": "tsc"
},
"license": "MIT",
@@ -28,7 +30,7 @@
"@types/markdown-escape": "^1.1.0",
"@types/node": "^20.2.1",
"@types/react": "^18.2.7",
"typescript": "^5.0.4",
"vite-node": "^0.31.1"
"esbuild": "^0.17.19",
"typescript": "^5.0.4"
}
}
+2 -2
View File
@@ -13,7 +13,7 @@ import cmdName from '../core/interaction/cmdName.js';
import negativeEmbed from '../core/interaction/negativeEmbed.js';
import positiveEmbed from '../core/interaction/positiveEmbed.js';
import addUsernameOption from '../core/options/addUsernameOption.js';
import { args } from '../core/process/args.js';
import { wargamingApplicationId } from '../core/process/args.js';
import { CommandRegistry } from '../events/interactionCreate.js';
import { AccountInfo } from '../types/accountInfo.js';
@@ -51,7 +51,7 @@ export default {
const clan = interaction.options.getString('clan') as SkilledClan;
const { id, server } = await getBlitzAccount(interaction);
const accountInfo = await getWargamingResponse<AccountInfo>(
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`,
);
const problems: TableInput = [];
const title = `${accountInfo[id].nickname}'s eligibility for ${SKILLED_CLANS[clan]}`;
+5 -5
View File
@@ -10,7 +10,7 @@ import getBlitzClan from '../core/blitz/getBlitzClan.js';
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import cmdName from '../core/interaction/cmdName.js';
import addClanChoices from '../core/options/addClanChoices.js';
import { args } from '../core/process/args.js';
import { wargamingApplicationId } from '../core/process/args.js';
import render from '../core/ui/render.js';
import { CommandRegistry } from '../events/interactionCreate.js';
import { AccountInfo } from '../types/accountInfo.js';
@@ -44,14 +44,14 @@ export default {
const time = new Date().getTime() / 1000;
const clanData = (
await getWargamingResponse<ClanInfo>(
`https://api.wotblitz.${server}/wotb/clans/info/?application_id=${args['wargaming-application-id']}&clan_id=${id}`,
`https://api.wotblitz.${server}/wotb/clans/info/?application_id=${wargamingApplicationId}&clan_id=${id}`,
)
)[id];
const memberIds = clanData.members_ids;
const accounts = await getWargamingResponse<AccountInfo>(
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${
args['wargaming-application-id']
}&account_id=${memberIds.join(',')}`,
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${memberIds.join(
',',
)}`,
);
const inactive = memberIds
.map((memberId) => {
+3 -3
View File
@@ -12,7 +12,7 @@ import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import { TIER_ROMAN_NUMERALS, tankopedia } from '../core/blitz/tankopedia.js';
import cmdName from '../core/interaction/cmdName.js';
import addUsernameOption from '../core/options/addUsernameOption.js';
import { args } from '../core/process/args.js';
import { wargamingApplicationId } from '../core/process/args.js';
import render from '../core/ui/render.js';
import { CommandRegistry } from '../events/interactionCreate.js';
import { AccountInfo } from '../types/accountInfo.js';
@@ -62,14 +62,14 @@ export default {
const account = await getBlitzAccount(interaction);
const { id, server } = account;
const accountInfo = await getWargamingResponse<AccountInfo>(
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`,
);
const tankStats = await getTankStats(interaction, server, id);
const tanks = tankStats
.map((tankData) => tankopedia[tankData.tank_id])
.filter((tank) => tank?.tier === tier);
const clanData = await getWargamingResponse<PlayerClanData>(
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`,
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${wargamingApplicationId}&account_id=${id}&extra=clan`,
);
console.time('ownedtanks');
+3 -3
View File
@@ -8,7 +8,7 @@ import cleanTable, { TableInputEntry } from '../core/interaction/cleanTable.js';
import cmdName from '../core/interaction/cmdName.js';
import infoEmbed from '../core/interaction/infoEmbed.js';
import addUsernameOption from '../core/options/addUsernameOption.js';
import { args } from '../core/process/args.js';
import { wargamingApplicationId } from '../core/process/args.js';
import { CommandRegistry } from '../events/interactionCreate.js';
import { AccountAchievements } from '../types/accountAchievements.js';
import { AccountInfo } from '../types/accountInfo.js';
@@ -39,11 +39,11 @@ export default {
const account = await getBlitzAccount(interaction);
const { id, server } = account;
const accounts = await getWargamingResponse<AccountInfo>(
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`,
);
const accountsAchievements =
await getWargamingResponse<AccountAchievements>(
`https://api.wotblitz.${server}/wotb/account/achievements/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
`https://api.wotblitz.${server}/wotb/account/achievements/?application_id=${wargamingApplicationId}&account_id=${id}`,
);
const accountAchievements = accountsAchievements[id];
const compound = {
+2 -2
View File
@@ -7,7 +7,7 @@ import cleanTable from '../core/interaction/cleanTable.js';
import cmdName from '../core/interaction/cmdName.js';
import infoEmbed from '../core/interaction/infoEmbed.js';
import addUsernameOption from '../core/options/addUsernameOption.js';
import { args } from '../core/process/args.js';
import { wargamingApplicationId } from '../core/process/args.js';
import { CommandRegistry } from '../events/interactionCreate.js';
import { AccountInfo } from '../types/accountInfo.js';
@@ -25,7 +25,7 @@ export default {
const account = await getBlitzAccount(interaction);
const { id, server } = account;
const accounts = await getWargamingResponse<AccountInfo>(
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`,
);
const accountInfo = accounts[id];
+2 -2
View File
@@ -6,7 +6,7 @@ import cmdName from '../core/interaction/cmdName.js';
import infoEmbed from '../core/interaction/infoEmbed.js';
import addClanChoices from '../core/options/addClanChoices.js';
import addServerChoices from '../core/options/addServerChoices.js';
import { args } from '../core/process/args.js';
import { wargamingApplicationId } from '../core/process/args.js';
import { CommandRegistry } from '../events/interactionCreate.js';
import { ClanList } from '../types/clanList.js';
@@ -33,7 +33,7 @@ export default {
const clan = interaction.options.getString('clan')!;
const limit = interaction.options.getInteger('limit') ?? 25;
const clanList = await getWargamingResponse<ClanList>(
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${clan}&limit=${limit}`,
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${wargamingApplicationId}&search=${clan}&limit=${limit}`,
);
await interaction.editReply({
+4 -4
View File
@@ -7,7 +7,7 @@ import cmdName from '../core/interaction/cmdName.js';
import infoEmbed from '../core/interaction/infoEmbed.js';
import addServerChoices from '../core/options/addServerChoices.js';
import addUsernameOption from '../core/options/addUsernameOption.js';
import { args } from '../core/process/args.js';
import { wargamingApplicationId } from '../core/process/args.js';
import { CommandRegistry } from '../events/interactionCreate.js';
import { AccountList } from '../types/accountList.js';
@@ -38,9 +38,9 @@ export default {
const trimmedSearch = name.trim();
const players = usernamePattern.test(trimmedSearch)
? await getWargamingResponse<AccountList>(
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${
args['wargaming-application-id']
}&search=${encodeURIComponent(trimmedSearch)}&limit=${limit}`,
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${wargamingApplicationId}&search=${encodeURIComponent(
trimmedSearch,
)}&limit=${limit}`,
)
: [];
+3 -3
View File
@@ -28,7 +28,7 @@ import addStatPeriodChoices, {
statPeriodNames,
} from '../core/options/addStatPeriodChoices.js';
import addUsernameOption from '../core/options/addUsernameOption.js';
import { args } from '../core/process/args.js';
import { wargamingApplicationId } from '../core/process/args.js';
import render from '../core/ui/render.js';
import { CommandRegistry } from '../events/interactionCreate.js';
import {
@@ -53,10 +53,10 @@ export default {
const period = interaction.options.getString('period') as StatPeriod;
const { id, server } = await getBlitzAccount(interaction);
const accountInfo = await getWargamingResponse<AccountInfo>(
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`,
);
const clanData = await getWargamingResponse<PlayerClanData>(
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`,
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${wargamingApplicationId}&account_id=${id}&extra=clan`,
);
const tankStats = await getTankStats(interaction, server, id);
let stats: AllStats;
+2 -2
View File
@@ -33,7 +33,7 @@ import addStatPeriodChoices, {
} from '../core/options/addStatPeriodChoices.js';
import addTankChoices from '../core/options/addTankChoices.js';
import addUsernameOption from '../core/options/addUsernameOption.js';
import { args } from '../core/process/args.js';
import { wargamingApplicationId } from '../core/process/args.js';
import render from '../core/ui/render.js';
import { CommandRegistry } from '../events/interactionCreate.js';
import { AccountInfo, AllStats } from '../types/accountInfo.js';
@@ -59,7 +59,7 @@ export default {
const blitzAccount = await getBlitzAccount(interaction);
const { id, server } = blitzAccount;
const accountInfo = await getWargamingResponse<AccountInfo>(
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`,
);
const tankStats = await getTankStats(interaction, server, id);
let stats: AllStats;
+3 -3
View File
@@ -24,7 +24,7 @@ import cmdName from '../core/interaction/cmdName.js';
import fullBlitzStarsStats from '../core/interaction/fullBlitzStarsStats.js';
import { supportBlitzStars } from '../core/interaction/supportBlitzStars.js';
import addUsernameOption from '../core/options/addUsernameOption.js';
import { args } from '../core/process/args.js';
import { wargamingApplicationId } from '../core/process/args.js';
import render from '../core/ui/render.js';
import { CommandRegistry } from '../events/interactionCreate.js';
import { AccountInfo, AllStats } from '../types/accountInfo.js';
@@ -50,10 +50,10 @@ export default {
new Date().getTime() / 1000,
);
const accountInfo = await getWargamingResponse<AccountInfo>(
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`,
);
const clanData = await getWargamingResponse<PlayerClanData>(
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`,
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${wargamingApplicationId}&account_id=${id}&extra=clan`,
);
const careerTankStatsRaw = await getTankStats(interaction, server, id);
const careerStats: Record<number, AllStats> = {
+3 -3
View File
@@ -7,7 +7,7 @@ import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import cmdName from '../core/interaction/cmdName.js';
import addUsernameOption from '../core/options/addUsernameOption.js';
import { args } from '../core/process/args.js';
import { wargamingApplicationId } from '../core/process/args.js';
import { CommandRegistry } from '../events/interactionCreate.js';
import { AccountInfo } from '../types/accountInfo.js';
import { PlayerClanData } from '../types/playerClanData.js';
@@ -26,10 +26,10 @@ export default {
const blitzAccount = await getBlitzAccount(interaction);
const { id, server } = blitzAccount;
const accountInfo = await getWargamingResponse<AccountInfo>(
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`,
);
const clanData = await getWargamingResponse<PlayerClanData>(
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${id}&extra=clan`,
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${wargamingApplicationId}&account_id=${id}&extra=clan`,
);
const clan = clanData[id]?.clan;
const clanTag = clan ? ` [${clan!.tag}]` : '';
+2 -2
View File
@@ -1,7 +1,7 @@
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js';
import { TanksStats } from '../../types/tanksStats.js';
import { args } from '../process/args.js';
import { wargamingApplicationId } from '../process/args.js';
import errorWithCause from '../process/errorWithCause.js';
import getWargamingResponse from './getWargamingResponse.js';
@@ -11,7 +11,7 @@ export default async function getTankStats(
id: number,
) {
const tankStats = await getWargamingResponse<TanksStats>(
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${wargamingApplicationId}&account_id=${id}`,
);
if (tankStats[id] === null) {
+4 -4
View File
@@ -1,6 +1,6 @@
import { BlitzServer } from '../../constants/servers.js';
import { Account, AccountList } from '../../types/accountList.js';
import { args } from '../process/args.js';
import { wargamingApplicationId } from '../process/args.js';
import getWargamingResponse from './getWargamingResponse.js';
export type AccountListWithServer = (Account & {
@@ -19,7 +19,7 @@ export default async function listAccountsPanServer(search: string, limit = 9) {
return (
await Promise.all([
getWargamingResponse<AccountList>(
`https://api.wotblitz.com/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${encodedSearch}&limit=${normalizedLimit}`,
`https://api.wotblitz.com/wotb/account/list/?application_id=${wargamingApplicationId}&search=${encodedSearch}&limit=${normalizedLimit}`,
).then(
(value) =>
value &&
@@ -29,7 +29,7 @@ export default async function listAccountsPanServer(search: string, limit = 9) {
})),
),
getWargamingResponse<AccountList>(
`https://api.wotblitz.eu/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${encodedSearch}&limit=${normalizedLimit}`,
`https://api.wotblitz.eu/wotb/account/list/?application_id=${wargamingApplicationId}&search=${encodedSearch}&limit=${normalizedLimit}`,
).then(
(value) =>
value &&
@@ -39,7 +39,7 @@ export default async function listAccountsPanServer(search: string, limit = 9) {
})),
),
getWargamingResponse<AccountList>(
`https://api.wotblitz.asia/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${encodedSearch}&limit=${normalizedLimit}`,
`https://api.wotblitz.asia/wotb/account/list/?application_id=${wargamingApplicationId}&search=${encodedSearch}&limit=${normalizedLimit}`,
).then(
(value) =>
value &&
+4 -4
View File
@@ -1,6 +1,6 @@
import { BlitzServer } from '../../constants/servers.js';
import { Clan, ClanList } from '../../types/clanList.js';
import { args } from '../process/args.js';
import { wargamingApplicationId } from '../process/args.js';
import getWargamingResponse from './getWargamingResponse.js';
export type ClanListWithServer = (Clan & {
@@ -15,7 +15,7 @@ export default async function listClansPanServer(search: string, limit = 9) {
return (
await Promise.all([
getWargamingResponse<ClanList>(
`https://api.wotblitz.com/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`,
`https://api.wotblitz.com/wotb/clans/list/?application_id=${wargamingApplicationId}&search=${search}&limit=${normalizedLimit}`,
).then(
(value) =>
value &&
@@ -25,7 +25,7 @@ export default async function listClansPanServer(search: string, limit = 9) {
})),
),
getWargamingResponse<ClanList>(
`https://api.wotblitz.eu/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`,
`https://api.wotblitz.eu/wotb/clans/list/?application_id=${wargamingApplicationId}&search=${search}&limit=${normalizedLimit}`,
).then(
(value) =>
value &&
@@ -35,7 +35,7 @@ export default async function listClansPanServer(search: string, limit = 9) {
})),
),
getWargamingResponse<ClanList>(
`https://api.wotblitz.asia/wotb/clans/list/?application_id=${args['wargaming-application-id']}&search=${search}&limit=${normalizedLimit}`,
`https://api.wotblitz.asia/wotb/clans/list/?application_id=${wargamingApplicationId}&search=${search}&limit=${normalizedLimit}`,
).then(
(value) =>
value &&
+13 -6
View File
@@ -18,13 +18,20 @@ export interface Tankopedia {
[id: number]: TankopediaEntry;
}
export const tankopedia: Tankopedia = {};
console.log('Caching tankopedia...');
export const tankopedia = (
(await (
await fetch('https://www.blitzstars.com/bs-tankopedia.json')
).json()) as WargamingResponse<Tankopedia> & { status: 'ok' }
).data;
console.log('Cached tankopedia');
fetch('https://www.blitzstars.com/bs-tankopedia.json')
.then(
(response) =>
response.json() as Promise<
WargamingResponse<Tankopedia> & { status: 'ok' }
>,
)
.then((wargamingResponse) => {
Object.assign(tankopedia, wargamingResponse.data);
console.log('Cached tankopedia');
});
export const TANK_ICONS: Record<TankType, string> = {
'AT-SPG': 'https://i.imgur.com/BIHSEH0.png',
+11 -10
View File
@@ -63,7 +63,7 @@ export interface MeanSd {
spbSd: number;
}
export interface IndividualTankAverages {
export interface IndividualTankAverage {
_id: number;
battle_life_time: number;
total_battle_life_time: number;
@@ -78,13 +78,14 @@ export interface IndividualTankAverages {
last_update: number;
}
console.log('Caching tank averages...');
const tankAveragesRaw = (await (
await fetch('https://www.blitzstars.com/api/tankaverages.json')
).json()) as IndividualTankAverages[];
export const tankAverages: Record<number, IndividualTankAverages> = {};
export const tankAverages: Record<number, IndividualTankAverage> = {};
Object.entries(tankAveragesRaw).forEach(([, tank]) => {
tankAverages[tank.tank_id] = tank;
});
console.log('Tank averages cached');
console.log('Caching tank averages...');
fetch('https://www.blitzstars.com/api/tankaverages.json')
.then((response) => response.json() as Promise<IndividualTankAverage[]>)
.then((individualTankAverages) => {
individualTankAverages.forEach((individualTankAverage) => {
tankAverages[individualTankAverage.tank_id] = individualTankAverage;
});
console.log('Tank averages cached');
});
+1
View File
@@ -0,0 +1 @@
/// <reference types="vite/client" />
+4 -1
View File
@@ -3,7 +3,7 @@ import errorWithCause from './errorWithCause.js';
type ArgumentName = 'discord-token' | 'wargaming-application-id';
export const args: Record<ArgumentName, string> = {
const args: Record<ArgumentName, string> = {
'discord-token': '',
'wargaming-application-id': '',
};
@@ -23,3 +23,6 @@ Object.keys(args).forEach((arg) => {
);
}
});
export const discordToken = args['discord-token'];
export const wargamingApplicationId = args['wargaming-application-id'];
+9 -3
View File
@@ -6,8 +6,12 @@ import satori from 'satori';
const FONT_NAME = 'Roboto';
const FONT_FILES = ['Roboto', 'Roboto-Bold', 'Roboto-Black'];
let robotoFlex: Buffer;
let robotoFlexBold: Buffer;
let robotoFlexBlack: Buffer;
console.log('Importing fonts...');
const [robotoFlex, robotoFlexBold, robotoFlexBlack] = await Promise.all(
Promise.all(
FONT_FILES.map(
(file) =>
new Promise<Buffer>((resolve, reject) => {
@@ -17,8 +21,10 @@ const [robotoFlex, robotoFlexBold, robotoFlexBlack] = await Promise.all(
});
}),
),
);
console.log('Fonts imported');
).then((data) => {
[robotoFlex, robotoFlexBold, robotoFlexBlack] = data;
console.log('Fonts imported');
});
export default async function render(element: ReactNode) {
const svg = await satori(element, {
-2
View File
@@ -37,6 +37,4 @@ export function registerErrorHandlers() {
client.on(name, (error) => handleError(error, 'client error')),
);
}
return client;
}
+63 -33
View File
@@ -5,17 +5,29 @@ import {
ButtonStyle,
CacheType,
ChatInputCommandInteraction,
Collection,
Interaction,
REST,
RESTPostAPIChatInputApplicationCommandsJSONBody,
Routes,
SlashCommandBuilder,
} from 'discord.js';
import { readdirSync } from 'fs';
import discord from '../../discord.json' assert { type: 'json' };
import debug from '../commands/debug.js';
import eligible from '../commands/eligible.js';
import help from '../commands/help.js';
import inactive from '../commands/inactive.js';
import ownedtanks from '../commands/ownedtanks.js';
import playerachievements from '../commands/playerachievements.js';
import playerinfo from '../commands/playerinfo.js';
import searchclans from '../commands/searchclans.js';
import searchplayers from '../commands/searchplayers.js';
import searchtanks from '../commands/searchtanks.js';
import stats from '../commands/stats.js';
import tankstats from '../commands/tankstats.js';
import today from '../commands/today.js';
import verify from '../commands/verify.js';
import negativeEmbed from '../core/interaction/negativeEmbed.js';
import { args } from '../core/process/args.js';
import { discordToken } from '../core/process/args.js';
import getClientId from '../core/process/getClientId.js';
import isDev from '../core/process/isDev.js';
import { handleError } from './error.js';
@@ -30,52 +42,70 @@ export interface CommandRegistry {
autocomplete?: (interaction: AutocompleteInteraction<CacheType>) => void;
}
const rest = new REST().setToken(args['discord-token']);
const rest = new REST().setToken(discordToken);
const commands = [
debug,
eligible,
help,
inactive,
ownedtanks,
playerachievements,
playerinfo,
searchclans,
searchplayers,
searchtanks,
stats,
tankstats,
today,
verify,
].reduce<Record<string, CommandRegistry>>((accumulator, registry) => {
return { ...accumulator, [registry.command.name]: registry };
}, {});
const commandFolders = readdirSync('src/commands/');
const commandCollection = new Collection<string, CommandRegistry>();
export const guildCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =
[];
export const publicCommands: RESTPostAPIChatInputApplicationCommandsJSONBody[] =
[];
for (const file of commandFolders) {
const command = (await import(`../commands/${file}`))
.default as CommandRegistry;
if (isDev() ? command.inDevelopment : command.inProduction) {
if (command.inPublic) {
publicCommands.push(command.command.toJSON());
Object.entries(commands).forEach(([, registry]) => {
if (isDev() ? registry.inDevelopment : registry.inProduction) {
if (registry.inPublic) {
publicCommands.push(registry.command.toJSON());
} else {
guildCommands.push(command.command.toJSON());
guildCommands.push(registry.command.toJSON());
}
commandCollection.set(command.command.name, command);
}
}
});
try {
console.log(`Refreshing ${publicCommands.length} public command(s).`);
const publicData = (await rest.put(
Routes.applicationCommands(getClientId()),
{ body: publicCommands },
)) as RESTPostAPIChatInputApplicationCommandsJSONBody[];
console.log(`Successfully refreshed ${publicData.length} public command(s).`);
rest
.put(Routes.applicationCommands(getClientId()), { body: publicCommands })
.then((publicData) => {
console.log(
`Successfully refreshed ${
(publicData as RESTPostAPIChatInputApplicationCommandsJSONBody[])
.length
} public command(s).`,
);
});
console.log(`Refreshing ${guildCommands.length} guild command(s).`);
const guildData = [
...((await rest.put(
Promise.all([
rest.put(
Routes.applicationGuildCommands(getClientId(), discord.sklld_guild_id),
{ body: guildCommands },
)) as RESTPostAPIChatInputApplicationCommandsJSONBody[]),
...((await rest.put(
),
rest.put(
Routes.applicationGuildCommands(getClientId(), discord.tres_guild_id),
{ body: guildCommands },
)) as RESTPostAPIChatInputApplicationCommandsJSONBody[]),
];
console.log(
`Successfully refreshed ${guildData.length / 2} guild command(s).`,
);
),
]).then((guildData) => {
console.log(
`Successfully refreshed ${guildData.flat().length / 2} guild command(s).`,
);
});
} catch (error) {
console.error(error);
}
@@ -84,7 +114,7 @@ export default async function interactionCreate(
interaction: Interaction<CacheType>,
) {
if (interaction.isAutocomplete()) {
const command = commandCollection.get(interaction.commandName);
const command = commands[interaction.commandName];
if (!command) {
console.error(
@@ -95,7 +125,7 @@ export default async function interactionCreate(
if (command.autocomplete) command.autocomplete(interaction);
} else if (interaction.isChatInputCommand()) {
const command = commandCollection.get(interaction.commandName);
const command = commands[interaction.commandName];
if (!command) {
console.error(
+6 -8
View File
@@ -1,5 +1,5 @@
import { Client, GatewayIntentBits } from 'discord.js';
import { args } from './core/process/args.js';
import { discordToken } from './core/process/args.js';
import { registerErrorHandlers } from './events/error.js';
import guildMemberAdd from './events/guildMemberAdd.js';
import interactionCreate from './events/interactionCreate.js';
@@ -7,12 +7,10 @@ import ready from './events/ready.js';
export const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers],
});
registerErrorHandlers();
client
})
.on('ready', ready)
.on('guildMemberAdd', guildMemberAdd)
.on('interactionCreate', interactionCreate)
.login(args['discord-token']);
.on('interactionCreate', interactionCreate);
registerErrorHandlers();
client.login(discordToken);
+2 -117
View File
@@ -333,11 +333,6 @@
dependencies:
"@types/node" "*"
acorn@^8.8.2:
version "8.8.2"
resolved "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz"
integrity sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==
[email protected]:
version "0.0.8"
resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-0.0.8.tgz#1101e9544f4a76b1bc3b26d452ca96d7a35e7978"
@@ -355,11 +350,6 @@ busboy@^1.6.0:
dependencies:
streamsearch "^1.1.0"
cac@^6.7.14:
version "6.7.14"
resolved "https://registry.npmjs.org/cac/-/cac-6.7.14.tgz"
integrity sha512-b6Ilus+c3RrdDk+JhLKUAQfzzgLEPy6wcXqS7f/xe1EETvsDP6GORG7SFuOs6cID5YkqchW/LXZbX5bc8j7ZcQ==
camelize@^1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/camelize/-/camelize-1.0.1.tgz#89b7e16884056331a35d6b5ad064332c91daa6c3"
@@ -399,13 +389,6 @@ csstype@^3.0.2:
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b"
integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==
debug@^4.3.4:
version "4.3.4"
resolved "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
dependencies:
ms "2.1.2"
discord-api-types@^0.37.37:
version "0.37.39"
resolved "https://registry.npmjs.org/discord-api-types/-/discord-api-types-0.37.39.tgz"
@@ -435,9 +418,9 @@ emoji-regex@^10.2.1:
resolved "https://registry.yarnpkg.com/emoji-regex/-/emoji-regex-10.2.1.tgz#a41c330d957191efd3d9dfe6e1e8e1e9ab048b3f"
integrity sha512-97g6QgOk8zlDRdgq1WxwgTMgEWGVAQvB5Fdpgc1MkNy56la5SKP9GsMXKDOdqwn90/41a8yPwIGk1Y6WVbeMQA==
esbuild@^0.17.5:
esbuild@^0.17.19:
version "0.17.19"
resolved "https://registry.npmjs.org/esbuild/-/esbuild-0.17.19.tgz"
resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.17.19.tgz#087a727e98299f0462a3d0bcdd9cd7ff100bd955"
integrity sha512-XQ0jAPFkK/u3LcVRcvVHQcTIqD6E2H1fvZMA5dQPSOWb3suUbWbfbRf94pjc0bNzRYLfIrDRQXr7X+LHIm5oHw==
optionalDependencies:
"@esbuild/android-arm" "0.17.19"
@@ -487,11 +470,6 @@ file-type@^18.2.1:
strtok3 "^7.0.0"
token-types "^5.0.1"
fsevents@~2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.2.tgz#8a526f78b8fdf4623b709e0b975c52c24c02fd1a"
integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==
fuzzysort@^2.0.4:
version "2.0.4"
resolved "https://registry.npmjs.org/fuzzysort/-/fuzzysort-2.0.4.tgz"
@@ -517,11 +495,6 @@ inherits@^2.0.3:
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
jsonc-parser@^3.2.0:
version "3.2.0"
resolved "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.2.0.tgz"
integrity sha512-gfFQZrcTc8CnKXp6Y4/CBT3fTc0OVuDofpre4aEeEpSBPV5X5v4+Vmx+8snU7RLPrNHPKSgLxGo9YuQzz20o+w==
linebreak@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/linebreak/-/linebreak-1.1.0.tgz#831cf378d98bced381d8ab118f852bd50d81e46b"
@@ -557,26 +530,6 @@ markdown-escape@^2.0.0:
resolved "https://registry.npmjs.org/markdown-escape/-/markdown-escape-2.0.0.tgz"
integrity sha512-Trz4v0+XWlwy68LJIyw3bLbsJiC8XAbRCKF9DbEtZjyndKOGVx6n+wNB0VfoRmY2LKboQLeniap3xrb6LGSJ8A==
mlly@^1.2.0:
version "1.2.1"
resolved "https://registry.npmjs.org/mlly/-/mlly-1.2.1.tgz"
integrity sha512-1aMEByaWgBPEbWV2BOPEMySRrzl7rIHXmQxam4DM8jVjalTQDjpN2ZKOLUrwyhfZQO7IXHml2StcHMhooDeEEQ==
dependencies:
acorn "^8.8.2"
pathe "^1.1.0"
pkg-types "^1.0.3"
ufo "^1.1.2"
[email protected]:
version "2.1.2"
resolved "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz"
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==
nanoid@^3.3.6:
version "3.3.6"
resolved "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz"
integrity sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==
pako@^0.2.5:
version "0.2.9"
resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75"
@@ -590,44 +543,16 @@ parse-css-color@^0.2.1:
color-name "^1.1.4"
hex-rgb "^4.1.0"
pathe@^1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/pathe/-/pathe-1.1.0.tgz"
integrity sha512-ODbEPR0KKHqECXW1GoxdDb+AZvULmXjVPy4rt+pGo2+TnjJTIPJQSVS6N63n8T2Ip+syHhbn52OewKicV0373w==
peek-readable@^5.0.0:
version "5.0.0"
resolved "https://registry.npmjs.org/peek-readable/-/peek-readable-5.0.0.tgz"
integrity sha512-YtCKvLUOvwtMGmrniQPdO7MwPjgkFBtFIrmfSbYmYuq3tKDV/mcfAhBth1+C3ru7uXIZasc/pHnb+YDYNkkj4A==
picocolors@^1.0.0:
version "1.0.0"
resolved "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz"
integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==
pkg-types@^1.0.3:
version "1.0.3"
resolved "https://registry.npmjs.org/pkg-types/-/pkg-types-1.0.3.tgz"
integrity sha512-nN7pYi0AQqJnoLPC9eHFQ8AcyaixBUOwvqc5TDnIKCMEE6I0y8P7OKA7fPexsXGCGxQDl/cmrLAp26LhcwxZ4A==
dependencies:
jsonc-parser "^3.2.0"
mlly "^1.2.0"
pathe "^1.1.0"
postcss-value-parser@^4.0.2, postcss-value-parser@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz#723c09920836ba6d3e5af019f92bc0971c02e514"
integrity sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==
postcss@^8.4.23:
version "8.4.23"
resolved "https://registry.npmjs.org/postcss/-/postcss-8.4.23.tgz"
integrity sha512-bQ3qMcpF6A/YjR55xtoTr0jGOlnPOKAIMdOWiv0EIT6HVPEaJiJB4NLljSbiHoC2RX7DN5Uvjtpbg1NPdwv1oA==
dependencies:
nanoid "^3.3.6"
picocolors "^1.0.0"
source-map-js "^1.0.2"
react@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
@@ -651,13 +576,6 @@ readable-web-to-node-stream@^3.0.2:
dependencies:
readable-stream "^3.6.0"
rollup@^3.21.0:
version "3.22.0"
resolved "https://registry.npmjs.org/rollup/-/rollup-3.22.0.tgz"
integrity sha512-imsigcWor5Y/dC0rz2q0bBt9PabcL3TORry2hAa6O6BuMvY71bqHyfReAz5qyAqiQATD1m70qdntqBfBQjVWpQ==
optionalDependencies:
fsevents "~2.3.2"
safe-buffer@~5.2.0:
version "5.2.1"
resolved "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz"
@@ -678,11 +596,6 @@ satori@^0.9.1:
postcss-value-parser "^4.2.0"
yoga-wasm-web "^0.3.3"
source-map-js@^1.0.2:
version "1.0.2"
resolved "https://registry.npmjs.org/source-map-js/-/source-map-js-1.0.2.tgz"
integrity sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==
streamsearch@^1.1.0:
version "1.1.0"
resolved "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz"
@@ -736,11 +649,6 @@ typescript@^5.0.4:
resolved "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz"
integrity sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==
ufo@^1.1.2:
version "1.1.2"
resolved "https://registry.npmjs.org/ufo/-/ufo-1.1.2.tgz"
integrity sha512-TrY6DsjTQQgyS3E3dBaOXf0TpPD8u9FVrVYmKVegJuFw51n/YB9XPt+U6ydzFG5ZIN7+DIjPbNmXoBj9esYhgQ==
undici@^5.21.0:
version "5.21.2"
resolved "https://registry.npmjs.org/undici/-/undici-5.21.2.tgz"
@@ -761,29 +669,6 @@ util-deprecate@^1.0.1:
resolved "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz"
integrity sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==
vite-node@^0.31.1:
version "0.31.1"
resolved "https://registry.npmjs.org/vite-node/-/vite-node-0.31.1.tgz"
integrity sha512-BajE/IsNQ6JyizPzu9zRgHrBwczkAs0erQf/JRpgTIESpKvNj9/Gd0vxX905klLkb0I0SJVCKbdrl5c6FnqYKA==
dependencies:
cac "^6.7.14"
debug "^4.3.4"
mlly "^1.2.0"
pathe "^1.1.0"
picocolors "^1.0.0"
vite "^3.0.0 || ^4.0.0"
"vite@^3.0.0 || ^4.0.0":
version "4.3.8"
resolved "https://registry.npmjs.org/vite/-/vite-4.3.8.tgz"
integrity sha512-uYB8PwN7hbMrf4j1xzGDk/lqjsZvCDbt/JC5dyfxc19Pg8kRm14LinK/uq+HSLNswZEoKmweGdtpbnxRtrAXiQ==
dependencies:
esbuild "^0.17.5"
postcss "^8.4.23"
rollup "^3.21.0"
optionalDependencies:
fsevents "~2.3.2"
ws@^8.13.0:
version "8.13.0"
resolved "https://registry.npmjs.org/ws/-/ws-8.13.0.tgz"