mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 18:57:03 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5bab8a698 |
No files matched your search
@@ -0,0 +1,7 @@
|
||||
# Blitzkrieg 1.12.4
|
||||
|
||||
Added very badly-coded temporary `/clan-event` command (without linting)
|
||||
|
||||
## Changes
|
||||
|
||||
- Added `/clan-event` command
|
||||
@@ -0,0 +1,107 @@
|
||||
import { SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import autocompleteClan from '../core/discord/autocompleteClan';
|
||||
import embedInfo from '../core/discord/embedInfo';
|
||||
import { secrets } from '../core/node/secrets';
|
||||
import { CommandRegistry } from '../events/interactionCreate';
|
||||
|
||||
const DEFAULT_THRESHOLD = 7;
|
||||
|
||||
export const clanEventCommand: CommandRegistry = {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName('clan-event')
|
||||
.setDescription('Lists all inactive players')
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('clan')
|
||||
.setDescription('The clan name or tag you are checking')
|
||||
.setRequired(true),
|
||||
),
|
||||
|
||||
async handler(interaction) {
|
||||
const REGION = 'com';
|
||||
const CLAN_SEARCH = interaction.options.getString('clan', true);
|
||||
|
||||
const {
|
||||
clan_id,
|
||||
name: clan_name,
|
||||
tag: clan_tag,
|
||||
} = await fetch(
|
||||
`https://api.wotblitz.${REGION}/wotb/clans/list/?application_id=${secrets.WARGAMING_APPLICATION_ID}&search=${CLAN_SEARCH}`,
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then(({ data }) => data[0]);
|
||||
const memebers = await fetch(
|
||||
`https://api.wotblitz.${REGION}/wotb/clans/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&clan_id=${clan_id}`,
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then(({ data }) => data[clan_id].members_ids);
|
||||
const stats = await Promise.all(
|
||||
memebers.map(async (id, index) => {
|
||||
await new Promise((resolve) => setTimeout(resolve, index * 200));
|
||||
|
||||
const [yesterdayPlatoonWins, name, todayPlatoonWins] =
|
||||
await Promise.all([
|
||||
fetch(`https://www.blitzstars.com/api/playerstats/${id}`)
|
||||
.then((response) => response.json())
|
||||
.then((data) => data[0]?.achievements.jointVictoryCount),
|
||||
fetch(
|
||||
`https://api.wotblitz.${REGION}/wotb/account/info/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then(({ data }) => data[id].nickname),
|
||||
fetch(
|
||||
`https://api.wotblitz.${REGION}/wotb/account/achievements/?application_id=${secrets.WARGAMING_APPLICATION_ID}&account_id=${id}`,
|
||||
)
|
||||
.then((response) => response.json())
|
||||
.then(({ data }) => data[id].max_series.jointVictory),
|
||||
]);
|
||||
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
yesterdayPlatoonWins,
|
||||
todayPlatoonWins,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
return embedInfo(
|
||||
`Estimation of ${clan_name} [${clan_tag}]'s total platoon wins today: ${(
|
||||
stats.reduce(
|
||||
(accumulator, player) =>
|
||||
accumulator +
|
||||
(player.yesterdayPlatoonWins === undefined
|
||||
? 0
|
||||
: player.todayPlatoonWins - player.yesterdayPlatoonWins),
|
||||
0,
|
||||
) / 2
|
||||
).toFixed(0)}`,
|
||||
stats
|
||||
.sort(
|
||||
(playerA, playerB) =>
|
||||
(playerB.yesterdayPlatoonWins === undefined
|
||||
? 0
|
||||
: playerB.todayPlatoonWins - playerB.yesterdayPlatoonWins) -
|
||||
(playerA.yesterdayPlatoonWins === undefined
|
||||
? 0
|
||||
: playerA.todayPlatoonWins - playerA.yesterdayPlatoonWins),
|
||||
)
|
||||
.map(
|
||||
(player) =>
|
||||
`${markdownEscape(player.name)}: ${
|
||||
player.yesterdayPlatoonWins === undefined
|
||||
? 0
|
||||
: player.todayPlatoonWins - player.yesterdayPlatoonWins
|
||||
}`,
|
||||
)
|
||||
.join('\n'),
|
||||
);
|
||||
},
|
||||
|
||||
autocomplete: autocompleteClan,
|
||||
};
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
SlashCommandSubcommandsOnlyBuilder,
|
||||
} from 'discord.js';
|
||||
import discord from '../../../discord.json' assert { type: 'json' };
|
||||
import { clanEventCommand } from '../../commands/clanEvent';
|
||||
import { debugCommand } from '../../commands/debug';
|
||||
import { eligibleCommand } from '../../commands/eligible';
|
||||
import { evolutionCommand } from '../../commands/evolution';
|
||||
@@ -99,6 +100,7 @@ export const COMMANDS_RAW: CommandRegistry[] = [
|
||||
evolutionCommand,
|
||||
statsCommand,
|
||||
ratingsCommand,
|
||||
clanEventCommand,
|
||||
];
|
||||
|
||||
export const commands = Promise.all(COMMANDS_RAW).then((rawCommands) =>
|
||||
|
||||
+1
-1
@@ -11,5 +11,5 @@
|
||||
"resolveJsonModule": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": ["src/**/*.ts", "src/components/Tanks/components/Row.tsx"]
|
||||
"include": ["src/**/*.ts", "src/components/Tanks/components/Row.tsx", "src/commands/clanEvent.ts"]
|
||||
}
|
||||
Reference in new issue
Block a user