feat: extracted renderer from /stats

This commit is contained in:
TresAbhi committed 2023-06-23 01:35:15 +00:00
1 parent bcbc1e259f
commit 752f9b339b
21 files changed
+329 -273

No files matched your search

-41
View File
@@ -1,41 +0,0 @@
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
import { BlitzServer } from '../../constants/servers.js';
import errorWithCause from '../process/errorWithCause.js';
import listAccountsPanServer, {
usernamePatternWithoutPosition,
} from './listAccountsPanServer.js';
export const serverAndIdPattern = /(com|eu|asia)\/[0-9]+/;
export default async function getBlitzAccount(
interaction: ChatInputCommandInteraction<CacheType>,
) {
const commandUsername = interaction.options.getString('username');
const displayName = interaction.guild?.members.cache
.get(interaction.user.id)
?.displayName.match(usernamePatternWithoutPosition)?.[0];
const username = commandUsername ?? displayName;
if (username === undefined) {
throw errorWithCause(
'Username could not be inferred',
"You didn't provide me a username in the command nor was I able to infer your Blitz username from your Discord nickname. Try providing a username manually in the command or using the `/verify` command to set your Discord nickname to your Blitz username.",
);
}
if (serverAndIdPattern.test(username)) {
const [server, accountId] = username.split('/');
return { server: server as BlitzServer, id: Number(accountId) };
} else {
const accounts = await listAccountsPanServer(username);
if (accounts[0]) {
return { server: accounts[0].server, id: accounts[0].account_id };
} else {
throw errorWithCause(
'Could not find user',
`I couldn't find user \`${username}\`. Try providing a valid username manually or using the \`/verify\` command to set your Discord nickname to your Blitz username.`,
);
}
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
import { CacheType, ChatInputCommandInteraction } from 'discord.js';
import { BlitzServer } from '../../constants/servers.js';
import { serverAndIdPattern } from '../options/resolvePlayer.js';
import errorWithCause from '../process/errorWithCause.js';
import { serverAndIdPattern } from './getBlitzAccount.js';
import listClansPanServer from './listClansPanServer.js';
export default async function getBlitzClan(