feat: added player list api

This commit is contained in:
TresAbhi committed 2023-09-18 23:05:19 +00:00
1 parent 33b4ea04b4
commit cbeb83d8d0
7 files changed
+57 -17

No files matched your search

+11 -7
View File
@@ -1,10 +1,14 @@
import { Region } from '../../constants/regions';
import { Account, AccountList } from '../../types/accountList';
import { secrets } from '../node/secrets';
import getWargamingResponse from './getWargamingResponse';
interface Account {
nickname: string;
account_id: number;
}
type AccountList = Account[];
export type AccountListWithServer = (Account & {
server: 'com' | 'eu' | 'asia';
region: Region;
})[];
export const usernamePattern = /^[a-zA-Z0-9_]{3,24}$/;
@@ -25,7 +29,7 @@ export default async function listPlayers(search: string, limit = 9) {
value &&
value.map((account) => ({
...account,
server: 'com' as Region,
region: 'com' as Region,
})),
),
getWargamingResponse<AccountList>(
@@ -35,7 +39,7 @@ export default async function listPlayers(search: string, limit = 9) {
value &&
value.map((account) => ({
...account,
server: 'eu' as Region,
region: 'eu' as Region,
})),
),
getWargamingResponse<AccountList>(
@@ -45,14 +49,14 @@ export default async function listPlayers(search: string, limit = 9) {
value &&
value.map((account) => ({
...account,
server: 'asia' as Region,
region: 'asia' as Region,
})),
),
])
)
.filter(Boolean)
.flat();
.flat() as AccountListWithServer;
} else {
return [];
return [] as AccountListWithServer;
}
}
+2 -2
View File
@@ -19,8 +19,8 @@ export default async function autocompleteUsername(
? players.map(
(player) =>
({
name: `${player.nickname} (${REGION_NAMES[player.server]})`,
value: `${player.server}/${player.account_id}`,
name: `${player.nickname} (${REGION_NAMES[player.region]})`,
value: `${player.region}/${player.account_id}`,
}) satisfies ApplicationCommandOptionChoiceData<string>,
)
: [],
+1 -1
View File
@@ -39,7 +39,7 @@ export default async function resolvePlayerFromCommand(
if (accounts[0]) {
return {
region: accounts[0].server,
region: accounts[0].region,
id: accounts[0].account_id,
} satisfies ResolvedPlayer;
} else {