diff --git a/.github/workflows/cd-asia-ratings-latest.yml b/.github/workflows/cd-asia-ratings-latest.yml deleted file mode 100644 index 9be005f72..000000000 --- a/.github/workflows/cd-asia-ratings-latest.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: CD Asia Ratings Latest - -on: - schedule: - - cron: "0 0 * * *" - -jobs: - host: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Use node - uses: actions/setup-node@v3 - with: - node-version: 18 - 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: Generate leaderboard - run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=asia --latest diff --git a/.github/workflows/cd-asia-ratings-leaderboards.yml b/.github/workflows/cd-asia-ratings-leaderboards.yml deleted file mode 100644 index 2462e4601..000000000 --- a/.github/workflows/cd-asia-ratings-leaderboards.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: CD Asia Ratings Leaderboards - -on: - schedule: - - cron: "0 17 * * *" - -jobs: - host: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Use node - uses: actions/setup-node@v3 - with: - node-version: 18 - 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: Generate leaderboard - run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=asia diff --git a/.github/workflows/cd-docs.yml b/.github/workflows/cd-docs.yml index 61855855e..74d93ec97 100644 --- a/.github/workflows/cd-docs.yml +++ b/.github/workflows/cd-docs.yml @@ -2,7 +2,7 @@ name: CD Docs on: push: - branches: [main] + branches: main jobs: build: diff --git a/.github/workflows/cd-eu-ratings-latest.yml b/.github/workflows/cd-ratings-asia.yml similarity index 68% rename from .github/workflows/cd-eu-ratings-latest.yml rename to .github/workflows/cd-ratings-asia.yml index c988ee70e..1c237bcb2 100644 --- a/.github/workflows/cd-eu-ratings-latest.yml +++ b/.github/workflows/cd-ratings-asia.yml @@ -1,8 +1,12 @@ -name: CD Europe Ratings Latest +name: CD Ratings Asia + +# latest: '0 0 * * *' +# asia midnight: '0 17 * * *' on: schedule: - - cron: "0 0 * * *" + - cron: '0 0 * * *' + - cron: '0 17 * * *' jobs: host: @@ -16,7 +20,7 @@ jobs: uses: actions/setup-node@v3 with: node-version: 18 - cache: "npm" + cache: 'npm' - name: Install Yarn run: npm install --location=global yarn @@ -24,11 +28,11 @@ jobs: - name: Use node_modules cache uses: actions/cache@v3 with: - path: "**/node_modules" + path: '**/node_modules' key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} - name: Install dependencies run: yarn - name: Generate leaderboard - run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=eu --latest + run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=asia --target=${{ github.event.schedule == '0 0 * * *' && 'latest' || 'midnight' }} diff --git a/.github/workflows/cd-na-ratings-latest.yml b/.github/workflows/cd-ratings-eu.yml similarity index 77% rename from .github/workflows/cd-na-ratings-latest.yml rename to .github/workflows/cd-ratings-eu.yml index ff7ab3470..1f699cfa4 100644 --- a/.github/workflows/cd-na-ratings-latest.yml +++ b/.github/workflows/cd-ratings-eu.yml @@ -1,8 +1,12 @@ -name: CD North America Ratings Latest +name: CD Ratings Europe + +# latest: '0 0 * * *' +# eu midnight: '0 23 * * *' on: schedule: - cron: '0 0 * * *' + - cron: '0 23 * * *' jobs: host: @@ -31,4 +35,4 @@ jobs: run: yarn - name: Generate leaderboard - run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=na --latest + run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=eu --target=${{ github.event.schedule == '0 0 * * *' && 'latest' || 'midnight' }} diff --git a/.github/workflows/cd-eu-ratings-leaderboards.yml b/.github/workflows/cd-ratings-na.yml similarity index 67% rename from .github/workflows/cd-eu-ratings-leaderboards.yml rename to .github/workflows/cd-ratings-na.yml index c026c483d..89b801ce0 100644 --- a/.github/workflows/cd-eu-ratings-leaderboards.yml +++ b/.github/workflows/cd-ratings-na.yml @@ -1,8 +1,12 @@ -name: CD Europe Ratings Leaderboards +name: CD Ratings North America + +# latest: '0 0 * * *' +# na midnight: '0 5 * * *' on: schedule: - - cron: "0 23 * * *" + - cron: '0 0 * * *' + - cron: '0 5 * * *' jobs: host: @@ -16,7 +20,7 @@ jobs: uses: actions/setup-node@v3 with: node-version: 18 - cache: "npm" + cache: 'npm' - name: Install Yarn run: npm install --location=global yarn @@ -24,11 +28,11 @@ jobs: - name: Use node_modules cache uses: actions/cache@v3 with: - path: "**/node_modules" + path: '**/node_modules' key: ${{ runner.os }}-modules-${{ hashFiles('**/yarn.lock') }} - name: Install dependencies run: yarn - name: Generate leaderboard - run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=eu + run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=na --target=${{ github.event.schedule == '0 0 * * *' && 'latest' || 'midnight' }} diff --git a/.github/workflows/ci-build-bot.yml b/.github/workflows/ci-build-bot.yml index 1a3f05e23..2f29938cb 100644 --- a/.github/workflows/ci-build-bot.yml +++ b/.github/workflows/ci-build-bot.yml @@ -1,6 +1,6 @@ name: CI Build Bot -on: [push, pull_request] +on: push concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/.github/workflows/ci-build-docs.yml b/.github/workflows/ci-build-docs.yml index 79c7c3095..c9dfbaca0 100644 --- a/.github/workflows/ci-build-docs.yml +++ b/.github/workflows/ci-build-docs.yml @@ -1,6 +1,6 @@ name: CI Build Docs -on: [push, pull_request] +on: push concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/.github/workflows/ci-build-website.yml b/.github/workflows/ci-build-website.yml index 4f48e8b62..66c3eb778 100644 --- a/.github/workflows/ci-build-website.yml +++ b/.github/workflows/ci-build-website.yml @@ -1,6 +1,6 @@ name: CI Build Website -on: [push, pull_request] +on: push concurrency: group: ${{ github.workflow }}-${{ github.ref }} diff --git a/.github/workflows/cd-na-ratings-leaderboards.yml b/.github/workflows/ci-version.yml similarity index 77% rename from .github/workflows/cd-na-ratings-leaderboards.yml rename to .github/workflows/ci-version.yml index 414e143a3..3e567d42d 100644 --- a/.github/workflows/cd-na-ratings-leaderboards.yml +++ b/.github/workflows/ci-version.yml @@ -1,8 +1,6 @@ -name: CD North America Ratings Leaderboards +name: CI Version -on: - schedule: - - cron: '0 5 * * *' +on: push jobs: host: @@ -31,4 +29,4 @@ jobs: run: yarn - name: Generate leaderboard - run: GH_TOKEN=${{ secrets.GH_TOKEN }} yarn publish:ratingsleaderboard --region=na + run: yarn lint:version diff --git a/.vscode/settings.json b/.vscode/settings.json index c157c2994..eebb31783 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -15,6 +15,7 @@ "fuzzysort", "immer", "kranvagn", + "krieg", "Leaderboard", "leaderboards", "MURICA", diff --git a/docs/changelogs/1.15.2.md b/docs/changelogs/1.15.2.md new file mode 100644 index 000000000..4f95b9741 --- /dev/null +++ b/docs/changelogs/1.15.2.md @@ -0,0 +1,9 @@ +# Blitzkrieg 1.15.2 + +Infinity reduced to a finite value. + +## Fixes + +- Added a maximum value to the jump to position button +- Removed neighbor checking for the seeding player + - This fixes the jump to position button not loading at all diff --git a/docs/changelogs/1.15.3.md b/docs/changelogs/1.15.3.md new file mode 100644 index 000000000..8772fc54a --- /dev/null +++ b/docs/changelogs/1.15.3.md @@ -0,0 +1,30 @@ +# Blitzkrieg 1.15.3 + +The bot now gets more expressive! + +## Features + +- The bot can now have presence messages; examples: + - "Living in {number} servers" + - "Server {number} users" + - "Observing {number} channels" + - More will be added in the future! Give me some ideas + +## Changes + +- Moved `/credits` to `/about creators` +- `/debug` command now ditches embeds and has better information to serve + +## Technical Features + +- Added a workflow and lint for package and changelog version miss match + +## Technical Changes + +- Removed manual trigger for Asian latest ratings leaderboard archiver +- Leaderboard archiver now accepts an explicit target like `midnight` or `latest` +- Combined midnight and latest leaderboard archival workflow into one file + +## Technical Fixed + +- Reviewed all workflow triggers and updated them diff --git a/docs/changelogs/1.15.4.md b/docs/changelogs/1.15.4.md new file mode 100644 index 000000000..b1bfa06dd --- /dev/null +++ b/docs/changelogs/1.15.4.md @@ -0,0 +1,13 @@ +# Blitzkrieg 1.15.4 + +Unlocking future potential + +## Technical Changes + +- Moved the word "Ratings" to the front of the workflow name +- Renamed `blitzkrieg-db` to `blitzkrieg-assets` +- Moved the region folders from the root to `regions` + +## Technical Fixes + +- The ratings leaderboard archiver now correctly skips undefined players diff --git a/docs/changelogs/1.15.5.md b/docs/changelogs/1.15.5.md new file mode 100644 index 000000000..439b14476 --- /dev/null +++ b/docs/changelogs/1.15.5.md @@ -0,0 +1,7 @@ +# Blitzkrieg 1.15.5 + +Oops, this should've been in the last patch. + +## Fixes + +- User and channel cache is now guild cache exhaustive diff --git a/docs/guide/creators.md b/docs/guide/creators.md new file mode 100644 index 000000000..663fb39ab --- /dev/null +++ b/docs/guide/creators.md @@ -0,0 +1,6 @@ +# Creators + +- TrèsAbhi `@tresabhi` + - Creator & main programmer; _I do it all!_ +- Prince_NA `@prince_na` + - Advisor & tester diff --git a/package.json b/package.json index d23645902..e77c4d947 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blitzkrieg", - "version": "1.15.1", + "version": "1.15.5", "description": "🎉 Tools for everything World of Tanks Blitz", "main": "src/server.ts", "type": "module", @@ -22,6 +22,7 @@ "lint": "npx tsc", "lint:website": "next lint", "format": "prettier --write \"**/*.@(json|js|jsx|css|md|ts|tsx|html|xml|yml|gltf)\"", + "lint:version": "vite-node --script scripts/checkVersionMissMatch", "knip": "knip", "update": "yarn upgrade --latest" }, diff --git a/scripts/buildRatingsLeaderboard.ts b/scripts/buildRatingsLeaderboard.ts index 564bffb66..cedf7e465 100644 --- a/scripts/buildRatingsLeaderboard.ts +++ b/scripts/buildRatingsLeaderboard.ts @@ -23,12 +23,15 @@ export type BlitzkriegRatingsLeaderboardEntry = { id: number; score: number }; export type BlitzkriegRatingsLeaderboard = BlitzkriegRatingsLeaderboardEntry[]; const publish = argv.includes('--publish'); -const latest = argv.includes('--latest'); +const target = argv + .find((arg) => arg.startsWith('--target=')) + ?.split('=')[1] as 'midnight' | 'latest' | undefined; const server = argv.find((arg) => arg.startsWith('--region='))?.split('=')[1]; +if (!target) throw new Error('Target parameter not specified'); if (!server) throw new Error('Region parameter not specified'); -const NEIGHBORS = 1024; +const NEIGHBORS = 2 ** 8; const PLAYERS = await patientFetchJSON( `https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`, ).then((data) => (data.detail === undefined ? data.count : undefined)); @@ -98,7 +101,10 @@ await Promise.all([ console.log('Converting to an array...'); for (let index = 0; index < PLAYERS; index++) { const listing = players[index + 1]; - if (!listing) console.warn(`Position ${index + 1} had no player`); + if (!listing) { + console.warn(`Position ${index + 1} had no player`); + continue; + } leaderboard[index] = { id: listing.spa_id, @@ -110,23 +116,19 @@ const leaderboardJSON = JSON.stringify(leaderboard); if (publish) { const octokit = new Octokit({ auth: env.GH_TOKEN }); - const info = await patientFetchJSON( `https://${server}.wotblitz.com/en/api/rating-leaderboards/season/`, ); const normalizedServer = server === 'na' ? 'com' : server; - - const infoPath = `${normalizedServer}/ratings/${info.current_season}/info.json`; - const leaderboardPath = `${normalizedServer}/ratings/${info.current_season}/${ - latest ? 'latest' : 'midnight' - }.json`; + const infoPath = `regions/${normalizedServer}/ratings/${info.current_season}/info.json`; + const leaderboardPath = `regions/${normalizedServer}/ratings/${info.current_season}/${target}.json`; const infoJSON = JSON.stringify(info); console.log(`Publishing to season ${info.current_season}...`); commitMultipleFiles( octokit, 'tresabhi', - 'blitzkrieg-db', + 'blitzkrieg-assets', 'main', new Date().toString(), [ diff --git a/scripts/checkVersionMissMatch.ts b/scripts/checkVersionMissMatch.ts new file mode 100644 index 000000000..a13c9351e --- /dev/null +++ b/scripts/checkVersionMissMatch.ts @@ -0,0 +1,12 @@ +import { readdir } from 'fs/promises'; +import packageJSON from '../package.json'; + +const { version } = packageJSON; +const changelogs = await readdir('docs/changelogs'); +const hasVersion = changelogs.includes(`${version}.md`); + +if (hasVersion) { + console.log(`Version ${version} found in changelogs`); +} else { + throw new Error(`Version ${version} not found in changelogs`); +} diff --git a/src/app/tools/ratings/page.tsx b/src/app/tools/ratings/page.tsx index fe70ff97f..979e4c1c3 100644 --- a/src/app/tools/ratings/page.tsx +++ b/src/app/tools/ratings/page.tsx @@ -299,19 +299,11 @@ export default function Page() { } } - const seedingPlayerNeighborEntry = Object.entries( - leaderboard[region][season], - ).find(([, player]) => id === player); - - if (seedingPlayerNeighborEntry === undefined) return null; - - // const seedingPlayerPosition = parseInt(seedingPlayerNeighborEntry[0]); const { neighbors } = await getRatingsNeighbors(region, id, size, true); useLeaderboardCache.setState( produce((draft: LeaderboardCache) => { neighbors.forEach((neighbor, neighborIndex) => { - // const position = neighborIndex - radius + seedingPlayerPosition; const position = neighbor.number - 1; if (!(position in draft[region][season])) { @@ -347,9 +339,9 @@ export default function Page() { async function jumpToPosition(position: number) { if (!ratingsInfo || ratingsInfo?.detail) return; - const targetPosition = Math.max( - 0, - Math.min(position, ratingsInfo.count - 1), + const targetPosition = Math.min( + ratingsInfo.count - 1, + Math.max(0, Math.min(position, ratingsInfo.count - 1)), ); if (season === 0) { diff --git a/src/commands/about.ts b/src/commands/about.ts index 63fbc6aa0..94b60fbf0 100644 --- a/src/commands/about.ts +++ b/src/commands/about.ts @@ -11,6 +11,7 @@ const DOCS = { introduction: 'guide/introduction', invite: 'guide/invite', timezones: 'guide/timezones', + creators: 'guide/creators', }; const DOC_DESCRIPTIONS: Record = { permissions: 'The permissions needed for the bot to function', @@ -18,6 +19,7 @@ const DOC_DESCRIPTIONS: Record = { introduction: 'About the bot', invite: 'How to invite the bot', timezones: 'How Blitzkrieg infers and uses your timezone', + creators: 'Who created the bot', }; function addDocsSubcommands(option: SlashCommandSubcommandsOnlyBuilder) { diff --git a/src/commands/credits.ts b/src/commands/credits.ts deleted file mode 100644 index 9cbe952d1..000000000 --- a/src/commands/credits.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { AttachmentBuilder, SlashCommandBuilder } from 'discord.js'; -import { CommandRegistry } from '../events/interactionCreate'; - -export const creditsCommand: CommandRegistry = { - inProduction: true, - inPublic: true, - - command: new SlashCommandBuilder() - .setName('credits') - .setDescription('Me and the people who made this bot'), - - async handler() { - return new AttachmentBuilder('https://i.imgur.com/ZF5ch33.png'); - }, -}; diff --git a/src/commands/debug.ts b/src/commands/debug.ts index 7b1254add..70ac62ad9 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -1,11 +1,6 @@ import { SlashCommandBuilder } from 'discord.js'; import packageJSON from '../../package.json' assert { type: 'json' }; -import getClientId from '../core/blitzkrieg/getClientId'; -import { tankAverages } from '../core/blitzstars/tankAverages'; -import { tankopedia } from '../core/blitzstars/tankopedia'; import { client } from '../core/discord/client'; -import embedInfo from '../core/discord/embedInfo'; -import markdownTable from '../core/discord/markdownTable'; import { CommandRegistry } from '../events/interactionCreate'; const executionStart = new Date().getTime(); @@ -21,24 +16,21 @@ export const debugCommand: CommandRegistry = { async handler(interaction) { const currentTime = new Date().getTime(); const uptime = currentTime - executionStart; + const list = [ + ['Version', packageJSON.version], + ['Shard', client.shard?.ids[0] ?? 'default'], + [ + 'Uptime', + `${Math.floor((uptime / 1000 / 60 / 60) % 24)}h ${Math.floor( + (uptime / 1000 / 60) % 60, + )}m ${Math.floor((uptime / 1000) % 60)}s ${Math.floor( + uptime % 1000, + )}ms`, + ], + ] + .map(([key, value]) => `- ${key}: ${value}`) + .join('\n'); - return embedInfo( - `${client.user?.username} debug information`, - markdownTable([ - ['Version', packageJSON.version], - ['Client ID', getClientId()], - ['Tag', interaction.client.user.tag], - [ - 'Uptime', - `${Math.floor(uptime / 1000 / 60 / 60 / 24)}d ${Math.floor( - (uptime / 1000 / 60 / 60) % 24, - )}h ${Math.floor((uptime / 1000 / 60) % 60)}m ${Math.floor( - (uptime / 1000) % 60, - )}s ${Math.floor(uptime % 1000)}ms`, - ], - ['Tankopedia cached', `${(await tankopedia) !== undefined}`], - ['Tank averages cached', `${(await tankAverages) !== undefined}`], - ]), - ); + return `# Debug\n\n${list}`; }, }; diff --git a/src/core/blitzkrieg/getArchivedLatestSeasonNumber.ts b/src/core/blitzkrieg/getArchivedLatestSeasonNumber.ts index 8d508e0e1..d5688089f 100644 --- a/src/core/blitzkrieg/getArchivedLatestSeasonNumber.ts +++ b/src/core/blitzkrieg/getArchivedLatestSeasonNumber.ts @@ -8,7 +8,7 @@ export async function getArchivedLatestSeasonNumber() { if (ratingsInfo.detail) { const comURL = ( (await fetch( - 'https://api.github.com/repos/tresabhi/blitzkrieg-db/git/trees/main', + 'https://api.github.com/repos/tresabhi/blitzkrieg-assets/git/trees/main', ).then((response) => response.json())) as { tree: { path: string; url: string }[]; } diff --git a/src/core/blitzkrieg/getArchivedRatingsInfo.ts b/src/core/blitzkrieg/getArchivedRatingsInfo.ts index e08b9793a..a69af3b7d 100644 --- a/src/core/blitzkrieg/getArchivedRatingsInfo.ts +++ b/src/core/blitzkrieg/getArchivedRatingsInfo.ts @@ -24,7 +24,7 @@ export default async function getArchivedRatingsInfo( } const response = await fetch( - `https://raw.githubusercontent.com/tresabhi/blitzkrieg-db/main/${region}/ratings/${season}/info.json`, + `https://raw.githubusercontent.com/tresabhi/blitzkrieg-assets/main/${region}/ratings/${season}/info.json`, ); const jsonContent = (await response.json()) as RatingsInfo & { detail: undefined; diff --git a/src/core/blitzkrieg/getArchivedRatingsLeaderboard.ts b/src/core/blitzkrieg/getArchivedRatingsLeaderboard.ts index 29e59e56e..f116ea00f 100644 --- a/src/core/blitzkrieg/getArchivedRatingsLeaderboard.ts +++ b/src/core/blitzkrieg/getArchivedRatingsLeaderboard.ts @@ -19,7 +19,7 @@ export async function getArchivedRatingsLeaderboard( } const response = await fetch( - `https://raw.githubusercontent.com/tresabhi/blitzkrieg-db/main/${region}/ratings/${season}/latest.json`, + `https://raw.githubusercontent.com/tresabhi/blitzkrieg-assets/main/${region}/ratings/${season}/latest.json`, ); const json = (await response.json()) as BlitzkriegRatingsLeaderboard; LEADERBOARD_CACHE[region][season] = json; diff --git a/src/core/blitzkrieg/getArchivedRatingsMidnightLeaderboard.ts b/src/core/blitzkrieg/getArchivedRatingsMidnightLeaderboard.ts index 85c7029b0..f656d23c0 100644 --- a/src/core/blitzkrieg/getArchivedRatingsMidnightLeaderboard.ts +++ b/src/core/blitzkrieg/getArchivedRatingsMidnightLeaderboard.ts @@ -1,7 +1,7 @@ import { BlitzkriegRatingsLeaderboard } from '../../../scripts/buildRatingsLeaderboard'; import { Region } from '../../constants/regions'; -export const DATABASE_REPO = { owner: 'tresabhi', repo: 'blitzkrieg-db' }; +export const DATABASE_REPO = { owner: 'tresabhi', repo: 'blitzkrieg-assets' }; const MIDNIGHT_LEADERBOARD_CACHE: Record< Region, @@ -22,7 +22,7 @@ export default async function getArchivedRatingsMidnightLeaderboard( try { const response = await fetch( - `https://raw.githubusercontent.com/tresabhi/blitzkrieg-db/main/${region}/ratings/${season}/midnight.json`, + `https://raw.githubusercontent.com/tresabhi/blitzkrieg-assets/main/${region}/ratings/${season}/midnight.json`, ); const json = (await response.json()) as BlitzkriegRatingsLeaderboard; MIDNIGHT_LEADERBOARD_CACHE[region][season] = json; diff --git a/src/core/blitzkrieg/patientFetchJSON.ts b/src/core/blitzkrieg/patientFetchJSON.ts index c96b4dc83..de3a31105 100644 --- a/src/core/blitzkrieg/patientFetchJSON.ts +++ b/src/core/blitzkrieg/patientFetchJSON.ts @@ -7,8 +7,8 @@ export async function patientFetchJSON( while (patientJSON! === undefined) { try { - patientJSON = (await fetch(url, options).then(({ json }) => - json(), + patientJSON = (await fetch(url, options).then((response) => + response.json(), )) as Type; } catch (error) { console.warn( diff --git a/src/core/discord/client.ts b/src/core/discord/client.ts index d79c653d5..3b9e6bbd8 100644 --- a/src/core/discord/client.ts +++ b/src/core/discord/client.ts @@ -1,10 +1,11 @@ import { Client, GatewayIntentBits } from 'discord.js'; import guildMemberAdd from '../../events/guildMemberAdd'; import interactionCreate from '../../events/interactionCreate'; +import ready from '../../events/ready'; export const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers], }) - // .on('ready', ready) + .on('ready', ready) .on('guildMemberAdd', guildMemberAdd) .on('interactionCreate', interactionCreate); diff --git a/src/events/interactionCreate/index.ts b/src/events/interactionCreate/index.ts index 6dedea8b9..0b7aeadcb 100644 --- a/src/events/interactionCreate/index.ts +++ b/src/events/interactionCreate/index.ts @@ -16,7 +16,6 @@ import { import discord from '../../../discord.json' assert { type: 'json' }; import { aboutCommand } from '../../commands/about'; import { breakdownCommand } from '../../commands/breakdown'; -import { creditsCommand } from '../../commands/credits'; import { debugCommand } from '../../commands/debug'; import { eligibleCommand } from '../../commands/eligible'; import { evolutionCommand } from '../../commands/evolution'; @@ -102,7 +101,6 @@ export const COMMANDS_RAW: CommandRegistry[] = [ evolutionCommand, statsCommand, ratingsCommand, - creditsCommand, ]; export const commands = Promise.all(COMMANDS_RAW).then((rawCommands) => diff --git a/src/events/ready.ts b/src/events/ready.ts index 3c24d0ab2..a6278013e 100644 --- a/src/events/ready.ts +++ b/src/events/ready.ts @@ -1,5 +1,29 @@ -import { Client } from 'discord.js'; +import { ActivityType, Client } from 'discord.js'; export default function ready(client: Client) { - console.log(`🟢 Launched bot ${client.shard?.ids[0]}`); + console.log(`🟢 Launched bot ${client.shard?.ids[0] ?? 'default'}`); + + const activities: (() => string)[] = [ + () => `Living in ${client.guilds.cache.size.toLocaleString()} servers`, + () => + `Serving ${client.guilds.cache + .reduce((accumulator, guild) => accumulator + guild.memberCount, 0) + .toLocaleString()} users`, + () => + `Observing ${client.guilds.cache + .reduce( + (accumulator, guild) => accumulator + guild.channels.cache.size, + 0, + ) + .toLocaleString()} channels`, + ]; + + client.user.setPresence({ + activities: [ + { + type: ActivityType.Custom, + name: activities[Math.floor(Math.random() * activities.length)](), + }, + ], + }); }