diff --git a/.vscode/settings.json b/.vscode/settings.json index e5c80b4cb..9258669b3 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,7 +5,6 @@ "kranvagn", "ownedtanks", "searchplayers", - "SKLLD", "Smri", "strvk", "tankopedia", diff --git a/README.md b/README.md index f8deacd39..d8f52d033 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# Skilled Bot +# blitzkrieg -Executes specific tasks in the Skilled Discord server. +A Discord bot for anything and everything related to World of Tanks Blitz. ## Invite the Bot -Join the [Skilled Discord server](https://discord.gg/ZPvcEG7DS8), click on the bot's profile, and click "Add to Server". +Join the [Discord server](https://discord.gg/nDt7AjGJQH), click on the bot's profile, and click "Add to Server". ## Using diff --git a/package.json b/package.json index 25ddfdec7..399aa5fb7 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "sklld-bot", + "name": "blitzkrieg", "version": "0.6.0", "description": "", "main": "index.js", diff --git a/src/commands/debug.ts b/src/commands/debug.ts index 2280c12a0..b194b7ea7 100644 --- a/src/commands/debug.ts +++ b/src/commands/debug.ts @@ -1,11 +1,11 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import packageJSON from '../../package.json' assert { type: 'json' }; -import { SKILLED_COLOR } from '../constants/colors.js'; +import { INFO_COLOR } from '../constants/colors.js'; import { tankopedia } from '../core/blitzstars/tankopedia.js'; import cmdName from '../core/interaction/cmdName.js'; import getClientId from '../core/process/getClientId.js'; -import { client } from '../index.js'; import { CommandRegistry } from '../events/interactionCreate.js'; +import { client } from '../index.js'; const executionStart = new Date().getTime(); @@ -26,7 +26,7 @@ export default { embeds: [ new EmbedBuilder() .setTitle(`${client.user?.username} debug information`) - .setColor(SKILLED_COLOR) + .setColor(INFO_COLOR) .setDescription( `**Version**: ${packageJSON.version}\n**Uptime**: ${Math.floor( uptime / 1000 / 60 / 60 / 24, diff --git a/src/commands/eligible.ts b/src/commands/eligible.ts deleted file mode 100644 index 027c7beab..000000000 --- a/src/commands/eligible.ts +++ /dev/null @@ -1,149 +0,0 @@ -import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; -import markdownEscape from 'markdown-escape'; -import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js'; -import { BlitzServer } from '../constants/servers.js'; -import usernameAutocomplete from '../core/autocomplete/username.js'; -import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; -import blitzStarsLinks from '../core/blitzstars/blitzStarsLinks.js'; -import getBlitzStarsAccount from '../core/blitzstars/getBlitzStarsAccount.js'; -import poweredByBlitzStars from '../core/blitzstars/poweredByBlitzStars.js'; -import cmdName from '../core/interaction/cmdName.js'; -import addServerChoices from '../core/options/addServerChoices.js'; -import addUsernameOption from '../core/options/addUsernameOption.js'; -import { CommandRegistry } from '../events/interactionCreate.js'; - -const CLANS = { - sklld: { id: 71559, name: 'Skilled' }, - smri: { id: 91244, name: 'Samurai' }, -}; - -export default { - inProduction: false, - inDevelopment: false, - inPublic: false, - - command: new SlashCommandBuilder() - .setName(cmdName('eligible')) - .setDescription("Gets the user's eligibility for Skilled clans") - .addStringOption((option) => - option - .setName('clan') - .setDescription('The Skilled clan you are checking') - .addChoices( - { name: CLANS.sklld.name, value: 'sklld' }, - { name: CLANS.smri.name, value: 'smri' }, - ) - .setRequired(true), - ) - .addStringOption(addServerChoices) - .addStringOption(addUsernameOption), - - async execute(interaction) { - const clan = interaction.options.getString('clan') as keyof typeof CLANS; - const name = interaction.options.getString('username')!; - const server = interaction.options.getString('server') as BlitzServer; - const blitzAccount = await getBlitzAccount(interaction, name, server); - - if (!blitzAccount) return; - - const blitzStarsAccount = await getBlitzStarsAccount( - interaction, - blitzAccount.account_id, - ); - if (!blitzStarsAccount) return; - - const issues: string[] = []; - - if (clan === 'sklld') { - if (blitzStarsAccount.period30d.all.battles < 150) { - issues.push( - `**Battles**: ${blitzStarsAccount.period30d.all.battles} (${ - blitzStarsAccount.period30d.all.battles - 150 - })`, - ); - } - if (blitzStarsAccount.period30d.avg_tier < 8) { - issues.push( - `**Tier**: ${blitzStarsAccount.period30d.avg_tier.toFixed(2)} (${( - blitzStarsAccount.period30d.avg_tier - 8 - ).toFixed(2)})`, - ); - } - if (blitzStarsAccount.period30d.special.winrate < 60) { - issues.push( - `**Winrate**: ${blitzStarsAccount.period30d.special.winrate.toFixed( - 2, - )}% (${(blitzStarsAccount.period30d.special.winrate - 60).toFixed( - 2, - )}%)`, - ); - } - if (blitzStarsAccount.period30d.wn8 < 2100) { - issues.push( - `**WN8**: ${blitzStarsAccount.period30d.wn8.toFixed(0)} (${( - blitzStarsAccount.period30d.wn8 - 2100 - ).toFixed(0)})`, - ); - } - if (blitzStarsAccount.period30d.special.dpb < 2400) { - issues.push( - `**Damage per battle**: ${blitzStarsAccount.period30d.special.dpb.toFixed( - 0, - )} (${(blitzStarsAccount.period30d.special.dpb - 2400).toFixed(0)})`, - ); - } - } else { - if (blitzStarsAccount.statistics.all.battles < 1500) { - issues.push( - `**Battles**: ${blitzStarsAccount.statistics.all.battles} (${ - blitzStarsAccount.statistics.all.battles - 1500 - })`, - ); - } - if (blitzStarsAccount.statistics.special.winrate < 53) { - issues.push( - `**Winrate**: ${blitzStarsAccount.statistics.special.winrate.toFixed( - 2, - )}% (${(blitzStarsAccount.statistics.special.winrate - 53).toFixed( - 2, - )}%)`, - ); - } - } - - const eligible = issues.length === 0; - - await interaction.editReply({ - embeds: [ - poweredByBlitzStars( - new EmbedBuilder() - .setTitle( - `${markdownEscape(blitzStarsAccount.nickname)} is ${ - eligible ? '' : 'not ' - }eligible for ${CLANS[clan].name}`, - ) - .setColor(eligible ? POSITIVE_COLOR : NEGATIVE_COLOR) - .setDescription( - `${ - eligible - ? `${markdownEscape( - blitzStarsAccount.nickname, - )} meets all the requirements set for ${CLANS[clan].name}.` - : `${markdownEscape( - blitzStarsAccount.nickname, - )}'s shortcomings for ${CLANS[clan].name} (${ - clan === 'sklld' ? '30 days stats' : 'career stats' - }):\n\n${issues.join('\n')}` - }\n\n${blitzStarsLinks(server, blitzAccount.nickname)}`, - ), - ), - ], - }); - - console.log( - `Showing ${blitzStarsAccount.nickname}'s eligibility for ${CLANS[clan].name}`, - ); - }, - - autocomplete: usernameAutocomplete, -} satisfies CommandRegistry; diff --git a/src/commands/help.ts b/src/commands/help.ts index ce2df554e..a33476f49 100644 --- a/src/commands/help.ts +++ b/src/commands/help.ts @@ -1,9 +1,13 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import discord from '../../discord.json' assert { type: 'json' }; -import { SKILLED_COLOR } from '../constants/colors.js'; +import { INFO_COLOR } from '../constants/colors.js'; import cmdName from '../core/interaction/cmdName.js'; +import { + CommandRegistry, + guildCommands, + publicCommands, +} from '../events/interactionCreate.js'; import { client } from '../index.js'; -import { CommandRegistry, guildCommands, publicCommands } from '../events/interactionCreate.js'; export default { inProduction: true, @@ -19,11 +23,11 @@ export default { embeds: [ new EmbedBuilder() .setTitle(`${client.user?.username} help`) - .setColor(SKILLED_COLOR) + .setColor(INFO_COLOR) .setDescription( `**About**\n${ client.user?.username - } automates many mundane tasks and provide statistics in numerous flexible ways.\n\nMade by TresAbhi from the Skilled [SKLLD] clan.\nGitHub: https://github.com/tresabhi/sklld-bot\nDiscord server: https://discord.gg/nDt7AjGJQH\nSkilled server: https://discord.gg/ZPvcEG7DS8\n\n**Commands**\n${(interaction.guildId === + } automates many mundane tasks and provide statistics in numerous flexible ways.\n\nMade by TresAbhi from the Skilled [SKLLD] clan.\nGitHub: https://github.com/tresabhi/blitzkrieg\nDiscord server: https://discord.gg/nDt7AjGJQH\nSkilled server: https://discord.gg/ZPvcEG7DS8\n\n**Commands**\n${(interaction.guildId === discord.sklld_guild_id ? [...guildCommands, ...publicCommands] : publicCommands diff --git a/src/commands/ownedtanks.ts b/src/commands/ownedtanks.ts index d38e7705f..50e291f07 100644 --- a/src/commands/ownedtanks.ts +++ b/src/commands/ownedtanks.ts @@ -1,6 +1,6 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; -import { SKILLED_COLOR } from '../constants/colors.js'; +import { INFO_COLOR } from '../constants/colors.js'; import usernameAutocomplete from '../core/autocomplete/username.js'; import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; @@ -100,7 +100,7 @@ export default { TANK_TYPE_EMOJIS['AT-SPG'] } = Tank Destroyer`, ) - .setColor(SKILLED_COLOR), + .setColor(INFO_COLOR), ], }); diff --git a/src/commands/playerachievements.ts b/src/commands/playerachievements.ts index bcc14e126..a9025c6d0 100644 --- a/src/commands/playerachievements.ts +++ b/src/commands/playerachievements.ts @@ -6,7 +6,7 @@ import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import cleanTable, { TableInputEntry } from '../core/interaction/cleanTable.js'; import cmdName from '../core/interaction/cmdName.js'; -import sklldEmbed from '../core/interaction/sklldEmbed.js'; +import infoEmbed from '../core/interaction/infoEmbed.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; import { args } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; @@ -57,7 +57,7 @@ export default { interaction.editReply({ embeds: [ - sklldEmbed( + infoEmbed( `${markdownEscape(accounts[id].nickname)}'s information`, cleanTable( diff --git a/src/commands/playerinfo.ts b/src/commands/playerinfo.ts index cfa9254ec..9f6795494 100644 --- a/src/commands/playerinfo.ts +++ b/src/commands/playerinfo.ts @@ -5,7 +5,7 @@ import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import cleanTable from '../core/interaction/cleanTable.js'; import cmdName from '../core/interaction/cmdName.js'; -import sklldEmbed from '../core/interaction/sklldEmbed.js'; +import infoEmbed from '../core/interaction/infoEmbed.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; import { args } from '../core/process/args.js'; import { CommandRegistry } from '../events/interactionCreate.js'; @@ -34,7 +34,7 @@ export default { interaction.editReply({ embeds: [ - sklldEmbed( + infoEmbed( `${markdownEscape(accountInfo.nickname)}'s information`, cleanTable([ diff --git a/src/commands/searchclans.ts b/src/commands/searchclans.ts index cf298a9dc..d55f18f0b 100644 --- a/src/commands/searchclans.ts +++ b/src/commands/searchclans.ts @@ -3,7 +3,7 @@ import markdownEscape from 'markdown-escape'; import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import cmdName from '../core/interaction/cmdName.js'; -import sklldEmbed from '../core/interaction/sklldEmbed.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'; @@ -12,7 +12,7 @@ import { ClanList } from '../types/clanList.js'; export default { inProduction: true, - inDevelopment: true, + inDevelopment: false, inPublic: true, command: new SlashCommandBuilder() @@ -39,7 +39,7 @@ export default { await interaction.editReply({ embeds: [ - sklldEmbed( + infoEmbed( `Clan search for "${markdownEscape(clan)}" in ${ BLITZ_SERVERS[server] }`, diff --git a/src/commands/searchplayers.ts b/src/commands/searchplayers.ts index 19cd7263e..a2bea41fd 100644 --- a/src/commands/searchplayers.ts +++ b/src/commands/searchplayers.ts @@ -1,6 +1,6 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; -import { SKILLED_COLOR } from '../constants/colors.js'; +import { INFO_COLOR } from '../constants/colors.js'; import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import cmdName from '../core/interaction/cmdName.js'; @@ -42,7 +42,7 @@ export default { await interaction.editReply({ embeds: [ new EmbedBuilder() - .setColor(SKILLED_COLOR) + .setColor(INFO_COLOR) .setTitle( `Player search for "${markdownEscape(name)}" in ${ BLITZ_SERVERS[server] diff --git a/src/commands/searchtanks.ts b/src/commands/searchtanks.ts index 9706e0481..bf7d49823 100644 --- a/src/commands/searchtanks.ts +++ b/src/commands/searchtanks.ts @@ -3,7 +3,7 @@ import { go } from 'fuzzysort'; import markdownEscape from 'markdown-escape'; import { tankNames } from '../core/blitzstars/tankopedia.js'; import cmdName from '../core/interaction/cmdName.js'; -import sklldEmbed from '../core/interaction/sklldEmbed.js'; +import infoEmbed from '../core/interaction/infoEmbed.js'; import addTankChoices from '../core/options/addTankChoices.js'; import { CommandRegistry } from '../events/interactionCreate.js'; @@ -33,7 +33,7 @@ export default { await interaction.editReply({ embeds: [ - sklldEmbed( + infoEmbed( `Tank search for "${markdownEscape(tank)}"`, results.length === 0 ? 'No tanks found.' diff --git a/src/commands/stats.ts b/src/commands/stats.ts index 6b2b18ccb..da2569cdc 100644 --- a/src/commands/stats.ts +++ b/src/commands/stats.ts @@ -1,6 +1,6 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js'; import markdownEscape from 'markdown-escape'; -import { SKILLED_COLOR } from '../constants/colors.js'; +import { INFO_COLOR } from '../constants/colors.js'; import usernameAutocomplete from '../core/autocomplete/username.js'; import getBlitzAccount from '../core/blitz/getBlitzAccount.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; @@ -103,7 +103,7 @@ export default { embeds: [ poweredByBlitzStars( new EmbedBuilder() - .setColor(SKILLED_COLOR) + .setColor(INFO_COLOR) .setTitle( `${markdownEscape(blitzStarsAccount.nickname)}'s ${ period === 'career' diff --git a/src/commands/tankstats.ts b/src/commands/tankstats.ts index 0ed5393cd..4c5c12db6 100644 --- a/src/commands/tankstats.ts +++ b/src/commands/tankstats.ts @@ -11,7 +11,7 @@ import getPeriodicStats, { import cleanTable from '../core/interaction/cleanTable.js'; import cmdName from '../core/interaction/cmdName.js'; import errorEmbed from '../core/interaction/errorEmbed.js'; -import sklldEmbed from '../core/interaction/sklldEmbed.js'; +import infoEmbed from '../core/interaction/infoEmbed.js'; import addTankChoices from '../core/options/addTankChoices.js'; import addUsernameOption from '../core/options/addUsernameOption.js'; import { args } from '../core/process/args.js'; @@ -79,7 +79,7 @@ export default { interaction.editReply({ embeds: [ - sklldEmbed( + infoEmbed( `${period} day stats for ${markdownEscape( accountInfo[id].nickname, )}'s ${resolveTankName(tank)}`, diff --git a/src/constants/colors.ts b/src/constants/colors.ts index e486d0847..f81fdc6ad 100644 --- a/src/constants/colors.ts +++ b/src/constants/colors.ts @@ -1,3 +1,3 @@ -export const SKILLED_COLOR = '#8e3cf5'; +export const INFO_COLOR = '#8e3cf5'; export const POSITIVE_COLOR = '#82ff29'; export const NEGATIVE_COLOR = '#ff4747'; diff --git a/src/core/interaction/infoEmbed.ts b/src/core/interaction/infoEmbed.ts new file mode 100644 index 000000000..ee47b02c3 --- /dev/null +++ b/src/core/interaction/infoEmbed.ts @@ -0,0 +1,9 @@ +import { EmbedBuilder } from 'discord.js'; +import { INFO_COLOR } from '../../constants/colors.js'; + +export default function infoEmbed(title: string, description: string) { + return new EmbedBuilder() + .setColor(INFO_COLOR) + .setTitle(title) + .setDescription(description); +} diff --git a/src/core/interaction/sklldEmbed.ts b/src/core/interaction/sklldEmbed.ts deleted file mode 100644 index eebe46e35..000000000 --- a/src/core/interaction/sklldEmbed.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { EmbedBuilder } from 'discord.js'; -import { SKILLED_COLOR } from '../../constants/colors.js'; - -export default function sklldEmbed(title: string, description: string) { - return new EmbedBuilder() - .setColor(SKILLED_COLOR) - .setTitle(title) - .setDescription(description); -} diff --git a/src/events/guildMemberAdd.ts b/src/events/guildMemberAdd.ts index 032be1845..ee07d839e 100644 --- a/src/events/guildMemberAdd.ts +++ b/src/events/guildMemberAdd.ts @@ -1,6 +1,6 @@ import { EmbedBuilder, GuildMember, TextChannel } from 'discord.js'; import discord from '../../discord.json' assert { type: 'json' }; -import { SKILLED_COLOR } from '../constants/colors.js'; +import { INFO_COLOR } from '../constants/colors.js'; export default async function (member: GuildMember) { if (member.guild.id === discord.sklld_guild_id) { @@ -12,7 +12,7 @@ export default async function (member: GuildMember) { content: member.toString(), embeds: [ new EmbedBuilder() - .setColor(SKILLED_COLOR) + .setColor(INFO_COLOR) .setTitle(`Welcome ${member.user.username}`) .setDescription( `Welcome to the Skilled server, **${member.user.username}**! To continue, please use the \`/verify\` command.\n\nExample: \`/verify Europe Sabina244\``, diff --git a/src/events/interactionCreate.ts b/src/events/interactionCreate.ts index 5582f2465..8eb7bc1bd 100644 --- a/src/events/interactionCreate.ts +++ b/src/events/interactionCreate.ts @@ -16,9 +16,9 @@ import getClientId from '../core/process/getClientId.js'; import isDev from '../core/process/isDev.js'; export interface CommandRegistry { - inDevelopment: boolean; // register with Skilled Bot (default: false) - inProduction: boolean; // register with Skilled Canary (default: false) - inPublic: boolean; // registers on all servers (default: true) + inDevelopment: boolean; + inProduction: boolean; + inPublic: boolean; command: Omit; execute: (interaction: ChatInputCommandInteraction) => void;