mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 10:47:04 +02:00
feat: re-added manual username entry
This commit is contained in:
1 parent
be644bb3d9
commit
f965452c5d
1 file changed
+38
-7
@@ -1,5 +1,7 @@
|
||||
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { Region } from '../../constants/regions';
|
||||
import listPlayers from '../blitz/listPlayers';
|
||||
import { getBlitzFromDiscord } from '../cockroackdb/discordBlitz';
|
||||
import throwError from '../node/throwError';
|
||||
|
||||
@@ -13,14 +15,43 @@ export interface ResolvedPlayer {
|
||||
export default async function resolvePlayerFromCommand(
|
||||
interaction: ChatInputCommandInteraction<CacheType>,
|
||||
) {
|
||||
const account = await getBlitzFromDiscord(parseInt(interaction.user.id));
|
||||
const commandUsername = interaction.options.getString('username');
|
||||
|
||||
if (account) {
|
||||
return { region: account.region, id: account.blitz };
|
||||
if (commandUsername) {
|
||||
if (serverAndIdPattern.test(commandUsername)) {
|
||||
const [server, accountId] = commandUsername.split('/');
|
||||
|
||||
return {
|
||||
region: server as Region,
|
||||
id: Number(accountId),
|
||||
} satisfies ResolvedPlayer;
|
||||
} else {
|
||||
const accounts = await listPlayers(commandUsername);
|
||||
|
||||
if (accounts[0]) {
|
||||
return {
|
||||
region: accounts[0].region,
|
||||
id: accounts[0].account_id,
|
||||
} satisfies ResolvedPlayer;
|
||||
} else {
|
||||
throw throwError(
|
||||
'Could not find user',
|
||||
`I couldn't find user "${markdownEscape(
|
||||
commandUsername,
|
||||
)}". Try picking an user from the search result, typing in a valid username, or using the \`/link\` command.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw throwError(
|
||||
"You're not linked",
|
||||
'Use the `/link` command to link your Discord and Blitz accounts.',
|
||||
);
|
||||
const account = await getBlitzFromDiscord(parseInt(interaction.user.id));
|
||||
|
||||
if (account) {
|
||||
return { region: account.region, id: account.blitz };
|
||||
} else {
|
||||
throw throwError(
|
||||
"You're not linked",
|
||||
'Use the `/link` command to link your Discord and Blitz accounts.',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user