feat: cleaned discord

This commit is contained in:
TresAbhi committed 2023-06-27 02:22:28 +00:00
1 parent 169588a211
commit 01ed20941d
30 files changed
+93 -121

No files matched your search

+4 -4
View File
@@ -3,8 +3,8 @@ import packageJSON from '../../package.json' assert { type: 'json' };
import { client } from '../bot.js'; import { client } from '../bot.js';
import { tankopedia } from '../core/blitz/tankopedia.js'; import { tankopedia } from '../core/blitz/tankopedia.js';
import { tankAverages } from '../core/blitzstars/tankAverages.js'; import { tankAverages } from '../core/blitzstars/tankAverages.js';
import cleanTable from '../core/discord/cleanTable.js'; import embedInfo from '../core/discord/embedInfo.js';
import infoEmbed from '../core/discord/infoEmbed.js'; import markdownTable from '../core/discord/markdownTable.js';
import getClientId from '../core/node/getClientId.js'; import getClientId from '../core/node/getClientId.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
@@ -23,9 +23,9 @@ export default {
const currentTime = new Date().getTime(); const currentTime = new Date().getTime();
const uptime = currentTime - executionStart; const uptime = currentTime - executionStart;
return infoEmbed( return embedInfo(
`${client.user?.username} debug information`, `${client.user?.username} debug information`,
cleanTable([ markdownTable([
['Version', packageJSON.version], ['Version', packageJSON.version],
['Client ID', getClientId()], ['Client ID', getClientId()],
['Tag', interaction.client.user.tag], ['Tag', interaction.client.user.tag],
+8 -8
View File
@@ -7,10 +7,10 @@ import getPeriodNow from '../core/blitzstars/getPeriodNow.js';
import getPeriodStart from '../core/blitzstars/getPeriodStart.js'; import getPeriodStart from '../core/blitzstars/getPeriodStart.js';
import getTankStatsDiffed from '../core/blitzstars/getTankStatsDiffed.js'; import getTankStatsDiffed from '../core/blitzstars/getTankStatsDiffed.js';
import { tankAverages } from '../core/blitzstars/tankAverages.js'; import { tankAverages } from '../core/blitzstars/tankAverages.js';
import addUsernameOption from '../core/discord/addUsernameOption.js'; import addUsernameChoices from '../core/discord/addUsernameChoices.js';
import cleanTable, { TableInput } from '../core/discord/cleanTable.js'; import embedNegative from '../core/discord/embedNegative.js';
import negativeEmbed from '../core/discord/negativeEmbed.js'; import embedPositive from '../core/discord/embedPositive.js';
import positiveEmbed from '../core/discord/positiveEmbed.js'; import markdownTable, { TableInput } from '../core/discord/markdownTable.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
@@ -44,7 +44,7 @@ export default {
) )
.setRequired(true), .setRequired(true),
) )
.addStringOption(addUsernameOption), .addStringOption(addUsernameChoices),
async handler(interaction) { async handler(interaction) {
const clan = interaction.options.getString('clan') as SkilledClan; const clan = interaction.options.getString('clan') as SkilledClan;
@@ -137,7 +137,7 @@ export default {
isEligible = problems.length === 0; isEligible = problems.length === 0;
body = isEligible body = isEligible
? 'Player is fully eligible.' ? 'Player is fully eligible.'
: `Player is not eligible. Shortcomings in 30-day statistics:\n\n${cleanTable( : `Player is not eligible. Shortcomings in 30-day statistics:\n\n${markdownTable(
problems, problems,
)}`; )}`;
} else if (clan === 'SMRI') { } else if (clan === 'SMRI') {
@@ -162,11 +162,11 @@ export default {
isEligible = problems.length === 0; isEligible = problems.length === 0;
body = isEligible body = isEligible
? 'Player is fully eligible.' ? 'Player is fully eligible.'
: `Player is not eligible. Shortcomings in career statistics:\n\n${cleanTable( : `Player is not eligible. Shortcomings in career statistics:\n\n${markdownTable(
problems, problems,
)}`; )}`;
} }
return (isEligible ? positiveEmbed : negativeEmbed)(title, body); return (isEligible ? embedPositive : embedNegative)(title, body);
}, },
} satisfies CommandRegistry; } satisfies CommandRegistry;
+6 -6
View File
@@ -1,10 +1,10 @@
import { SlashCommandBuilder } from 'discord.js'; import { SlashCommandBuilder } from 'discord.js';
import resolveTankId from '../core/blitz/resolveTankId.js'; import resolveTankId from '../core/blitz/resolveTankId.js';
import addStatsSubCommandGroups from '../core/discord/addStatsSubCommandGroups.js'; import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups.js';
import autocompleteTanks from '../core/discord/autocompleteTanks.js';
import autocompleteUsername from '../core/discord/autocompleteUsername.js';
import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand.js'; import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import tanksAutocomplete from '../core/discord/tanksAutocomplete.js';
import usernameAutocomplete from '../core/discord/usernameAutocomplete.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
import evolution from '../renderers/evolution.js'; import evolution from '../renderers/evolution.js';
import { StatType } from '../renderers/stats.js'; import { StatType } from '../renderers/stats.js';
@@ -14,7 +14,7 @@ export default {
inDevelopment: true, inDevelopment: true,
inPublic: true, inPublic: true,
command: addStatsSubCommandGroups( command: addStatTypeSubCommandGroups(
new SlashCommandBuilder() new SlashCommandBuilder()
.setName('evolution') .setName('evolution')
.setDescription('Evolution of statistics'), .setDescription('Evolution of statistics'),
@@ -45,7 +45,7 @@ export default {
}, },
autocomplete: (interaction) => { autocomplete: (interaction) => {
usernameAutocomplete(interaction); autocompleteUsername(interaction);
tanksAutocomplete(interaction); autocompleteTanks(interaction);
}, },
} satisfies CommandRegistry; } satisfies CommandRegistry;
+2 -2
View File
@@ -1,7 +1,7 @@
import { SlashCommandBuilder } from 'discord.js'; import { SlashCommandBuilder } from 'discord.js';
import discord from '../../discord.json' assert { type: 'json' }; import discord from '../../discord.json' assert { type: 'json' };
import { client } from '../bot.js'; import { client } from '../bot.js';
import infoEmbed from '../core/discord/infoEmbed.js'; import embedInfo from '../core/discord/embedInfo.js';
import { import {
CommandRegistry, CommandRegistry,
guildCommands, guildCommands,
@@ -18,7 +18,7 @@ export default {
.setDescription('All the help you need about the bot'), .setDescription('All the help you need about the bot'),
handler(interaction) { handler(interaction) {
return infoEmbed( return embedInfo(
`${client.user?.username} help`, `${client.user?.username} help`,
`**About**\n${ `**About**\n${
client.user?.username client.user?.username
+2 -2
View File
@@ -8,7 +8,7 @@ import { BLITZ_SERVERS } from '../constants/servers.js';
import getBlitzClan from '../core/blitz/getBlitzClan.js'; import getBlitzClan from '../core/blitz/getBlitzClan.js';
import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import addClanChoices from '../core/discord/addClanChoices.js'; import addClanChoices from '../core/discord/addClanChoices.js';
import clanAutocomplete from '../core/discord/clanAutocomplete.js'; import autocompleteClan from '../core/discord/autocompleteClan.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountInfo } from '../types/accountInfo.js'; import { AccountInfo } from '../types/accountInfo.js';
@@ -84,5 +84,5 @@ export default {
); );
}, },
autocomplete: clanAutocomplete, autocomplete: autocompleteClan,
} satisfies CommandRegistry; } satisfies CommandRegistry;
+4 -4
View File
@@ -12,9 +12,9 @@ import {
Tier, Tier,
tankopedia, tankopedia,
} from '../core/blitz/tankopedia.js'; } from '../core/blitz/tankopedia.js';
import addUsernameOption from '../core/discord/addUsernameOption.js'; import addUsernameChoices from '../core/discord/addUsernameChoices.js';
import autocompleteUsername from '../core/discord/autocompleteUsername.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import usernameAutocomplete from '../core/discord/usernameAutocomplete.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountInfo } from '../types/accountInfo.js'; import { AccountInfo } from '../types/accountInfo.js';
@@ -67,7 +67,7 @@ export default {
) )
.setRequired(true), .setRequired(true),
) )
.addStringOption(addUsernameOption), .addStringOption(addUsernameChoices),
async handler(interaction) { async handler(interaction) {
const tier = Number(interaction.options.getString('tier')); const tier = Number(interaction.options.getString('tier'));
@@ -120,5 +120,5 @@ export default {
); );
}, },
autocomplete: usernameAutocomplete, autocomplete: autocompleteUsername,
} satisfies CommandRegistry; } satisfies CommandRegistry;
+10 -8
View File
@@ -2,11 +2,13 @@ import { SlashCommandBuilder } from 'discord.js';
import { startCase } from 'lodash'; import { startCase } from 'lodash';
import markdownEscape from 'markdown-escape'; import markdownEscape from 'markdown-escape';
import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import addUsernameOption from '../core/discord/addUsernameOption.js'; import addUsernameChoices from '../core/discord/addUsernameChoices.js';
import cleanTable, { TableInputEntry } from '../core/discord/cleanTable.js'; import autocompleteUsername from '../core/discord/autocompleteUsername.js';
import infoEmbed from '../core/discord/infoEmbed.js'; import embedInfo from '../core/discord/embedInfo.js';
import markdownTable, {
TableInputEntry,
} from '../core/discord/markdownTable.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import usernameAutocomplete from '../core/discord/usernameAutocomplete.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountAchievements } from '../types/accountAchievements.js'; import { AccountAchievements } from '../types/accountAchievements.js';
@@ -22,7 +24,7 @@ export default {
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
.setName('playerachievements') .setName('playerachievements')
.setDescription("All the player's achievements") .setDescription("All the player's achievements")
.addStringOption(addUsernameOption) .addStringOption(addUsernameChoices)
.addStringOption((option) => .addStringOption((option) =>
option option
.setName('sort') .setName('sort')
@@ -50,10 +52,10 @@ export default {
...accountAchievements.max_series, ...accountAchievements.max_series,
}; };
return infoEmbed( return embedInfo(
`${markdownEscape(accounts[id].nickname)}'s information`, `${markdownEscape(accounts[id].nickname)}'s information`,
cleanTable( markdownTable(
Object.keys(compound) Object.keys(compound)
.filter((achievement) => compound[achievement] > 0) .filter((achievement) => compound[achievement] > 0)
.sort( .sort(
@@ -72,5 +74,5 @@ export default {
); );
}, },
autocomplete: usernameAutocomplete, autocomplete: autocompleteUsername,
} satisfies CommandRegistry; } satisfies CommandRegistry;
+8 -8
View File
@@ -1,11 +1,11 @@
import { SlashCommandBuilder } from 'discord.js'; import { SlashCommandBuilder } from 'discord.js';
import markdownEscape from 'markdown-escape'; import markdownEscape from 'markdown-escape';
import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import addUsernameOption from '../core/discord/addUsernameOption.js'; import addUsernameChoices from '../core/discord/addUsernameChoices.js';
import cleanTable from '../core/discord/cleanTable.js'; import autocompleteUsername from '../core/discord/autocompleteUsername.js';
import infoEmbed from '../core/discord/infoEmbed.js'; import embedInfo from '../core/discord/embedInfo.js';
import markdownTable from '../core/discord/markdownTable.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import usernameAutocomplete from '../core/discord/usernameAutocomplete.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountInfo } from '../types/accountInfo.js'; import { AccountInfo } from '../types/accountInfo.js';
@@ -18,7 +18,7 @@ export default {
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
.setName('playerinfo') .setName('playerinfo')
.setDescription('Basic information about a player') .setDescription('Basic information about a player')
.addStringOption(addUsernameOption), .addStringOption(addUsernameChoices),
async handler(interaction) { async handler(interaction) {
const account = await resolvePlayerFromCommand(interaction); const account = await resolvePlayerFromCommand(interaction);
@@ -28,10 +28,10 @@ export default {
); );
const accountInfo = accounts[id]; const accountInfo = accounts[id];
return infoEmbed( return embedInfo(
`${markdownEscape(accountInfo.nickname)}'s information`, `${markdownEscape(accountInfo.nickname)}'s information`,
cleanTable([ markdownTable([
['Nickname', `${accountInfo.nickname}`], ['Nickname', `${accountInfo.nickname}`],
['Battles', `${accountInfo.statistics.all.battles}`], ['Battles', `${accountInfo.statistics.all.battles}`],
[ [
@@ -56,5 +56,5 @@ export default {
); );
}, },
autocomplete: usernameAutocomplete, autocomplete: autocompleteUsername,
} satisfies CommandRegistry; } satisfies CommandRegistry;
+2 -2
View File
@@ -4,7 +4,7 @@ import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import addClanChoices from '../core/discord/addClanChoices.js'; import addClanChoices from '../core/discord/addClanChoices.js';
import addServerChoices from '../core/discord/addServerChoices.js'; import addServerChoices from '../core/discord/addServerChoices.js';
import infoEmbed from '../core/discord/infoEmbed.js'; import embedInfo from '../core/discord/embedInfo.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
import { ClanList } from '../types/clanList.js'; import { ClanList } from '../types/clanList.js';
@@ -35,7 +35,7 @@ export default {
`https://api.wotblitz.${server}/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`, `https://api.wotblitz.${server}/wotb/clans/list/?application_id=${WARGAMING_APPLICATION_ID}&search=${clan}&limit=${limit}`,
); );
return infoEmbed( return embedInfo(
`Clan search for "${markdownEscape(clan)}" in ${BLITZ_SERVERS[server]}`, `Clan search for "${markdownEscape(clan)}" in ${BLITZ_SERVERS[server]}`,
clanList.length === 0 clanList.length === 0
? 'No clans found.' ? 'No clans found.'
+4 -4
View File
@@ -4,8 +4,8 @@ import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import { usernamePattern } from '../core/blitz/listPlayers.js'; import { usernamePattern } from '../core/blitz/listPlayers.js';
import addServerChoices from '../core/discord/addServerChoices.js'; import addServerChoices from '../core/discord/addServerChoices.js';
import addUsernameOption from '../core/discord/addUsernameOption.js'; import addUsernameChoices from '../core/discord/addUsernameChoices.js';
import infoEmbed from '../core/discord/infoEmbed.js'; import embedInfo from '../core/discord/embedInfo.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountList } from '../types/accountList.js'; import { AccountList } from '../types/accountList.js';
@@ -20,7 +20,7 @@ export default {
.setDescription('Search players in a Blitz server') .setDescription('Search players in a Blitz server')
.addStringOption(addServerChoices) .addStringOption(addServerChoices)
.addStringOption((option) => .addStringOption((option) =>
addUsernameOption(option).setAutocomplete(false).setRequired(true), addUsernameChoices(option).setAutocomplete(false).setRequired(true),
) )
.addIntegerOption((option) => .addIntegerOption((option) =>
option option
@@ -43,7 +43,7 @@ export default {
) )
: []; : [];
return infoEmbed( return embedInfo(
`Player search for "${markdownEscape(name)}" in ${BLITZ_SERVERS[server]}`, `Player search for "${markdownEscape(name)}" in ${BLITZ_SERVERS[server]}`,
`\`\`\`${ `\`\`\`${
players.length === 0 players.length === 0
+2 -2
View File
@@ -3,7 +3,7 @@ import { go } from 'fuzzysort';
import markdownEscape from 'markdown-escape'; import markdownEscape from 'markdown-escape';
import { TANK_NAMES } from '../core/blitz/tankopedia.js'; import { TANK_NAMES } from '../core/blitz/tankopedia.js';
import addTankChoices from '../core/discord/addTankChoices.js'; import addTankChoices from '../core/discord/addTankChoices.js';
import infoEmbed from '../core/discord/infoEmbed.js'; import embedInfo from '../core/discord/embedInfo.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
export default { export default {
@@ -30,7 +30,7 @@ export default {
(result) => result.target, (result) => result.target,
); );
return infoEmbed( return embedInfo(
`Tank search for "${markdownEscape(tank)}"`, `Tank search for "${markdownEscape(tank)}"`,
results.length === 0 results.length === 0
? 'No tanks found.' ? 'No tanks found.'
+6 -6
View File
@@ -2,7 +2,9 @@ import { SlashCommandBuilder } from 'discord.js';
import { CYCLIC_API } from '../constants/cyclic.js'; import { CYCLIC_API } from '../constants/cyclic.js';
import resolveTankId from '../core/blitz/resolveTankId.js'; import resolveTankId from '../core/blitz/resolveTankId.js';
import { Period } from '../core/discord/addPeriodSubCommands.js'; import { Period } from '../core/discord/addPeriodSubCommands.js';
import addStatsSubCommandGroups from '../core/discord/addStatsSubCommandGroups.js'; import addStatTypeSubCommandGroups from '../core/discord/addStatTypeSubCommandGroups.js';
import autocompleteTanks from '../core/discord/autocompleteTanks.js';
import autocompleteUsername from '../core/discord/autocompleteUsername.js';
import interactionToURL from '../core/discord/interactionToURL.js'; import interactionToURL from '../core/discord/interactionToURL.js';
import linkButton from '../core/discord/linkButton.js'; import linkButton from '../core/discord/linkButton.js';
import primaryButton from '../core/discord/primaryButton.js'; import primaryButton from '../core/discord/primaryButton.js';
@@ -10,8 +12,6 @@ import resolvePeriodFromButton from '../core/discord/resolvePeriodFromButton.js'
import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand.js'; import resolvePeriodFromCommand from '../core/discord/resolvePeriodFromCommand.js';
import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton.js'; import resolvePlayerFromButton from '../core/discord/resolvePlayerFromButton.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import tanksAutocomplete from '../core/discord/tanksAutocomplete.js';
import usernameAutocomplete from '../core/discord/usernameAutocomplete.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
import stats, { StatType } from '../renderers/stats.js'; import stats, { StatType } from '../renderers/stats.js';
@@ -20,7 +20,7 @@ export default {
inDevelopment: false, inDevelopment: false,
inPublic: true, inPublic: true,
command: addStatsSubCommandGroups( command: addStatTypeSubCommandGroups(
new SlashCommandBuilder() new SlashCommandBuilder()
.setName('stats') .setName('stats')
.setDescription('In-game statistics'), .setDescription('In-game statistics'),
@@ -51,8 +51,8 @@ export default {
}, },
autocomplete: (interaction) => { autocomplete: (interaction) => {
usernameAutocomplete(interaction); autocompleteUsername(interaction);
tanksAutocomplete(interaction); autocompleteTanks(interaction);
}, },
async button(interaction) { async button(interaction) {
+4 -4
View File
@@ -1,7 +1,7 @@
import { SlashCommandBuilder } from 'discord.js'; import { SlashCommandBuilder } from 'discord.js';
import addUsernameOption from '../core/discord/addUsernameOption.js'; import addUsernameChoices from '../core/discord/addUsernameChoices.js';
import autocompleteUsername from '../core/discord/autocompleteUsername.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import usernameAutocomplete from '../core/discord/usernameAutocomplete.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
import today from '../renderers/today.js'; import today from '../renderers/today.js';
@@ -13,7 +13,7 @@ export default {
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
.setName('today') .setName('today')
.setDescription('A general daily breakdown of your performance') .setDescription('A general daily breakdown of your performance')
.addStringOption(addUsernameOption), .addStringOption(addUsernameChoices),
async handler(interaction) { async handler(interaction) {
const player = await resolvePlayerFromCommand(interaction); const player = await resolvePlayerFromCommand(interaction);
@@ -21,5 +21,5 @@ export default {
return await today(player); return await today(player);
}, },
autocomplete: usernameAutocomplete, autocomplete: autocompleteUsername,
} satisfies CommandRegistry; } satisfies CommandRegistry;
+11 -11
View File
@@ -2,11 +2,11 @@ import { SlashCommandBuilder } from 'discord.js';
import markdownEscape from 'markdown-escape'; import markdownEscape from 'markdown-escape';
import discord from '../../discord.json' assert { type: 'json' }; import discord from '../../discord.json' assert { type: 'json' };
import getWargamingResponse from '../core/blitz/getWargamingResponse.js'; import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
import addUsernameOption from '../core/discord/addUsernameOption.js'; import addUsernameChoices from '../core/discord/addUsernameChoices.js';
import negativeEmbed from '../core/discord/negativeEmbed.js'; import autocompleteUsername from '../core/discord/autocompleteUsername.js';
import positiveEmbed from '../core/discord/positiveEmbed.js'; import embedNegative from '../core/discord/embedNegative.js';
import embedPositive from '../core/discord/embedPositive.js';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand.js';
import usernameAutocomplete from '../core/discord/usernameAutocomplete.js';
import { WARGAMING_APPLICATION_ID } from '../core/node/args.js'; import { WARGAMING_APPLICATION_ID } from '../core/node/args.js';
import { CommandRegistry } from '../events/interactionCreate/index.js'; import { CommandRegistry } from '../events/interactionCreate/index.js';
import { AccountInfo } from '../types/accountInfo.js'; import { AccountInfo } from '../types/accountInfo.js';
@@ -20,7 +20,7 @@ export default {
command: new SlashCommandBuilder() command: new SlashCommandBuilder()
.setName('verify') .setName('verify')
.setDescription("Set's the user's username to their in-game name") .setDescription("Set's the user's username to their in-game name")
.addStringOption((option) => addUsernameOption(option).setRequired(true)), .addStringOption((option) => addUsernameChoices(option).setRequired(true)),
async handler(interaction) { async handler(interaction) {
const blitzAccount = await resolvePlayerFromCommand(interaction); const blitzAccount = await resolvePlayerFromCommand(interaction);
@@ -38,13 +38,13 @@ export default {
interaction.guild?.members.cache.get(interaction.member?.user.id); interaction.guild?.members.cache.get(interaction.member?.user.id);
if (!interaction.guild?.members.me?.permissions.has('ManageNicknames')) { if (!interaction.guild?.members.me?.permissions.has('ManageNicknames')) {
return negativeEmbed( return embedNegative(
`${markdownEscape(interaction.user.username)} failed to verify`, `${markdownEscape(interaction.user.username)} failed to verify`,
"I don't have the permission to change your nickname.", "I don't have the permission to change your nickname.",
); );
} }
if (!interaction.member || !member) { if (!interaction.member || !member) {
return negativeEmbed( return embedNegative(
`${interaction.user.username} is not in this server`, `${interaction.user.username} is not in this server`,
"I couldn't find this person in this server. Did they leave?", "I couldn't find this person in this server. Did they leave?",
); );
@@ -55,7 +55,7 @@ export default {
if (interaction.guildId === discord.sklld_guild_id) { if (interaction.guildId === discord.sklld_guild_id) {
if (!interaction.guild?.members.me?.permissions.has('ManageRoles')) { if (!interaction.guild?.members.me?.permissions.has('ManageRoles')) {
return negativeEmbed( return embedNegative(
`${markdownEscape(interaction.user.username)} failed to verify`, `${markdownEscape(interaction.user.username)} failed to verify`,
"I don't have the permission to change your manage roles.", "I don't have the permission to change your manage roles.",
); );
@@ -65,19 +65,19 @@ export default {
await member.roles.add(discord.sklld_peasant_role); await member.roles.add(discord.sklld_peasant_role);
} }
return positiveEmbed( return embedPositive(
`${interaction.user.username} is verified`, `${interaction.user.username} is verified`,
`The user is now verified as ${markdownEscape( `The user is now verified as ${markdownEscape(
accountInfo[id].nickname, accountInfo[id].nickname,
)}${markdownEscape(clanTag)}`, )}${markdownEscape(clanTag)}`,
); );
} catch (error) { } catch (error) {
return negativeEmbed( return embedNegative(
`${interaction.user.username} failed to verify`, `${interaction.user.username} failed to verify`,
"I can't change your nickname because you have higher permissions than me. Try setting your nickname to your Blitz username manually.", "I can't change your nickname because you have higher permissions than me. Try setting your nickname to your Blitz username manually.",
); );
} }
}, },
autocomplete: usernameAutocomplete, autocomplete: autocompleteUsername,
} satisfies CommandRegistry; } satisfies CommandRegistry;
@@ -1,13 +1,15 @@
import { SlashCommandBuilder } from 'discord.js'; import { SlashCommandBuilder } from 'discord.js';
import addPeriodSubCommands from './addPeriodSubCommands.js'; import addPeriodSubCommands from './addPeriodSubCommands.js';
import addTankChoices from './addTankChoices.js'; import addTankChoices from './addTankChoices.js';
import addUsernameOption from './addUsernameOption.js'; import addUsernameChoices from './addUsernameChoices.js';
export default function addStatsSubCommandGroups(option: SlashCommandBuilder) { export default function addStatTypeSubCommandGroups(
option: SlashCommandBuilder,
) {
return option return option
.addSubcommandGroup((option) => .addSubcommandGroup((option) =>
addPeriodSubCommands(option, (option) => addPeriodSubCommands(option, (option) =>
option.addStringOption(addUsernameOption), option.addStringOption(addUsernameChoices),
) )
.setName('player') .setName('player')
.setDescription("Player's statistics"), .setDescription("Player's statistics"),
@@ -16,7 +18,7 @@ export default function addStatsSubCommandGroups(option: SlashCommandBuilder) {
addPeriodSubCommands(option, (option) => addPeriodSubCommands(option, (option) =>
option option
.addStringOption(addTankChoices) .addStringOption(addTankChoices)
.addStringOption(addUsernameOption), .addStringOption(addUsernameChoices),
) )
.setName('tank') .setName('tank')
.setDescription("Tank's statistics"), .setDescription("Tank's statistics"),
@@ -1,6 +1,6 @@
import { SlashCommandStringOption } from 'discord.js'; import { SlashCommandStringOption } from 'discord.js';
export default function addUsernameOption(option: SlashCommandStringOption) { export default function addUsernameChoices(option: SlashCommandStringOption) {
return option return option
.setName('username') .setName('username')
.setDescription( .setDescription(
@@ -6,7 +6,7 @@ import {
import { BLITZ_SERVERS } from '../../constants/servers.js'; import { BLITZ_SERVERS } from '../../constants/servers.js';
import listClans from '../blitz/listClans.js'; import listClans from '../blitz/listClans.js';
export default async function clanAutocomplete( export default async function autocompleteClan(
interaction: AutocompleteInteraction<CacheType>, interaction: AutocompleteInteraction<CacheType>,
) { ) {
const focusedOption = interaction.options.getFocused(true); const focusedOption = interaction.options.getFocused(true);
@@ -7,7 +7,7 @@ import { go } from 'fuzzysort';
import resolveTankName from '../blitz/resolveTankName.js'; import resolveTankName from '../blitz/resolveTankName.js';
import { TANKS } from '../blitz/tankopedia.js'; import { TANKS } from '../blitz/tankopedia.js';
export default async function tanksAutocomplete( export default async function autocompleteTanks(
interaction: AutocompleteInteraction<CacheType>, interaction: AutocompleteInteraction<CacheType>,
) { ) {
const focusedOption = interaction.options.getFocused(true); const focusedOption = interaction.options.getFocused(true);
@@ -6,7 +6,7 @@ import {
import { BLITZ_SERVERS } from '../../constants/servers.js'; import { BLITZ_SERVERS } from '../../constants/servers.js';
import listPlayers from '../blitz/listPlayers.js'; import listPlayers from '../blitz/listPlayers.js';
export default async function usernameAutocomplete( export default async function autocompleteUsername(
interaction: AutocompleteInteraction<CacheType>, interaction: AutocompleteInteraction<CacheType>,
) { ) {
const focusedOption = interaction.options.getFocused(true); const focusedOption = interaction.options.getFocused(true);
@@ -1,7 +1,7 @@
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder } from 'discord.js';
import { ACCENT_COLOR } from '../../constants/colors.js'; import { ACCENT_COLOR } from '../../constants/colors.js';
export default function infoEmbed(title: string, description: string) { export default function embedInfo(title: string, description: string) {
return new EmbedBuilder() return new EmbedBuilder()
.setColor(ACCENT_COLOR) .setColor(ACCENT_COLOR)
.setTitle(title) .setTitle(title)
@@ -1,7 +1,7 @@
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder } from 'discord.js';
import { NEGATIVE_COLOR } from '../../constants/colors.js'; import { NEGATIVE_COLOR } from '../../constants/colors.js';
export default function negativeEmbed(title: string, description: string) { export default function embedNegative(title: string, description: string) {
return new EmbedBuilder() return new EmbedBuilder()
.setColor(NEGATIVE_COLOR) .setColor(NEGATIVE_COLOR)
.setTitle(title) .setTitle(title)
@@ -1,7 +1,7 @@
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder } from 'discord.js';
import { POSITIVE_COLOR } from '../../constants/colors.js'; import { POSITIVE_COLOR } from '../../constants/colors.js';
export default function positiveEmbed(title: string, description: string) { export default function embedPositive(title: string, description: string) {
return new EmbedBuilder() return new EmbedBuilder()
.setColor(POSITIVE_COLOR) .setColor(POSITIVE_COLOR)
.setTitle(title) .setTitle(title)
@@ -1,7 +1,7 @@
import { EmbedBuilder } from 'discord.js'; import { EmbedBuilder } from 'discord.js';
import { WARNING_COLOR } from '../../constants/colors.js'; import { WARNING_COLOR } from '../../constants/colors.js';
export default function warningEmbed(title: string, description: string) { export default function embedWarning(title: string, description: string) {
return new EmbedBuilder() return new EmbedBuilder()
.setColor(WARNING_COLOR) .setColor(WARNING_COLOR)
.setTitle(title) .setTitle(title)
-12
View File
@@ -1,12 +0,0 @@
import { ButtonBuilder, ButtonStyle } from 'discord.js';
import { BlitzServer } from '../../constants/servers.js';
export default function fullBlitzStarsStats(
server: BlitzServer,
username: string,
) {
return new ButtonBuilder()
.setLabel('View on BlitzStars')
.setURL(`https://www.blitzstars.com/player/${server}/${username}`)
.setStyle(ButtonStyle.Link);
}
-9
View File
@@ -1,9 +0,0 @@
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
export default function generateCustomId(
interaction: ChatInputCommandInteraction<CacheType>,
) {
return `${interaction.commandName}/${
interaction.options.getSubcommandGroup() ?? ''
}/${interaction.options.getSubcommand() ?? ''}`;
}
@@ -1,7 +1,7 @@
export type TableInputEntry = [string, string | number] | []; export type TableInputEntry = [string, string | number] | [];
export type TableInput = TableInputEntry[]; export type TableInput = TableInputEntry[];
export default function cleanTable(input: TableInput) { export default function markdownTable(input: TableInput) {
return input return input
.filter((array) => array[1] !== undefined) .filter((array) => array[1] !== undefined)
.map((array) => (array.length === 0 ? '' : `**${array[0]}**: ${array[1]}`)) .map((array) => (array.length === 0 ? '' : `**${array[0]}**: ${array[1]}`))
-6
View File
@@ -1,6 +0,0 @@
import negativeEmbed from './negativeEmbed.js';
export const noMember = negativeEmbed(
'User of command is not a member',
'Discord claims that the user of this command does not have an account... strange!',
);
@@ -1,6 +0,0 @@
import negativeEmbed from './negativeEmbed.js';
export const notTrackedByBlitzStars = negativeEmbed(
'No data to display',
'Player is not tracked by BlitzStars.',
);
+1
View File
@@ -1,5 +1,6 @@
import { ButtonBuilder, ButtonStyle } from 'discord.js'; import { ButtonBuilder, ButtonStyle } from 'discord.js';
// TODO: ADD THIS AGAIN IMMEDIATELY
export const supportBlitzStars = new ButtonBuilder() export const supportBlitzStars = new ButtonBuilder()
.setLabel('Support BlitzStars') .setLabel('Support BlitzStars')
.setURL('https://www.blitzstars.com/supporters') .setURL('https://www.blitzstars.com/supporters')
@@ -5,9 +5,9 @@ import {
CacheType, CacheType,
ChatInputCommandInteraction, ChatInputCommandInteraction,
} from 'discord.js'; } from 'discord.js';
import negativeEmbed from '../../../core/discord/negativeEmbed.js'; import embedNegative from '../../../core/discord/embedNegative.js';
import normalizeInteractionReturnable from '../../../core/discord/normalizeInteractionReturnable.js'; import normalizeInteractionReturnable from '../../../core/discord/normalizeInteractionReturnable.js';
import warningEmbed from '../../../core/discord/warningEmbed.js'; import embedWarning from '../../../core/discord/embedWarning.js';
import { psa } from '../../../core/node/psa.js'; import { psa } from '../../../core/node/psa.js';
import { handleError } from '../../error.js'; import { handleError } from '../../error.js';
import { commands } from '../index.js'; import { commands } from '../index.js';
@@ -29,7 +29,7 @@ export default async function handleChatInputCommand(
if (psa.data) { if (psa.data) {
if (!reply.embeds) reply.embeds = []; if (!reply.embeds) reply.embeds = [];
reply.embeds.push(warningEmbed(psa.data.title, psa.data.description)); reply.embeds.push(embedWarning(psa.data.title, psa.data.description));
} }
await interaction.editReply(reply); await interaction.editReply(reply);
@@ -43,7 +43,7 @@ export default async function handleChatInputCommand(
await interaction.editReply({ await interaction.editReply({
embeds: [ embeds: [
negativeEmbed( embedNegative(
(error as Error).message, (error as Error).message,
`${(error as Error).cause ?? 'No further information is available.'}`, `${(error as Error).cause ?? 'No further information is available.'}`,
), ),