feat: username suggestions

This commit is contained in:
TresAbhi committed 2023-05-14 17:13:42 +00:00
1 parent 613527e78f
commit 692f4d2b80
13 files changed
+167 -102

No files matched your search

-54
View File
@@ -1,54 +0,0 @@
import {
CacheType,
ChatInputCommandInteraction,
EmbedBuilder,
} from 'discord.js';
import markdownEscape from 'markdown-escape';
import { NEGATIVE_COLOR } from '../../constants/colors.js';
import { BLITZ_SERVERS, BlitzServer } from '../../constants/servers.js';
import { Players } from '../../types/players.js';
import { args } from '../process/args.js';
import getWargamingResponse from './getWargamingResponse.js';
export default async function getBlitzAccount(
interaction: ChatInputCommandInteraction<CacheType>,
name: string,
server: BlitzServer,
) {
const serverName = BLITZ_SERVERS[server];
const players = await getWargamingResponse<Players>(
`https://api.wotblitz.${server}/wotb/account/list/?application_id=${args['wargaming-application-id']}&search=${name}`,
);
if (
players.length > 0 &&
players[0].nickname.toLowerCase() === name.toLowerCase()
) {
return players[0];
} else {
// no exact match
await interaction.editReply({
embeds: [
new EmbedBuilder()
.setColor(NEGATIVE_COLOR)
.setTitle(`Account not found`)
.setDescription(
`I couldn't find "${markdownEscape(
name,
)}" in the ${serverName} server. I found ${
players ? (players.length < 100 ? players.length : 'over 100') : 0
} similarly spelled account${players?.length !== 1 ? 's' : ''}. ${
players && players.length > 0
? `Did you mean "${markdownEscape(players[0].nickname)}"? `
: ''
}Use the \`/verify\` command to fix any issues or re-run the command and don't make typos.`,
),
],
});
console.log(`Account not found for ${name} in ${serverName} server.`);
return null;
}
}