mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 20:19:49 +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",
|
"accountinfo",
|
||||||
"kranvagn",
|
"kranvagn",
|
||||||
"ownedtanks",
|
"ownedtanks",
|
||||||
|
"searchplayers",
|
||||||
"SKLLD",
|
"SKLLD",
|
||||||
"Smri",
|
"Smri",
|
||||||
"strvk",
|
"strvk",
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import isDev from '../utilities/isDev.js';
|
|||||||
const PROCESS_ERROR_EVENTS = ['uncaughtException'];
|
const PROCESS_ERROR_EVENTS = ['uncaughtException'];
|
||||||
const CLIENT_ERROR_EVENTS = ['error'];
|
const CLIENT_ERROR_EVENTS = ['error'];
|
||||||
|
|
||||||
function handleError(error: Error, client: Client) {
|
export function handleError(error: Error, client: Client) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|
||||||
(
|
(
|
||||||
@@ -17,7 +17,7 @@ function handleError(error: Error, client: Client) {
|
|||||||
).send({
|
).send({
|
||||||
embeds: [
|
embeds: [
|
||||||
new EmbedBuilder()
|
new EmbedBuilder()
|
||||||
.setTitle(`${client.user?.username} ran into a catastrophic error`)
|
.setTitle(`${client.user?.username} ran into an error`)
|
||||||
.setColor(NEGATIVE_COLOR)
|
.setColor(NEGATIVE_COLOR)
|
||||||
.setDescription(
|
.setDescription(
|
||||||
`\`\`\`${error.name}\n${error.message}\n${error.stack}\n${error.cause}\`\`\``,
|
`\`\`\`${error.name}\n${error.message}\n${error.stack}\n${error.cause}\`\`\``,
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||||
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, 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 blitzLinks from '../utilities/blitzLinks.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';
|
||||||
@@ -30,23 +32,8 @@ export default {
|
|||||||
)
|
)
|
||||||
.setRequired(true),
|
.setRequired(true),
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption(addServerChoices)
|
||||||
option
|
.addStringOption(addIGNOption),
|
||||||
.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),
|
|
||||||
),
|
|
||||||
|
|
||||||
execute(interaction) {
|
execute(interaction) {
|
||||||
const name = interaction.options.getString('name')!;
|
const name = interaction.options.getString('name')!;
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||||
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, BlitzServer } from '../constants/servers.js';
|
import { BlitzServer } from '../constants/servers.js';
|
||||||
import { ClanInfo } from '../types/clanInfo.js';
|
import { ClanInfo } from '../types/clanInfo.js';
|
||||||
import { PlayerPersonalData } from '../types/playerPersonalData.js';
|
import { PlayerPersonalData } from '../types/playerPersonalData.js';
|
||||||
|
import addServerChoices from '../utilities/addServerChoices.js';
|
||||||
import { args } from '../utilities/args.js';
|
import { args } from '../utilities/args.js';
|
||||||
import getClan from '../utilities/getClan.js';
|
import getClan from '../utilities/getClan.js';
|
||||||
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
import getWargamingResponse from '../utilities/getWargamingResponse.js';
|
||||||
@@ -18,17 +19,7 @@ export default {
|
|||||||
command: new SlashCommandBuilder()
|
command: new SlashCommandBuilder()
|
||||||
.setName('inactive')
|
.setName('inactive')
|
||||||
.setDescription('Lists all inactive players')
|
.setDescription('Lists all inactive players')
|
||||||
.addStringOption((option) =>
|
.addStringOption(addServerChoices)
|
||||||
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) =>
|
.addStringOption((option) =>
|
||||||
option
|
option
|
||||||
.setName('name')
|
.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 { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||||
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 { 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 blitzLinks from '../utilities/blitzLinks.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';
|
||||||
@@ -26,23 +28,8 @@ export default {
|
|||||||
)
|
)
|
||||||
.setRequired(true),
|
.setRequired(true),
|
||||||
)
|
)
|
||||||
.addStringOption((option) =>
|
.addStringOption(addServerChoices)
|
||||||
option
|
.addStringOption(addIGNOption),
|
||||||
.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),
|
|
||||||
),
|
|
||||||
|
|
||||||
execute(interaction) {
|
execute(interaction) {
|
||||||
const name = interaction.options.getString('name')!;
|
const name = interaction.options.getString('name')!;
|
||||||
|
|||||||
+7
-20
@@ -1,8 +1,10 @@
|
|||||||
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||||
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 { BLITZ_SERVERS, BlitzServer } from '../constants/servers.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 addServerChoices from '../utilities/addServerChoices.js';
|
||||||
import { args } from '../utilities/args.js';
|
import { args } from '../utilities/args.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';
|
||||||
@@ -37,24 +39,9 @@ export default {
|
|||||||
command: new SlashCommandBuilder()
|
command: new SlashCommandBuilder()
|
||||||
.setName('tanks')
|
.setName('tanks')
|
||||||
.setDescription("Shows a player's owned tanks")
|
.setDescription("Shows a player's owned tanks")
|
||||||
.addStringOption((option) =>
|
.addStringOption(addServerChoices)
|
||||||
option
|
.addStringOption(addIGNOption)
|
||||||
.setName('server')
|
.addIntegerOption((option) =>
|
||||||
.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) =>
|
|
||||||
option
|
option
|
||||||
.setName('tier')
|
.setName('tier')
|
||||||
.setDescription('The tier you want to see (default: all tiers)')
|
.setDescription('The tier you want to see (default: all tiers)')
|
||||||
@@ -66,7 +53,7 @@ export default {
|
|||||||
execute(interaction) {
|
execute(interaction) {
|
||||||
const server = interaction.options.getString('server') as BlitzServer;
|
const server = interaction.options.getString('server') as BlitzServer;
|
||||||
const name = interaction.options.getString('name')!;
|
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) => {
|
getBlitzAccount(interaction, name, server, async (account) => {
|
||||||
getWargamingResponse<TanksStats>(
|
getWargamingResponse<TanksStats>(
|
||||||
|
|||||||
+5
-18
@@ -2,8 +2,10 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
|||||||
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, 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 addServerChoices from '../utilities/addServerChoices.js';
|
||||||
import { args } from '../utilities/args.js';
|
import { args } from '../utilities/args.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';
|
||||||
@@ -16,23 +18,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) =>
|
.addStringOption(addServerChoices)
|
||||||
option
|
.addStringOption(addIGNOption),
|
||||||
.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),
|
|
||||||
),
|
|
||||||
|
|
||||||
execute(interaction) {
|
execute(interaction) {
|
||||||
const name = interaction.options.getString('name')!;
|
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') {
|
if (response.status === 'ok') {
|
||||||
callback(response.data);
|
callback(response.data);
|
||||||
} else {
|
} else {
|
||||||
wargamingError(interaction);
|
wargamingError(interaction, new Error(`Status ${response.status}`));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => wargamingError(interaction));
|
.catch((error) => wargamingError(interaction, error));
|
||||||
}
|
}
|
||||||
@@ -3,11 +3,13 @@ import {
|
|||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
} from 'discord.js';
|
} from 'discord.js';
|
||||||
|
import { handleError } from '../behaviors/error.js';
|
||||||
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
import { NEGATIVE_COLOR } from '../constants/colors.js';
|
||||||
import { client } from '../index.js';
|
import { client } from '../index.js';
|
||||||
|
|
||||||
export default async function wargamingError(
|
export default async function wargamingError(
|
||||||
interaction: ChatInputCommandInteraction<CacheType>,
|
interaction: ChatInputCommandInteraction<CacheType>,
|
||||||
|
error: Error,
|
||||||
) {
|
) {
|
||||||
await interaction.editReply({
|
await interaction.editReply({
|
||||||
embeds: [
|
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