mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: removed nickname based command usage
This commit is contained in:
1 parent
91af52b4b8
commit
ae650eeb38
8 files changed
+24
-101
No files matched your search
@@ -2,10 +2,10 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
|||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||||
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
||||||
|
import { BlitzServer } from '../constants/servers.js';
|
||||||
import addIGNOption from '../utilities/addIGNOption.js';
|
import addIGNOption from '../utilities/addIGNOption.js';
|
||||||
import addServerChoices from '../utilities/addServerChoices.js';
|
import addServerChoices from '../utilities/addServerChoices.js';
|
||||||
import blitzLinks from '../utilities/blitzLinks.js';
|
import blitzLinks from '../utilities/blitzLinks.js';
|
||||||
import extractUser from '../utilities/extractUser.js';
|
|
||||||
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||||
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
|
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
|
||||||
import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
|
import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
|
||||||
@@ -38,13 +38,10 @@ export default {
|
|||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const clan = interaction.options.getString('clan') as keyof typeof CLANS;
|
const clan = interaction.options.getString('clan') as keyof typeof CLANS;
|
||||||
|
const name = interaction.options.getString('name')!;
|
||||||
const extractedUser = await extractUser(interaction);
|
const server = interaction.options.getString('server') as BlitzServer;
|
||||||
if (!extractedUser) return;
|
|
||||||
|
|
||||||
const { name, server } = extractedUser;
|
|
||||||
|
|
||||||
const blitzAccount = await getBlitzAccount(interaction, name, server);
|
const blitzAccount = await getBlitzAccount(interaction, name, server);
|
||||||
|
|
||||||
if (!blitzAccount) return;
|
if (!blitzAccount) return;
|
||||||
|
|
||||||
const blitzStarsAccount = await getBlitzStarsAccount(
|
const blitzStarsAccount = await getBlitzStarsAccount(
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ export default {
|
|||||||
command: new SlashCommandBuilder()
|
command: new SlashCommandBuilder()
|
||||||
.setName('searchplayers')
|
.setName('searchplayers')
|
||||||
.setDescription('Search players in a Blitz server')
|
.setDescription('Search players in a Blitz server')
|
||||||
.addStringOption((option) => addServerChoices(option).setRequired(true))
|
.addStringOption(addServerChoices)
|
||||||
.addStringOption((option) => addIGNOption(option).setRequired(true))
|
.addStringOption(addIGNOption)
|
||||||
.addIntegerOption((option) =>
|
.addIntegerOption((option) =>
|
||||||
option
|
option
|
||||||
.setName('limit')
|
.setName('limit')
|
||||||
|
|||||||
@@ -2,13 +2,13 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
|||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||||
import { SKILLED_COLOR } from '../constants/colors.js';
|
import { SKILLED_COLOR } from '../constants/colors.js';
|
||||||
|
import { BlitzServer } from '../constants/servers.js';
|
||||||
import { AccountInfo, AllStats } from '../types/accountInfo.js';
|
import { AccountInfo, AllStats } from '../types/accountInfo.js';
|
||||||
import { PeriodStatistics, PlayerStatistics } from '../types/statistics.js';
|
import { PeriodStatistics, PlayerStatistics } from '../types/statistics.js';
|
||||||
import addIGNOption from '../utilities/addIGNOption.js';
|
import addIGNOption from '../utilities/addIGNOption.js';
|
||||||
import addServerChoices from '../utilities/addServerChoices.js';
|
import addServerChoices from '../utilities/addServerChoices.js';
|
||||||
import { args } from '../utilities/args.js';
|
import { args } from '../utilities/args.js';
|
||||||
import blitzLinks from '../utilities/blitzLinks.js';
|
import blitzLinks from '../utilities/blitzLinks.js';
|
||||||
import extractUser from '../utilities/extractUser.js';
|
|
||||||
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||||
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
|
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
|
||||||
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
||||||
@@ -41,14 +41,10 @@ export default {
|
|||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const period = interaction.options.getString('period') as Period;
|
const period = interaction.options.getString('period') as Period;
|
||||||
|
const name = interaction.options.getString('name')!;
|
||||||
const extractedUser = await extractUser(interaction);
|
const server = interaction.options.getString('server') as BlitzServer;
|
||||||
if (!extractedUser) return;
|
|
||||||
|
|
||||||
const { name, server } = extractedUser;
|
|
||||||
const command = `stats ${server} ${name} ${period}`;
|
|
||||||
|
|
||||||
const blitzAccount = await getBlitzAccount(interaction, name, server);
|
const blitzAccount = await getBlitzAccount(interaction, name, server);
|
||||||
|
|
||||||
if (!blitzAccount) return;
|
if (!blitzAccount) return;
|
||||||
|
|
||||||
const blitzStarsAccount = (await getBlitzStarsAccount(
|
const blitzStarsAccount = (await getBlitzStarsAccount(
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
|||||||
import markdownEscape from 'markdown-escape';
|
import markdownEscape from 'markdown-escape';
|
||||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||||
import { SKILLED_COLOR } from '../constants/colors.js';
|
import { SKILLED_COLOR } from '../constants/colors.js';
|
||||||
|
import { BlitzServer } from '../constants/servers.js';
|
||||||
import { TanksStats } from '../types/tanksStats.js';
|
import { TanksStats } from '../types/tanksStats.js';
|
||||||
import addIGNOption from '../utilities/addIGNOption.js';
|
import addIGNOption from '../utilities/addIGNOption.js';
|
||||||
import addServerChoices from '../utilities/addServerChoices.js';
|
import addServerChoices from '../utilities/addServerChoices.js';
|
||||||
import { args } from '../utilities/args.js';
|
import { args } from '../utilities/args.js';
|
||||||
import extractUser from '../utilities/extractUser.js';
|
|
||||||
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||||
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
||||||
import { TANK_TYPE_EMOJIS, tankopedia } from '../utilities/tankopedia.js';
|
import { TANK_TYPE_EMOJIS, tankopedia } from '../utilities/tankopedia.js';
|
||||||
@@ -53,12 +53,10 @@ export default {
|
|||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
const tier = interaction.options.getInteger('tier')!;
|
const tier = interaction.options.getInteger('tier')!;
|
||||||
const extractedUser = await extractUser(interaction);
|
const name = interaction.options.getString('name')!;
|
||||||
if (!extractedUser) return;
|
const server = interaction.options.getString('server') as BlitzServer;
|
||||||
|
|
||||||
const { name, server } = extractedUser;
|
|
||||||
|
|
||||||
const account = await getBlitzAccount(interaction, name, server);
|
const account = await getBlitzAccount(interaction, name, server);
|
||||||
|
|
||||||
if (!account) return;
|
if (!account) return;
|
||||||
|
|
||||||
const tankStats = await getWargamingResponse<TanksStats>(
|
const tankStats = await getWargamingResponse<TanksStats>(
|
||||||
|
|||||||
+8
-10
@@ -3,7 +3,7 @@ import markdownEscape from 'markdown-escape';
|
|||||||
import discord from '../../discord.json' assert { type: 'json' };
|
import discord from '../../discord.json' assert { type: 'json' };
|
||||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||||
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.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 { PlayerClanData } from '../types/playerClanData.js';
|
||||||
import addIGNOption from '../utilities/addIGNOption.js';
|
import addIGNOption from '../utilities/addIGNOption.js';
|
||||||
import addServerChoices from '../utilities/addServerChoices.js';
|
import addServerChoices from '../utilities/addServerChoices.js';
|
||||||
@@ -19,8 +19,8 @@ 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) => addServerChoices(option).setRequired(true))
|
.addStringOption(addServerChoices)
|
||||||
.addStringOption((Option) => addIGNOption(Option).setRequired(true)),
|
.addStringOption(addIGNOption),
|
||||||
|
|
||||||
async execute(interaction) {
|
async execute(interaction) {
|
||||||
let name = interaction.options.getString('name')!;
|
let name = interaction.options.getString('name')!;
|
||||||
@@ -65,9 +65,7 @@ export default {
|
|||||||
|
|
||||||
if (member) {
|
if (member) {
|
||||||
try {
|
try {
|
||||||
await member.setNickname(
|
await member.setNickname(`${name}${clanTag}`);
|
||||||
`${name} (${BLITZ_SERVERS_SHORT[server]})${clanTag}`,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (interaction.guildId === discord.guild_id) {
|
if (interaction.guildId === discord.guild_id) {
|
||||||
if (
|
if (
|
||||||
@@ -105,15 +103,15 @@ export default {
|
|||||||
.setColor(POSITIVE_COLOR)
|
.setColor(POSITIVE_COLOR)
|
||||||
.setTitle(`${interaction.user.username} is verified`)
|
.setTitle(`${interaction.user.username} is verified`)
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`The user is now verified as ${markdownEscape(name)} (${
|
`The user is now verified as ${markdownEscape(
|
||||||
BLITZ_SERVERS_SHORT[server]
|
name,
|
||||||
})${markdownEscape(clanTag)}`,
|
)}${markdownEscape(clanTag)}`,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`${interaction.user.username} verified as ${name} (${BLITZ_SERVERS_SHORT[server]})${clanTag}`,
|
`${interaction.user.username} verified as ${name}${clanTag}`,
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ export default function addIGNOption(option: SlashCommandStringOption) {
|
|||||||
return option
|
return option
|
||||||
.setName('name')
|
.setName('name')
|
||||||
.setDescription('The username you use in Blitz')
|
.setDescription('The username you use in Blitz')
|
||||||
.setRequired(false);
|
.setRequired(true);
|
||||||
}
|
}
|
||||||
@@ -10,5 +10,5 @@ export default function addServerChoices(option: SlashCommandStringOption) {
|
|||||||
{ name: BLITZ_SERVERS.eu, value: 'eu' },
|
{ name: BLITZ_SERVERS.eu, value: 'eu' },
|
||||||
{ name: BLITZ_SERVERS.asia, value: 'asia' },
|
{ name: BLITZ_SERVERS.asia, value: 'asia' },
|
||||||
)
|
)
|
||||||
.setRequired(false);
|
.setRequired(true);
|
||||||
}
|
}
|
||||||
@@ -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,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user