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