feat: removed nickname based command usage

This commit is contained in:
TresAbhi committed 2023-05-10 20:00:30 +00:00
1 parent 91af52b4b8
commit ae650eeb38
8 files changed
+24 -101

No files matched your search

+4 -7
View File
@@ -2,10 +2,10 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import markdownEscape from 'markdown-escape';
import { CommandRegistry } from '../behaviors/interactionCreate.js';
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
import { BlitzServer } from '../constants/servers.js';
import addIGNOption from '../utilities/addIGNOption.js';
import addServerChoices from '../utilities/addServerChoices.js';
import blitzLinks from '../utilities/blitzLinks.js';
import extractUser from '../utilities/extractUser.js';
import getBlitzAccount from '../utilities/getBlitzAccount.js';
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
@@ -38,13 +38,10 @@ export default {
async execute(interaction) {
const clan = interaction.options.getString('clan') as keyof typeof CLANS;
const extractedUser = await extractUser(interaction);
if (!extractedUser) return;
const { name, server } = extractedUser;
const name = interaction.options.getString('name')!;
const server = interaction.options.getString('server') as BlitzServer;
const blitzAccount = await getBlitzAccount(interaction, name, server);
if (!blitzAccount) return;
const blitzStarsAccount = await getBlitzStarsAccount(
+2 -2
View File
@@ -16,8 +16,8 @@ export default {
command: new SlashCommandBuilder()
.setName('searchplayers')
.setDescription('Search players in a Blitz server')
.addStringOption((option) => addServerChoices(option).setRequired(true))
.addStringOption((option) => addIGNOption(option).setRequired(true))
.addStringOption(addServerChoices)
.addStringOption(addIGNOption)
.addIntegerOption((option) =>
option
.setName('limit')
+4 -8
View File
@@ -2,13 +2,13 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import markdownEscape from 'markdown-escape';
import { CommandRegistry } from '../behaviors/interactionCreate.js';
import { SKILLED_COLOR } from '../constants/colors.js';
import { BlitzServer } from '../constants/servers.js';
import { AccountInfo, AllStats } from '../types/accountInfo.js';
import { PeriodStatistics, PlayerStatistics } from '../types/statistics.js';
import addIGNOption from '../utilities/addIGNOption.js';
import addServerChoices from '../utilities/addServerChoices.js';
import { args } from '../utilities/args.js';
import blitzLinks from '../utilities/blitzLinks.js';
import extractUser from '../utilities/extractUser.js';
import getBlitzAccount from '../utilities/getBlitzAccount.js';
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
import getWargamingResponse from '../utilities/getWargamingResponse.js';
@@ -41,14 +41,10 @@ export default {
async execute(interaction) {
const period = interaction.options.getString('period') as Period;
const extractedUser = await extractUser(interaction);
if (!extractedUser) return;
const { name, server } = extractedUser;
const command = `stats ${server} ${name} ${period}`;
const name = interaction.options.getString('name')!;
const server = interaction.options.getString('server') as BlitzServer;
const blitzAccount = await getBlitzAccount(interaction, name, server);
if (!blitzAccount) return;
const blitzStarsAccount = (await getBlitzStarsAccount(
+4 -6
View File
@@ -2,11 +2,11 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
import markdownEscape from 'markdown-escape';
import { CommandRegistry } from '../behaviors/interactionCreate.js';
import { SKILLED_COLOR } from '../constants/colors.js';
import { BlitzServer } from '../constants/servers.js';
import { TanksStats } from '../types/tanksStats.js';
import addIGNOption from '../utilities/addIGNOption.js';
import addServerChoices from '../utilities/addServerChoices.js';
import { args } from '../utilities/args.js';
import extractUser from '../utilities/extractUser.js';
import getBlitzAccount from '../utilities/getBlitzAccount.js';
import getWargamingResponse from '../utilities/getWargamingResponse.js';
import { TANK_TYPE_EMOJIS, tankopedia } from '../utilities/tankopedia.js';
@@ -53,12 +53,10 @@ export default {
async execute(interaction) {
const tier = interaction.options.getInteger('tier')!;
const extractedUser = await extractUser(interaction);
if (!extractedUser) return;
const { name, server } = extractedUser;
const name = interaction.options.getString('name')!;
const server = interaction.options.getString('server') as BlitzServer;
const account = await getBlitzAccount(interaction, name, server);
if (!account) return;
const tankStats = await getWargamingResponse<TanksStats>(
+8 -10
View File
@@ -3,7 +3,7 @@ import markdownEscape from 'markdown-escape';
import discord from '../../discord.json' assert { type: 'json' };
import { CommandRegistry } from '../behaviors/interactionCreate.js';
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
import { BLITZ_SERVERS_SHORT, BlitzServer } from '../constants/servers.js';
import { BlitzServer } from '../constants/servers.js';
import { PlayerClanData } from '../types/playerClanData.js';
import addIGNOption from '../utilities/addIGNOption.js';
import addServerChoices from '../utilities/addServerChoices.js';
@@ -19,8 +19,8 @@ export default {
command: new SlashCommandBuilder()
.setName('verify')
.setDescription("Set's the user's username to their in-game name")
.addStringOption((option) => addServerChoices(option).setRequired(true))
.addStringOption((Option) => addIGNOption(Option).setRequired(true)),
.addStringOption(addServerChoices)
.addStringOption(addIGNOption),
async execute(interaction) {
let name = interaction.options.getString('name')!;
@@ -65,9 +65,7 @@ export default {
if (member) {
try {
await member.setNickname(
`${name} (${BLITZ_SERVERS_SHORT[server]})${clanTag}`,
);
await member.setNickname(`${name}${clanTag}`);
if (interaction.guildId === discord.guild_id) {
if (
@@ -105,15 +103,15 @@ export default {
.setColor(POSITIVE_COLOR)
.setTitle(`${interaction.user.username} is verified`)
.setDescription(
`The user is now verified as ${markdownEscape(name)} (${
BLITZ_SERVERS_SHORT[server]
})${markdownEscape(clanTag)}`,
`The user is now verified as ${markdownEscape(
name,
)}${markdownEscape(clanTag)}`,
),
],
});
console.log(
`${interaction.user.username} verified as ${name} (${BLITZ_SERVERS_SHORT[server]})${clanTag}`,
`${interaction.user.username} verified as ${name}${clanTag}`,
);
} catch (error) {
await interaction.editReply({
+1 -1
View File
@@ -4,5 +4,5 @@ export default function addIGNOption(option: SlashCommandStringOption) {
return option
.setName('name')
.setDescription('The username you use in Blitz')
.setRequired(false);
.setRequired(true);
}
+1 -1
View File
@@ -10,5 +10,5 @@ export default function addServerChoices(option: SlashCommandStringOption) {
{ name: BLITZ_SERVERS.eu, value: 'eu' },
{ name: BLITZ_SERVERS.asia, value: 'asia' },
)
.setRequired(false);
.setRequired(true);
}
-66
View File
@@ -1,66 +0,0 @@
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
import {
BLITZ_SERVERS_SHORT,
BLITZ_SERVERS_SHORT_INVERSE,
BlitzServer,
} from '../constants/servers.js';
import { badNicknameFormat } from '../embeds/badNicknameFormat.js';
import { noMember } from '../embeds/noMember.js';
import errorEmbed from './errorEmbed.js';
const nicknamePattern = /(.+) \((.+)\)/;
const VALID_BLITZ_SERVERS_SHORT = Object.keys(BLITZ_SERVERS_SHORT_INVERSE);
export default async function extractUser(
interaction: ChatInputCommandInteraction<CacheType>,
) {
if (!interaction.member) {
await interaction.editReply({ embeds: [noMember] });
return;
}
const member = interaction.guild?.members.cache.get(
interaction.member.user.id,
);
const nickname = member?.nickname ?? member?.user.username;
if (!nickname) {
await interaction.editReply({ embeds: [noMember] });
return;
}
const matches = nickname.match(nicknamePattern);
if (!matches) {
await interaction.editReply({ embeds: [badNicknameFormat] });
return;
}
const [, nameMatch, serverMatch] = matches;
const nameArg = interaction.options.getString('name');
const serverArg = interaction.options.getString(
'server',
) as BlitzServer | null;
const name = nameArg ?? nameMatch;
const server =
BLITZ_SERVERS_SHORT[serverArg as keyof typeof BLITZ_SERVERS_SHORT] ??
serverMatch;
if (!VALID_BLITZ_SERVERS_SHORT.includes(server)) {
await interaction.editReply({
embeds: [
errorEmbed(
'Invalid server',
`"${server}" is not a valid server. Use the \`/verify\` command to setup your nickname correctly or manually provide me with the server in the command.`,
),
],
});
return;
}
return {
name,
server: BLITZ_SERVERS_SHORT_INVERSE[
server as keyof typeof BLITZ_SERVERS_SHORT_INVERSE
] as BlitzServer,
};
}