feat: removed search tanks

This commit is contained in:
TrèsAbhi committed 2024-03-08 20:43:30 -06:00
1 parent 3181f9c4e7
commit 4fedaf1cea
8 files changed
+101 -69

No files matched your search

@@ -10,7 +10,7 @@ import {
ModelTransformEventData, ModelTransformEventData,
modelTransformEvent, modelTransformEvent,
} from '../../../../../../../core/blitzkrieg/modelTransform'; } from '../../../../../../../core/blitzkrieg/modelTransform';
import { normalizeAnglePI } from '../../../../../../../core/math/normalizeAngle180'; import { normalizeAngleRad } from '../../../../../../../core/math/normalizeAngleRad';
import { useAwait } from '../../../../../../../hooks/useAwait'; import { useAwait } from '../../../../../../../hooks/useAwait';
import { useModel } from '../../../../../../../hooks/useModel'; import { useModel } from '../../../../../../../hooks/useModel';
import { mutateDuel, useDuel } from '../../../../../../../stores/duel'; import { mutateDuel, useDuel } from '../../../../../../../stores/duel';
@@ -172,8 +172,8 @@ export const TankModel = memo(() => {
} }
function handlePointerUp() { function handlePointerUp() {
mutateDuel((draft) => { mutateDuel((draft) => {
draft.protagonist!.pitch = normalizeAnglePI(pitch); draft.protagonist!.pitch = normalizeAngleRad(pitch);
draft.protagonist!.yaw = normalizeAnglePI(yaw); draft.protagonist!.yaw = normalizeAngleRad(yaw);
}); });
mutateTankopediaPersistent((draft) => { mutateTankopediaPersistent((draft) => {
draft.model.visual.controlsEnabled = true; draft.model.visual.controlsEnabled = true;
@@ -234,8 +234,8 @@ export const TankModel = memo(() => {
draft.model.visual.controlsEnabled = true; draft.model.visual.controlsEnabled = true;
}); });
mutateDuel((draft) => { mutateDuel((draft) => {
draft.protagonist!.pitch = normalizeAnglePI(pitch); draft.protagonist!.pitch = normalizeAngleRad(pitch);
draft.protagonist!.yaw = normalizeAnglePI(yaw); draft.protagonist!.yaw = normalizeAngleRad(yaw);
}); });
window.removeEventListener('pointermove', handlePointerMove); window.removeEventListener('pointermove', handlePointerMove);
window.removeEventListener('pointerup', handlePointerUp); window.removeEventListener('pointerup', handlePointerUp);
+26 -14
View File
@@ -1,11 +1,12 @@
import { SlashCommandBuilder } from 'discord.js';
import markdownEscape from 'markdown-escape'; import markdownEscape from 'markdown-escape';
import { getAccountInfo } from '../core/blitz/getAccountInfo'; import { getAccountInfo } from '../core/blitz/getAccountInfo';
import addUsernameChoices from '../core/discord/addUsernameChoices'; import addUsernameChoices from '../core/discord/addUsernameChoices';
import autocompleteUsername from '../core/discord/autocompleteUsername'; import autocompleteUsername from '../core/discord/autocompleteUsername';
import { createLocalizedCommand } from '../core/discord/createLocalizedCommand';
import embedInfo from '../core/discord/embedInfo'; import embedInfo from '../core/discord/embedInfo';
import markdownTable from '../core/discord/markdownTable'; import markdownTable from '../core/discord/markdownTable';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand'; import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
import { translator } from '../core/localization/translator';
import { CommandRegistry } from '../events/interactionCreate'; import { CommandRegistry } from '../events/interactionCreate';
export const playerInfoCommand = new Promise<CommandRegistry>((resolve) => { export const playerInfoCommand = new Promise<CommandRegistry>((resolve) => {
@@ -13,24 +14,28 @@ export const playerInfoCommand = new Promise<CommandRegistry>((resolve) => {
inProduction: true, inProduction: true,
inPublic: true, inPublic: true,
command: new SlashCommandBuilder() command:
.setName('player-info') createLocalizedCommand('player-info').addStringOption(addUsernameChoices),
.setDescription('Basic information about a player')
.addStringOption(addUsernameChoices),
async handler(interaction) { async handler(interaction) {
const { t, translate } = translator(interaction.locale);
const account = await resolvePlayerFromCommand(interaction); const account = await resolvePlayerFromCommand(interaction);
const { id, region: region } = account; const { id, region: region } = account;
const accountInfo = await getAccountInfo(region, id); const accountInfo = await getAccountInfo(region, id);
return embedInfo( return embedInfo(
`${markdownEscape(accountInfo.nickname)}'s information`, translate('bot.command.player_info.body.title', [
markdownEscape(accountInfo.nickname),
]),
markdownTable([ markdownTable([
['Nickname', `${accountInfo.nickname}`], [t`bot.command.player_info.body.nickname`, `${accountInfo.nickname}`],
['Battles', `${accountInfo.statistics.all.battles}`],
[ [
'Winrate', t`bot.command.player_info.body.battles`,
`${accountInfo.statistics.all.battles}`,
],
[
t`bot.command.player_info.body.winrate`,
`${( `${(
100 * 100 *
(accountInfo.statistics.all.wins / (accountInfo.statistics.all.wins /
@@ -38,14 +43,21 @@ export const playerInfoCommand = new Promise<CommandRegistry>((resolve) => {
).toFixed(2)}%`, ).toFixed(2)}%`,
], ],
[], [],
['Account ID', `${accountInfo.account_id}`],
[ [
'Created', t`bot.command.player_info.body.account_id`,
`${new Date(accountInfo.created_at * 1000).toDateString()}`, `${accountInfo.account_id}`,
], ],
[ [
'Last battle', t`bot.command.player_info.body.created`,
`${new Date(accountInfo.last_battle_time * 1000).toDateString()}`, new Date(accountInfo.created_at * 1000).toLocaleDateString(
interaction.locale,
),
],
[
t`bot.command.player_info.body.last_battle`,
new Date(accountInfo.last_battle_time * 1000).toLocaleDateString(
interaction.locale,
),
], ],
]), ]),
); );
+3 -1
View File
@@ -351,7 +351,9 @@ export const ratingsCommand = new Promise<CommandRegistry>(async (resolve) => {
playersAfter = playersAfter =
regionRatingsInfo.count - result[result.length - 1].position; regionRatingsInfo.count - result[result.length - 1].position;
titleName = `${ titleName = `${
leagueInfo ? leagueInfo.title : '' leagueInfo
? translate(`common.leagues.${LEAGUES[leagueInfo.index].name}`)
: ''
} - ${translate(`common.regions.short.${region}`)}`; } - ${translate(`common.regions.short.${region}`)}`;
titleImage = leagueInfo.big_icon.startsWith('http') titleImage = leagueInfo.big_icon.startsWith('http')
? leagueInfo.big_icon ? leagueInfo.big_icon
+47 -40
View File
@@ -1,44 +1,51 @@
import { SlashCommandBuilder } from 'discord.js'; // _____ _____ _ _ _ _ _____ ____ __ __ ______ ____ _____ _ __
import { go } from 'fuzzysort'; // |_ _| / ____| | | | /\ | | | | / ____/ __ \| \/ | ____| | _ \ /\ / ____| |/ /
import markdownEscape from 'markdown-escape'; // | | | (___ | |__| | / \ | | | | | | | | | | \ / | |__ | |_) | / \ | | | ' /
import { tankNames } from '../core/blitzkrieg/tankDefinitions'; // | | \___ \| __ | / /\ \ | | | | | | | | | | |\/| | __| | _ < / /\ \| | | <
import addTankChoices from '../core/discord/addTankChoices'; // _| |_ ____) | | | |/ ____ \| |____| |____ | |___| |__| | | | | |____ | |_) / ____ \ |____| . \
import embedInfo from '../core/discord/embedInfo'; // |_____| |_____/|_| |_/_/ \_\______|______| \_____\____/|_| |_|______| |____/_/ \_\_____|_|\_\
import { CommandRegistry } from '../events/interactionCreate';
export const searchTanksCommand = new Promise<CommandRegistry>((resolve) => { // import { SlashCommandBuilder } from 'discord.js';
resolve({ // import { go } from 'fuzzysort';
inProduction: true, // import markdownEscape from 'markdown-escape';
inPublic: true, // import { tankNames } from '../core/blitzkrieg/tankDefinitions';
// import addTankChoices from '../core/discord/addTankChoices';
// import embedInfo from '../core/discord/embedInfo';
// import { CommandRegistry } from '../events/interactionCreate';
command: new SlashCommandBuilder() // export const searchTanksCommand = new Promise<CommandRegistry>((resolve) => {
.setName('search-tanks') // resolve({
.setDescription('Search tanks') // inProduction: true,
.addStringOption((option) => // inPublic: true,
addTankChoices(option).setAutocomplete(false),
)
.addIntegerOption((option) =>
option
.setName('limit')
.setDescription('The size of the search result (default: 25)')
.setMinValue(1)
.setMaxValue(100),
),
async handler(interaction) { // command: new SlashCommandBuilder()
const tank = interaction.options.getString('tank')!; // .setName('search-tanks')
const limit = interaction.options.getInteger('limit') ?? 25; // .setDescription('Search tanks')
const results = go(tank, await tankNames, { // .addStringOption((option) =>
limit, // addTankChoices(option).setAutocomplete(false),
keys: ['combined'], // )
}).map((result) => result.obj.original); // .addIntegerOption((option) =>
// option
// .setName('limit')
// .setDescription('The size of the search result (default: 25)')
// .setMinValue(1)
// .setMaxValue(100),
// ),
return embedInfo( // async handler(interaction) {
`Tank search for "${markdownEscape(tank)}"`, // const tank = interaction.options.getString('tank')!;
results.length === 0 // const limit = interaction.options.getInteger('limit') ?? 25;
? 'No tanks found.' // const results = go(tank, await tankNames, {
: `\`\`\`\n${results.join('\n')}\n\`\`\``, // limit,
); // keys: ['combined'],
}, // }).map((result) => result.obj.original);
});
}); // return embedInfo(
// `Tank search for "${markdownEscape(tank)}"`,
// results.length === 0
// ? 'No tanks found.'
// : `\`\`\`\n${results.join('\n')}\n\`\`\``,
// );
// },
// });
// });
+4 -4
View File
@@ -1,6 +1,6 @@
import { clamp } from 'lodash'; import { clamp } from 'lodash';
import { PitchLimits, YawLimits } from '../blitzkrieg/modelDefinitions'; import { PitchLimits, YawLimits } from '../blitzkrieg/modelDefinitions';
import { normalizeAnglePI } from '../math/normalizeAngle180'; import { normalizeAngleRad } from '../math/normalizeAngleRad';
export function applyPitchYawLimits( export function applyPitchYawLimits(
pitch: number, // rad pitch: number, // rad
@@ -12,7 +12,7 @@ export function applyPitchYawLimits(
let newYaw = yaw; let newYaw = yaw;
if (yawLimits) { if (yawLimits) {
newYaw = normalizeAnglePI( newYaw = normalizeAngleRad(
clamp( clamp(
newYaw, newYaw,
-yawLimits.max * (Math.PI / 180), -yawLimits.max * (Math.PI / 180),
@@ -27,7 +27,7 @@ export function applyPitchYawLimits(
if (pitchLimits.back) { if (pitchLimits.back) {
const range = pitchLimits.back.range * (Math.PI / 180); const range = pitchLimits.back.range * (Math.PI / 180);
const yawRotatedAbs = Math.abs(normalizeAnglePI(newYaw - Math.PI)); const yawRotatedAbs = Math.abs(normalizeAngleRad(newYaw - Math.PI));
if (yawRotatedAbs <= range + transition) { if (yawRotatedAbs <= range + transition) {
if (yawRotatedAbs <= range) { if (yawRotatedAbs <= range) {
@@ -52,7 +52,7 @@ export function applyPitchYawLimits(
if (pitchLimits.front) { if (pitchLimits.front) {
const range = pitchLimits.front.range * (Math.PI / 180); const range = pitchLimits.front.range * (Math.PI / 180);
const yawAbs = Math.abs(normalizeAnglePI(newYaw)); const yawAbs = Math.abs(normalizeAngleRad(newYaw));
if (yawAbs <= range + transition) { if (yawAbs <= range + transition) {
if (yawAbs <= range) { if (yawAbs <= range) {
@@ -1,4 +1,4 @@
export function normalizeAnglePI(angle: number) { export function normalizeAngleRad(angle: number) {
const newAngle = angle % (2 * Math.PI); const newAngle = angle % (2 * Math.PI);
if (newAngle > Math.PI) return newAngle - 2 * Math.PI; if (newAngle > Math.PI) return newAngle - 2 * Math.PI;
if (newAngle < -Math.PI) return newAngle + 2 * Math.PI; if (newAngle < -Math.PI) return newAngle + 2 * Math.PI;
-4
View File
@@ -24,12 +24,10 @@ import { verifyCommand } from '../../commands/link';
import { ownedTanksCommand } from '../../commands/ownedTanks'; import { ownedTanksCommand } from '../../commands/ownedTanks';
import { permissionsCommand } from '../../commands/permissions'; import { permissionsCommand } from '../../commands/permissions';
import { pingCommand } from '../../commands/ping'; import { pingCommand } from '../../commands/ping';
import { playerAchievementsCommand } from '../../commands/playerAchievements';
import { playerInfoCommand } from '../../commands/playerInfo'; import { playerInfoCommand } from '../../commands/playerInfo';
import { ratingsCommand } from '../../commands/ratings'; import { ratingsCommand } from '../../commands/ratings';
import { searchClansCommand } from '../../commands/searchClans'; import { searchClansCommand } from '../../commands/searchClans';
import { searchPlayersCommand } from '../../commands/searchPlayers'; import { searchPlayersCommand } from '../../commands/searchPlayers';
import { searchTanksCommand } from '../../commands/searchTanks';
import { statsCommand } from '../../commands/stats'; import { statsCommand } from '../../commands/stats';
import { todayCommand } from '../../commands/today'; import { todayCommand } from '../../commands/today';
import getClientId from '../../core/blitzkrieg/getClientId'; import getClientId from '../../core/blitzkrieg/getClientId';
@@ -84,11 +82,9 @@ export const COMMANDS_RAW: Promise<CommandRegistry>[] = [
aboutCommand, aboutCommand,
inactiveCommand, inactiveCommand,
ownedTanksCommand, ownedTanksCommand,
playerAchievementsCommand,
playerInfoCommand, playerInfoCommand,
searchClansCommand, searchClansCommand,
searchPlayersCommand, searchPlayersCommand,
searchTanksCommand,
fullStatsCommand, fullStatsCommand,
breakdownCommand, breakdownCommand,
verifyCommand, verifyCommand,
+15
View File
@@ -471,6 +471,21 @@
"description": "Ping World of Tanks Blitz" "description": "Ping World of Tanks Blitz"
} }
} }
},
"player_info": {
"$": "player-info",
"description": "Basic information about a player",
"body": {
"title": "%'s information",
"nickname": "Nickname",
"battles": "Battles",
"winrate": "Winrate",
"account_id": "Account ID",
"created": "Created",
"last_battle": "Last battle"
}
} }
} }
}, },