feat: removed player acheivements

This commit is contained in:
TrèsAbhi committed 2024-03-08 20:32:06 -06:00
1 parent b3a50f2b27
commit 3181f9c4e7
1 file changed
+73 -66
+73 -66
View File
@@ -1,73 +1,80 @@
import { SlashCommandBuilder } from 'discord.js'; // _____ _____ _ _ _ _ _____ ____ __ __ ______ ____ _____ _ __
import { startCase } from 'lodash'; // |_ _| / ____| | | | /\ | | | | / ____/ __ \| \/ | ____| | _ \ /\ / ____| |/ /
import markdownEscape from 'markdown-escape'; // | | | (___ | |__| | / \ | | | | | | | | | | \ / | |__ | |_) | / \ | | | ' /
import { getAccountAchievements } from '../core/blitz/getAccountAchievements'; // | | \___ \| __ | / /\ \ | | | | | | | | | | |\/| | __| | _ < / /\ \| | | <
import { getAccountInfo } from '../core/blitz/getAccountInfo'; // _| |_ ____) | | | |/ ____ \| |____| |____ | |___| |__| | | | | |____ | |_) / ____ \ |____| . \
import addUsernameChoices from '../core/discord/addUsernameChoices'; // |_____| |_____/|_| |_/_/ \_\______|______| \_____\____/|_| |_|______| |____/_/ \_\_____|_|\_\
import autocompleteUsername from '../core/discord/autocompleteUsername';
import embedInfo from '../core/discord/embedInfo';
import markdownTable, { TableInputEntry } from '../core/discord/markdownTable';
import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
import { CommandRegistry } from '../events/interactionCreate';
type SortBy = 'name' | 'count'; // import { SlashCommandBuilder } from 'discord.js';
// import { startCase } from 'lodash';
// import markdownEscape from 'markdown-escape';
// import { getAccountAchievements } from '../core/blitz/getAccountAchievements';
// import { getAccountInfo } from '../core/blitz/getAccountInfo';
// import addUsernameChoices from '../core/discord/addUsernameChoices';
// import autocompleteUsername from '../core/discord/autocompleteUsername';
// import embedInfo from '../core/discord/embedInfo';
// import markdownTable, { TableInputEntry } from '../core/discord/markdownTable';
// import resolvePlayerFromCommand from '../core/discord/resolvePlayerFromCommand';
// import { CommandRegistry } from '../events/interactionCreate';
export const playerAchievementsCommand = new Promise<CommandRegistry>( // type SortBy = 'name' | 'count';
(resolve) => {
resolve({
inProduction: true,
inPublic: true,
command: new SlashCommandBuilder() // export const playerAchievementsCommand = new Promise<CommandRegistry>(
.setName('player-achievements') // (resolve) => {
.setDescription("All the player's achievements") // resolve({
.addStringOption(addUsernameChoices) // inProduction: true,
.addStringOption((option) => // inPublic: true,
option
.setName('sort')
.setDescription('What to sort by (default: name)')
.addChoices(
{ name: 'By name', value: 'name' satisfies SortBy },
{ name: 'By count', value: 'count' satisfies SortBy },
),
),
async handler(interaction) { // command: new SlashCommandBuilder()
const sortBy = (interaction.options.getString('sort') ?? // .setName('player-achievements')
'name') as SortBy; // .setDescription("All the player's achievements")
const account = await resolvePlayerFromCommand(interaction); // .addStringOption(addUsernameChoices)
const { id, region: region } = account; // .addStringOption((option) =>
const accountInfo = await getAccountInfo(region, id); // option
const accountsAchievements = await getAccountAchievements(region, id); // .setName('sort')
const accountAchievements = accountsAchievements; // .setDescription('What to sort by (default: name)')
const compound = { // .addChoices(
...accountAchievements.achievements, // { name: 'By name', value: 'name' satisfies SortBy },
...accountAchievements.max_series, // { name: 'By count', value: 'count' satisfies SortBy },
}; // ),
// ),
return embedInfo( // async handler(interaction) {
`${markdownEscape(accountInfo.nickname)}'s information`, // const sortBy = (interaction.options.getString('sort') ??
// 'name') as SortBy;
// const account = await resolvePlayerFromCommand(interaction);
// const { id, region: region } = account;
// const accountInfo = await getAccountInfo(region, id);
// const accountsAchievements = await getAccountAchievements(region, id);
// const accountAchievements = accountsAchievements;
// const compound = {
// ...accountAchievements.achievements,
// ...accountAchievements.max_series,
// };
markdownTable( // return embedInfo(
Object.keys(compound) // `${markdownEscape(accountInfo.nickname)}'s information`,
.filter((achievement) => compound[achievement] > 0)
.sort(
sortBy === 'count'
? (a, b) => compound[b] - compound[a]
: undefined,
)
.map(
(achievement) =>
[
startCase(achievement),
compound[achievement],
] as TableInputEntry,
),
),
);
},
autocomplete: autocompleteUsername, // markdownTable(
}); // Object.keys(compound)
}, // .filter((achievement) => compound[achievement] > 0)
); // .sort(
// sortBy === 'count'
// ? (a, b) => compound[b] - compound[a]
// : undefined,
// )
// .map(
// (achievement) =>
// [
// startCase(achievement),
// compound[achievement],
// ] as TableInputEntry,
// ),
// ),
// );
// },
// autocomplete: autocompleteUsername,
// });
// },
// );