mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 19:19:52 +02:00
feat: searchplayers
This commit is contained in:
1 parent
a9ba84e5d1
commit
8569079af9
12 files changed
+110
-91
No files matched your search
Vendored
+1
@@ -4,6 +4,7 @@
|
||||
"accountinfo",
|
||||
"kranvagn",
|
||||
"ownedtanks",
|
||||
"searchplayers",
|
||||
"SKLLD",
|
||||
"Smri",
|
||||
"strvk",
|
||||
|
||||
@@ -7,7 +7,7 @@ import isDev from '../utilities/isDev.js';
|
||||
const PROCESS_ERROR_EVENTS = ['uncaughtException'];
|
||||
const CLIENT_ERROR_EVENTS = ['error'];
|
||||
|
||||
function handleError(error: Error, client: Client) {
|
||||
export function handleError(error: Error, client: Client) {
|
||||
console.error(error);
|
||||
|
||||
(
|
||||
@@ -17,7 +17,7 @@ function handleError(error: Error, client: Client) {
|
||||
).send({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setTitle(`${client.user?.username} ran into a catastrophic error`)
|
||||
.setTitle(`${client.user?.username} ran into an error`)
|
||||
.setColor(NEGATIVE_COLOR)
|
||||
.setDescription(
|
||||
`\`\`\`${error.name}\n${error.message}\n${error.stack}\n${error.cause}\`\`\``,
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.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 getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
|
||||
@@ -30,23 +32,8 @@ export default {
|
||||
)
|
||||
.setRequired(true),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('server')
|
||||
.setDescription('The Blitz server you are in')
|
||||
.addChoices(
|
||||
{ name: BLITZ_SERVERS.com, value: 'com' },
|
||||
{ name: BLITZ_SERVERS.eu, value: 'eu' },
|
||||
{ name: BLITZ_SERVERS.asia, value: 'asia' },
|
||||
)
|
||||
.setRequired(true),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('name')
|
||||
.setDescription('The username you use in Blitz')
|
||||
.setRequired(true),
|
||||
),
|
||||
.addStringOption(addServerChoices)
|
||||
.addStringOption(addIGNOption),
|
||||
|
||||
execute(interaction) {
|
||||
const name = interaction.options.getString('name')!;
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.js';
|
||||
import { BlitzServer } from '../constants/servers.js';
|
||||
import { ClanInfo } from '../types/clanInfo.js';
|
||||
import { PlayerPersonalData } from '../types/playerPersonalData.js';
|
||||
import addServerChoices from '../utilities/addServerChoices.js';
|
||||
import { args } from '../utilities/args.js';
|
||||
import getClan from '../utilities/getClan.js';
|
||||
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
||||
@@ -18,17 +19,7 @@ export default {
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('inactive')
|
||||
.setDescription('Lists all inactive players')
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('server')
|
||||
.setDescription('The Blitz server you are in')
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: BLITZ_SERVERS.com, value: 'com' },
|
||||
{ name: BLITZ_SERVERS.eu, value: 'eu' },
|
||||
{ name: BLITZ_SERVERS.asia, value: 'asia' },
|
||||
),
|
||||
)
|
||||
.addStringOption(addServerChoices)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('name')
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { SKILLED_COLOR } from '../constants/colors.js';
|
||||
import { Players } from '../types/players.js';
|
||||
import addIGNOption from '../utilities/addIGNOption.js';
|
||||
import addServerChoices from '../utilities/addServerChoices.js';
|
||||
import { args } from '../utilities/args.js';
|
||||
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
||||
|
||||
export default {
|
||||
inDevelopment: false,
|
||||
inProduction: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('searchplayers')
|
||||
.setDescription('Search players in a Blitz server')
|
||||
.addStringOption(addServerChoices)
|
||||
.addStringOption(addIGNOption)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('limit')
|
||||
.setDescription('The size of the search result (default: 25)')
|
||||
.setMinValue(1)
|
||||
.setMaxValue(100),
|
||||
),
|
||||
|
||||
execute(interaction) {
|
||||
const server = interaction.options.getString('server')!;
|
||||
const name = interaction.options.getString('name')!;
|
||||
const limit = interaction.options.getInteger('limit') ?? 25;
|
||||
|
||||
getWargamingResponse<Players>(
|
||||
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${name}&limit=${limit}`,
|
||||
interaction,
|
||||
(players) => {
|
||||
interaction.editReply({
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setColor(SKILLED_COLOR)
|
||||
.setTitle(`Player search results for "${name}"`)
|
||||
.setDescription(
|
||||
`\`\`\`${
|
||||
players.length === 0
|
||||
? 'No players found.'
|
||||
: players.map((player) => player.nickname).join('\n')
|
||||
}\`\`\``,
|
||||
),
|
||||
],
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
} satisfies CommandRegistry;
|
||||
+5
-18
@@ -1,7 +1,9 @@
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { SKILLED_COLOR } from '../constants/colors.js';
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.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 getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
|
||||
@@ -26,23 +28,8 @@ export default {
|
||||
)
|
||||
.setRequired(true),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('server')
|
||||
.setDescription('The Blitz server you are in')
|
||||
.addChoices(
|
||||
{ name: BLITZ_SERVERS.com, value: 'com' },
|
||||
{ name: BLITZ_SERVERS.eu, value: 'eu' },
|
||||
{ name: BLITZ_SERVERS.asia, value: 'asia' },
|
||||
)
|
||||
.setRequired(true),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('name')
|
||||
.setDescription('The username you use in Blitz')
|
||||
.setRequired(true),
|
||||
),
|
||||
.addStringOption(addServerChoices)
|
||||
.addStringOption(addIGNOption),
|
||||
|
||||
execute(interaction) {
|
||||
const name = interaction.options.getString('name')!;
|
||||
|
||||
+7
-20
@@ -1,8 +1,10 @@
|
||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { SKILLED_COLOR } from '../constants/colors.js';
|
||||
import { BLITZ_SERVERS, BlitzServer } from '../constants/servers.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 getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
||||
@@ -37,24 +39,9 @@ export default {
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('tanks')
|
||||
.setDescription("Shows a player's owned tanks")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('server')
|
||||
.setDescription('The Blitz server you are in')
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: BLITZ_SERVERS.com, value: 'com' },
|
||||
{ name: BLITZ_SERVERS.eu, value: 'eu' },
|
||||
{ name: BLITZ_SERVERS.asia, value: 'asia' },
|
||||
),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('name')
|
||||
.setDescription('The username you use in Blitz')
|
||||
.setRequired(true),
|
||||
)
|
||||
.addNumberOption((option) =>
|
||||
.addStringOption(addServerChoices)
|
||||
.addStringOption(addIGNOption)
|
||||
.addIntegerOption((option) =>
|
||||
option
|
||||
.setName('tier')
|
||||
.setDescription('The tier you want to see (default: all tiers)')
|
||||
@@ -66,7 +53,7 @@ export default {
|
||||
execute(interaction) {
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
const name = interaction.options.getString('name')!;
|
||||
const tier = Math.round(interaction.options.getNumber('tier')!);
|
||||
const tier = interaction.options.getInteger('tier')!;
|
||||
|
||||
getBlitzAccount(interaction, name, server, async (account) => {
|
||||
getWargamingResponse<TanksStats>(
|
||||
|
||||
+5
-18
@@ -2,8 +2,10 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
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, 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';
|
||||
import { args } from '../utilities/args.js';
|
||||
import getBlitzAccount from '../utilities/getBlitzAccount.js';
|
||||
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
||||
@@ -16,23 +18,8 @@ export default {
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('verify')
|
||||
.setDescription("Set's the user's username to their in-game name")
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('server')
|
||||
.setDescription('The Blitz server you are in')
|
||||
.setRequired(true)
|
||||
.addChoices(
|
||||
{ name: BLITZ_SERVERS.com, value: 'com' },
|
||||
{ name: BLITZ_SERVERS.eu, value: 'eu' },
|
||||
{ name: BLITZ_SERVERS.asia, value: 'asia' },
|
||||
),
|
||||
)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('name')
|
||||
.setDescription('The username you use in Blitz')
|
||||
.setRequired(true),
|
||||
),
|
||||
.addStringOption(addServerChoices)
|
||||
.addStringOption(addIGNOption),
|
||||
|
||||
execute(interaction) {
|
||||
const name = interaction.options.getString('name')!;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { SlashCommandStringOption } from 'discord.js';
|
||||
|
||||
export default function addIGNOption(option: SlashCommandStringOption) {
|
||||
return option
|
||||
.setName('name')
|
||||
.setDescription('The username you use in Blitz')
|
||||
.setRequired(true);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import { SlashCommandStringOption } from 'discord.js';
|
||||
import { BLITZ_SERVERS } from '../constants/servers.js';
|
||||
|
||||
export default function addServerChoices(option: SlashCommandStringOption) {
|
||||
return option
|
||||
.setName('server')
|
||||
.setDescription('The Blitz server you are in')
|
||||
.addChoices(
|
||||
{ name: BLITZ_SERVERS.com, value: 'com' },
|
||||
{ name: BLITZ_SERVERS.eu, value: 'eu' },
|
||||
{ name: BLITZ_SERVERS.asia, value: 'asia' },
|
||||
)
|
||||
.setRequired(true);
|
||||
}
|
||||
@@ -16,8 +16,8 @@ export default async function getWargamingResponse<Data extends object>(
|
||||
if (response.status === 'ok') {
|
||||
callback(response.data);
|
||||
} else {
|
||||
wargamingError(interaction);
|
||||
wargamingError(interaction, new Error(`Status ${response.status}`));
|
||||
}
|
||||
})
|
||||
.catch(() => wargamingError(interaction));
|
||||
.catch((error) => wargamingError(interaction, error));
|
||||
}
|
||||
@@ -3,11 +3,13 @@ import {
|
||||
ChatInputCommandInteraction,
|
||||
EmbedBuilder,
|
||||
} from 'discord.js';
|
||||
import { handleError } from '../behaviors/error.js';
|
||||
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
||||
import { client } from '../index.js';
|
||||
|
||||
export default async function wargamingError(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
error: Error,
|
||||
) {
|
||||
await interaction.editReply({
|
||||
embeds: [
|
||||
@@ -18,5 +20,6 @@ export default async function wargamingError(
|
||||
],
|
||||
});
|
||||
|
||||
console.log('Wargaming returned an error.');
|
||||
console.log(`Wargaming returned an error`);
|
||||
handleError(error, client);
|
||||
}
|
||||
Reference in new issue
Block a user