mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: core chunk 1
This commit is contained in:
1 parent
7447ccc487
commit
e96538bae0
31 files changed
+463
-466
No files matched your search
+87
-91
@@ -1,97 +1,93 @@
|
||||
import { SlashCommandBuilder, escapeMarkdown } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { WARGAMING_APPLICATION_ID } from '../constants/wargamingApplicationID';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse';
|
||||
import { PlayerHistoriesRaw } from '../core/blitzstars/getPlayerHistories';
|
||||
import getTimeDaysAgo from '../core/blitzstars/getTimeDaysAgo';
|
||||
import addClanChoices from '../core/discord/addClanChoices';
|
||||
import autocompleteClan from '../core/discord/autocompleteClan';
|
||||
import embedWarning from '../core/discord/embedWarning';
|
||||
import resolveClanFromCommand from '../core/discord/resolveClanFromCommand';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
import { AccountAchievements } from '../types/accountAchievements';
|
||||
import { AccountInfo } from '../types/accountInfo';
|
||||
import { ClanInfo } from '../types/clanInfo';
|
||||
// _____ _____ _ _ _ _ _____ ____ __ __ ______ ____ _____ _ __
|
||||
// |_ _| / ____| | | | /\ | | | | / ____/ __ \| \/ | ____| | _ \ /\ / ____| |/ /
|
||||
// | | | (___ | |__| | / \ | | | | | | | | | | \ / | |__ | |_) | / \ | | | ' /
|
||||
// | | \___ \| __ | / /\ \ | | | | | | | | | | |\/| | __| | _ < / /\ \| | | <
|
||||
// _| |_ ____) | | | |/ ____ \| |____| |____ | |___| |__| | | | | |____ | |_) / ____ \ |____| . \
|
||||
// |_____| |_____/|_| |_/_/ \_\______|______| \_____\____/|_| |_|______| |____/_/ \_\_____|_|\_\
|
||||
|
||||
export const clanEventCommand: CommandRegistry = {
|
||||
inProduction: false,
|
||||
inPublic: true,
|
||||
// import { SlashCommandBuilder, escapeMarkdown } from 'discord.js';
|
||||
// import markdownEscape from 'markdown-escape';
|
||||
// import { getAccountAchievements } from '../_core/blitz/getAccountAchievements';
|
||||
// import { getAccountInfo } from '../_core/blitz/getAccountInfo';
|
||||
// import { getClanInfo } from '../_core/blitz/getClanInfo';
|
||||
// import { PlayerHistoriesRaw } from '../core/blitzstars/getPlayerHistories';
|
||||
// import getTimeDaysAgo from '../core/blitzstars/getTimeDaysAgo';
|
||||
// import addClanChoices from '../core/discord/addClanChoices';
|
||||
// import autocompleteClan from '../core/discord/autocompleteClan';
|
||||
// import embedWarning from '../core/discord/embedWarning';
|
||||
// import resolveClanFromCommand from '../core/discord/resolveClanFromCommand';
|
||||
// import { CommandRegistry } from '../events/interactionCreate';
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('clan-event')
|
||||
.setDescription('Lists all inactive players')
|
||||
.addStringOption(addClanChoices),
|
||||
// export const clanEventCommand: CommandRegistry = {
|
||||
// inProduction: false,
|
||||
// inPublic: true,
|
||||
|
||||
async handler(interaction) {
|
||||
const { region, id } = await resolveClanFromCommand(interaction);
|
||||
const clan = (
|
||||
await getWargamingResponse<ClanInfo>(
|
||||
`https://api.wotblitz.${region}/wotb/clans/info/?application_id=${WARGAMING_APPLICATION_ID}&clan_id=${id}`,
|
||||
)
|
||||
)[id];
|
||||
const memberIds = clan.members_ids.join(',');
|
||||
const [players, achievements, previousJointVictories] = await Promise.all([
|
||||
getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${region}/wotb/account/info/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${memberIds}`,
|
||||
),
|
||||
getWargamingResponse<AccountAchievements>(
|
||||
`https://api.wotblitz.${region}/wotb/account/achievements/?application_id=${WARGAMING_APPLICATION_ID}&account_id=${memberIds}`,
|
||||
),
|
||||
Promise.all(
|
||||
clan.members_ids.map((id) =>
|
||||
fetch(`https://www.blitzstars.com/api/playerstats/${id}`)
|
||||
.then((response) => response.json() as Promise<PlayerHistoriesRaw>)
|
||||
.then((data) => ({
|
||||
id,
|
||||
jointVictory: data[0]?.achievements.jointVictoryCount as
|
||||
| number
|
||||
| undefined,
|
||||
})),
|
||||
),
|
||||
).then((data) =>
|
||||
data.reduce<Record<number, number | undefined>>(
|
||||
(accumulator, value) => ({
|
||||
...accumulator,
|
||||
[value.id]: value.jointVictory,
|
||||
}),
|
||||
{},
|
||||
),
|
||||
),
|
||||
]);
|
||||
const jointVictories = clan.members_ids.map((id) => ({
|
||||
id,
|
||||
joinVictory:
|
||||
players[id].last_battle_time > getTimeDaysAgo(region, 1)
|
||||
? previousJointVictories[id] === undefined
|
||||
? 0
|
||||
: achievements[id].max_series.jointVictory -
|
||||
previousJointVictories[id]!
|
||||
: 0,
|
||||
}));
|
||||
// command: new SlashCommandBuilder()
|
||||
// .setName('clan-event')
|
||||
// .setDescription('Lists all inactive players')
|
||||
// .addStringOption(addClanChoices),
|
||||
|
||||
return [
|
||||
`# ${escapeMarkdown(clan.name)} [${escapeMarkdown(
|
||||
clan.tag,
|
||||
)}]'s platoon wins today: ${(
|
||||
jointVictories.reduce(
|
||||
(accumulator, { joinVictory }) => accumulator + joinVictory,
|
||||
0,
|
||||
) / 2
|
||||
).toFixed(0)}\n${jointVictories
|
||||
.filter(({ joinVictory }) => joinVictory)
|
||||
.sort((a, b) => b.joinVictory - a.joinVictory)
|
||||
.map(
|
||||
({ id, joinVictory }) =>
|
||||
`- ${markdownEscape(players[id].nickname)}: ${joinVictory}`,
|
||||
)
|
||||
.join('\n')}`,
|
||||
// async handler(interaction) {
|
||||
// const { region, id } = await resolveClanFromCommand(interaction);
|
||||
// const clan = await getClanInfo(region, id);
|
||||
// const [players, achievements, previousJointVictories] = await Promise.all([
|
||||
// getAccountInfo(region, clan.members_ids),
|
||||
// getAccountAchievements(region, clan.members_ids),
|
||||
// Promise.all(
|
||||
// clan.members_ids.map((id) =>
|
||||
// fetch(`https://www.blitzstars.com/api/playerstats/${id}`)
|
||||
// .then((response) => response.json() as Promise<PlayerHistoriesRaw>)
|
||||
// .then((data) => ({
|
||||
// id,
|
||||
// jointVictory: data[0]?.achievements.jointVictoryCount as
|
||||
// | number
|
||||
// | undefined,
|
||||
// })),
|
||||
// ),
|
||||
// ).then((data) =>
|
||||
// data.reduce<Record<number, number | undefined>>(
|
||||
// (accumulator, value) => ({
|
||||
// ...accumulator,
|
||||
// [value.id]: value.jointVictory,
|
||||
// }),
|
||||
// {},
|
||||
// ),
|
||||
// ),
|
||||
// ]);
|
||||
// const jointVictories = clan.members_ids.map((id) => ({
|
||||
// id,
|
||||
// joinVictory:
|
||||
// players[id].last_battle_time > getTimeDaysAgo(region, 1)
|
||||
// ? previousJointVictories[id] === undefined
|
||||
// ? 0
|
||||
// : achievements[id].max_series.jointVictory -
|
||||
// previousJointVictories[id]!
|
||||
// : 0,
|
||||
// }));
|
||||
|
||||
embedWarning(
|
||||
'This is an approximation!',
|
||||
"Wargaming provides very little information about platoons publicly. Caveats:\n- Players in two different clans platooning artificially inflates the total count\n- Game-mode battles aren't counted since Wargaming doesn't publicly share that data\n- This command is also subject to Blitzkrieg's reset times (use `/about timezones` for more info)",
|
||||
),
|
||||
];
|
||||
},
|
||||
// return [
|
||||
// `# ${escapeMarkdown(clan.name)} [${escapeMarkdown(
|
||||
// clan.tag,
|
||||
// )}]'s platoon wins today: ${(
|
||||
// jointVictories.reduce(
|
||||
// (accumulator, { joinVictory }) => accumulator + joinVictory,
|
||||
// 0,
|
||||
// ) / 2
|
||||
// ).toFixed(0)}\n${jointVictories
|
||||
// .filter(({ joinVictory }) => joinVictory)
|
||||
// .sort((a, b) => b.joinVictory - a.joinVictory)
|
||||
// .map(
|
||||
// ({ id, joinVictory }) =>
|
||||
// `- ${markdownEscape(players[id].nickname)}: ${joinVictory}`,
|
||||
// )
|
||||
// .join('\n')}`,
|
||||
|
||||
autocomplete: autocompleteClan,
|
||||
};
|
||||
// embedWarning(
|
||||
// 'This is an approximation!',
|
||||
// "Wargaming provides very little information about platoons publicly. Caveats:\n- Players in two different clans platooning artificially inflates the total count\n- Game-mode battles aren't counted since Wargaming doesn't publicly share that data\n- This command is also subject to Blitzkrieg's reset times (use `/about timezones` for more info)",
|
||||
// ),
|
||||
// ];
|
||||
// },
|
||||
|
||||
// autocomplete: autocompleteClan,
|
||||
// };
|
||||
Reference in new issue
Block a user