diff --git a/.github/workflows/host.yml b/.github/workflows/host.yml index 1f512bc5f..3c8036d95 100644 --- a/.github/workflows/host.yml +++ b/.github/workflows/host.yml @@ -8,40 +8,31 @@ on: - 'main' workflow_dispatch: -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - jobs: host: - name: Host runs-on: ubuntu-latest - strategy: - matrix: - node-version: [18.x] - steps: - - name: Get code - uses: actions/checkout@v2 - - name: Use node uses: actions/setup-node@v2 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@v2 + - name: Get latest release + uses: actions/github-script@v4 with: - path: '**/node_modules' - key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} + script: | + const response = await github.repos.getLatestRelease({ + owner: context.repo.owner, + repo: context.repo.repo + }); + console.log(response.data.assets[0].browser_download_url); + core.setOutput("download_url", response.data.assets[0].browser_download_url); - - name: Install dependencies - run: yarn + - name: Download release assets + run: | + curl -L -o dist.zip ${{ steps.get-latest-release.outputs.download_url }} + unzip dist.zip - - name: Host - run: NODE_ENV=production DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} WARGAMING_APPLICATION_ID=${{ secrets.WARGAMING_APPLICATION_ID }} yarn dev --dev + - name: Run index.cjs + run: NODE_ENV=production DISCORD_TOKEN=${{ secrets.DISCORD_TOKEN }} WARGAMING_APPLICATION_ID=${{ secrets.WARGAMING_APPLICATION_ID }} node --enable-source-maps dist/index.cjs diff --git a/.gitignore b/.gitignore index ddca36103..7702a7f6d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ package-lock.json /playwright/.cache/ dist/ yarn-error.log +dist.zip \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 06a367ecb..e44870599 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,7 @@ "cleandist", "fuzzysort", "kranvagn", + "outfile", "ownedtanks", "Resvg", "searchplayers", diff --git a/package.json b/package.json index b48311bd6..b7e103244 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,9 @@ "type": "module", "scripts": { "dev": "yarn build && yarn start", - "start": "node --enable-source-maps dist/server.cjs", - "cleandist": "rm -rf dist", - "build:raw": "npx esbuild src/index.ts --outfile=dist/server.cjs --platform=node --bundle --sourcemap --loader:.node=copy --loader:.ttf=file", - "build:package": "cp package.dist.json dist/package.json", - "build": "yarn cleandist && yarn build:raw && yarn build:package", + "start": "node --enable-source-maps dist/index.cjs", + "zip": "zip -r dist.zip dist", + "build": "node scripts/build", "lint": "tsc" }, "license": "MIT", diff --git a/scripts/build.js b/scripts/build.js new file mode 100644 index 000000000..975ff801b --- /dev/null +++ b/scripts/build.js @@ -0,0 +1,23 @@ +import { build } from 'esbuild'; +import { rmSync } from 'fs'; + +console.log('Removing dist...'); +rmSync('dist', { recursive: true, force: true }); + +console.log('Creating context...'); +build({ + entryPoints: ['src/index.ts'], + outfile: 'dist/index.cjs', + + platform: 'node', + loader: { + '.node': 'copy', + '.ttf': 'file', + }, + + bundle: true, + sourcemap: true, + minifyIdentifiers: false, // causes errors + minifySyntax: true, + minifyWhitespace: true, +}); diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts index 934f80c1b..f6a65bd33 100644 --- a/src/commands/eligible.ts +++ b/src/commands/eligible.ts @@ -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 { wargamingApplicationId } from '../core/process/args.js'; +import { WARGAMING_APPLICATION_ID } 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( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const problems: TableInput = []; const title = `${accountInfo[id].nickname}'s eligibility for ${SKILLED_CLANS[clan]}`; diff --git a/src/commands/inactive.tsx b/src/commands/inactive.tsx index ddca68934..9b91fa8eb 100644 --- a/src/commands/inactive.tsx +++ b/src/commands/inactive.tsx @@ -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 { wargamingApplicationId } from '../core/process/args.js'; +import { WARGAMING_APPLICATION_ID } 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,12 +44,12 @@ export default { const time = new Date().getTime() / 1000; const clanData = ( await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/info/?application_id=${wargamingApplicationId}&clan_id=${id}`, + `https://api.wotblitz.${server}/wotb/clans/info/?application_id=${WARGAMING_APPLICATION_ID}&clan_id=${id}`, ) )[id]; const memberIds = clanData.members_ids; const accounts = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${memberIds.join( + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${memberIds.join( ',', )}`, ); diff --git a/src/commands/ownedtanks.tsx b/src/commands/ownedtanks.tsx index 1eb80b433..98df0be0f 100644 --- a/src/commands/ownedtanks.tsx +++ b/src/commands/ownedtanks.tsx @@ -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 { wargamingApplicationId } from '../core/process/args.js'; +import { WARGAMING_APPLICATION_ID } 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( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&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( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${wargamingApplicationId}&account_id=${id}&extra=clan`, + `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`, ); const image = await render( diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index ed865dc40..cbe3626fd 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -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 { wargamingApplicationId } from '../core/process/args.js'; +import { WARGAMING_APPLICATION_ID } 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( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const accountsAchievements = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/achievements/?application_id=${wargamingApplicationId}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/achievements/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const accountAchievements = accountsAchievements[id]; const compound = { diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index a6f91953e..46a3eefb8 100644 --- a/src/commands/playerinfo.ts +++ b/src/commands/playerinfo.ts @@ -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 { wargamingApplicationId } from '../core/process/args.js'; +import { WARGAMING_APPLICATION_ID } 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( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const accountInfo = accounts[id]; diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index 3b6a50345..28216932d 100644 --- a/src/commands/searchclans.ts +++ b/src/commands/searchclans.ts @@ -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 { wargamingApplicationId } from '../core/process/args.js'; +import { WARGAMING_APPLICATION_ID } 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( - `https://api.wotblitz.${server}/wotb/clans/list/?application_id=${wargamingApplicationId}&search=${clan}&limit=${limit}`, + `https://api.wotblitz.${server}/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`, ); await interaction.editReply({ diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index 83bc9ae79..1f29125e5 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -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 { wargamingApplicationId } from '../core/process/args.js'; +import { WARGAMING_APPLICATION_ID } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; import { AccountList } from '../types/accountList.js'; @@ -38,7 +38,7 @@ export default { const trimmedSearch = name.trim(); const players = usernamePattern.test(trimmedSearch) ? await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/account/list/?application_id=${wargamingApplicationId}&search=${encodeURIComponent( + `https://api.wotblitz.${server}/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodeURIComponent( trimmedSearch, )}&limit=${limit}`, ) diff --git a/src/commands/stats.tsx b/src/commands/stats.tsx index 947eeba37..9939e2c20 100644 --- a/src/commands/stats.tsx +++ b/src/commands/stats.tsx @@ -28,7 +28,7 @@ import addStatPeriodChoices, { statPeriodNames, } from '../core/options/addStatPeriodChoices.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; -import { wargamingApplicationId } from '../core/process/args.js'; +import { WARGAMING_APPLICATION_ID } 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( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const clanData = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${wargamingApplicationId}&account_id=${id}&extra=clan`, + `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`, ); const tankStats = await getTankStats(interaction, server, id); let stats: AllStats; diff --git a/src/commands/tankstats.tsx b/src/commands/tankstats.tsx index e1844b937..baae75a9c 100644 --- a/src/commands/tankstats.tsx +++ b/src/commands/tankstats.tsx @@ -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 { wargamingApplicationId } from '../core/process/args.js'; +import { WARGAMING_APPLICATION_ID } 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( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const tankStats = await getTankStats(interaction, server, id); let stats: AllStats; diff --git a/src/commands/today.tsx b/src/commands/today.tsx index 8aab43f1d..887e3f27a 100644 --- a/src/commands/today.tsx +++ b/src/commands/today.tsx @@ -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 { wargamingApplicationId } from '../core/process/args.js'; +import { WARGAMING_APPLICATION_ID } 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( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const clanData = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${wargamingApplicationId}&account_id=${id}&extra=clan`, + `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`, ); const careerTankStatsRaw = await getTankStats(interaction, server, id); const careerStats: Record = { diff --git a/src/commands/verify.ts b/src/commands/verify.ts index b88566c6b..7fbfdeabc 100644 --- a/src/commands/verify.ts +++ b/src/commands/verify.ts @@ -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 { wargamingApplicationId } from '../core/process/args.js'; +import { WARGAMING_APPLICATION_ID } 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( - `https://api.wotblitz.${server}/wotb/account/info/?application_id=${wargamingApplicationId}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); const clanData = await getWargamingResponse( - `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${wargamingApplicationId}&account_id=${id}&extra=clan`, + `https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}&extra=clan`, ); const clan = clanData[id]?.clan; const clanTag = clan ? ` [${clan!.tag}]` : ''; diff --git a/src/core/blitz/getTankStats.ts b/src/core/blitz/getTankStats.ts index 912dbce02..334dfbc23 100644 --- a/src/core/blitz/getTankStats.ts +++ b/src/core/blitz/getTankStats.ts @@ -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 { wargamingApplicationId } from '../process/args.js'; +import { WARGAMING_APPLICATION_ID } 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( - `https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${wargamingApplicationId}&account_id=${id}`, + `https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${id}`, ); if (tankStats[id] === null) { diff --git a/src/core/blitz/listAccountsPanServer.ts b/src/core/blitz/listAccountsPanServer.ts index b868eb8a5..f09069ba7 100644 --- a/src/core/blitz/listAccountsPanServer.ts +++ b/src/core/blitz/listAccountsPanServer.ts @@ -1,6 +1,6 @@ import { BlitzServer } from '../../constants/servers.js'; import { Account, AccountList } from '../../types/accountList.js'; -import { wargamingApplicationId } from '../process/args.js'; +import { WARGAMING_APPLICATION_ID } 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( - `https://api.wotblitz.com/wotb/account/list/?application_id=${wargamingApplicationId}&search=${encodedSearch}&limit=${normalizedLimit}`, + `https://api.wotblitz.com/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -29,7 +29,7 @@ export default async function listAccountsPanServer(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.eu/wotb/account/list/?application_id=${wargamingApplicationId}&search=${encodedSearch}&limit=${normalizedLimit}`, + `https://api.wotblitz.eu/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -39,7 +39,7 @@ export default async function listAccountsPanServer(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.asia/wotb/account/list/?application_id=${wargamingApplicationId}&search=${encodedSearch}&limit=${normalizedLimit}`, + `https://api.wotblitz.asia/wotb/account/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${encodedSearch}&limit=${normalizedLimit}`, ).then( (value) => value && diff --git a/src/core/blitz/listClansPanServer.ts b/src/core/blitz/listClansPanServer.ts index cf81c97ff..2d5fc148c 100644 --- a/src/core/blitz/listClansPanServer.ts +++ b/src/core/blitz/listClansPanServer.ts @@ -1,6 +1,6 @@ import { BlitzServer } from '../../constants/servers.js'; import { Clan, ClanList } from '../../types/clanList.js'; -import { wargamingApplicationId } from '../process/args.js'; +import { WARGAMING_APPLICATION_ID } 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( - `https://api.wotblitz.com/wotb/clans/list/?application_id=${wargamingApplicationId}&search=${search}&limit=${normalizedLimit}`, + `https://api.wotblitz.com/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -25,7 +25,7 @@ export default async function listClansPanServer(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.eu/wotb/clans/list/?application_id=${wargamingApplicationId}&search=${search}&limit=${normalizedLimit}`, + `https://api.wotblitz.eu/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`, ).then( (value) => value && @@ -35,7 +35,7 @@ export default async function listClansPanServer(search: string, limit = 9) { })), ), getWargamingResponse( - `https://api.wotblitz.asia/wotb/clans/list/?application_id=${wargamingApplicationId}&search=${search}&limit=${normalizedLimit}`, + `https://api.wotblitz.asia/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${search}&limit=${normalizedLimit}`, ).then( (value) => value && diff --git a/src/core/process/args.ts b/src/core/process/args.ts index 0a9d3ad5d..dc8797b8c 100644 --- a/src/core/process/args.ts +++ b/src/core/process/args.ts @@ -1,11 +1,9 @@ -console.log(process.env); +export const DISCORD_TOKEN = process.env.DISCORD_TOKEN!; +export const WARGAMING_APPLICATION_ID = process.env.WARGAMING_APPLICATION_ID!; -export const discordToken = process.env.DISCORD_TOKEN!; -export const wargamingApplicationId = process.env.WARGAMING_APPLICATION_ID!; - -if (!discordToken) { +if (!DISCORD_TOKEN) { throw new Error('No Discord token provided'); } -if (!wargamingApplicationId) { +if (!WARGAMING_APPLICATION_ID) { throw new Error('No Wargaming application id provided}'); } diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 46d80e8f9..37ec47d85 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -27,7 +27,7 @@ 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 { discordToken } from '../core/process/args.js'; +import { DISCORD_TOKEN } from '../core/process/args.js'; import getClientId from '../core/process/getClientId.js'; import isDev from '../core/process/isDev.js'; import { handleError } from './error.js'; @@ -42,7 +42,7 @@ export interface CommandRegistry { autocomplete?: (interaction: AutocompleteInteraction) => void; } -const rest = new REST().setToken(discordToken); +const rest = new REST().setToken(DISCORD_TOKEN); const commands = [ debug, diff --git a/src/index.ts b/src/index.ts index caadbc5f3..53af8e31e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { Client, GatewayIntentBits } from 'discord.js'; -import { discordToken } from './core/process/args.js'; +import { DISCORD_TOKEN } from './core/process/args.js'; import { registerErrorHandlers } from './events/error.js'; import guildMemberAdd from './events/guildMemberAdd.js'; import interactionCreate from './events/interactionCreate.js'; @@ -13,4 +13,4 @@ export const client = new Client({ .on('interactionCreate', interactionCreate); registerErrorHandlers(); -client.login(discordToken); +client.login(DISCORD_TOKEN);