mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
feat: lenient username and clan lookup
This commit is contained in:
1 parent
9df4d52bb5
commit
9a9ea3a71a
19 files changed
+292
-209
No files matched your search
@@ -11,7 +11,7 @@ const executionStart = new Date().getTime();
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
|
||||
@@ -4,7 +4,7 @@ import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
||||
import { BlitzServer } from '../constants/servers.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import validateUsername from '../core/blitz/validateUsername.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import blitzStarsLinks from '../core/blitzstars/blitzStarsLinks.js';
|
||||
import getBlitzStarsAccount from '../core/blitzstars/getBlitzStarsAccount.js';
|
||||
import poweredByBlitzStars from '../core/blitzstars/poweredByBlitzStars.js';
|
||||
@@ -19,7 +19,7 @@ const CLANS = {
|
||||
|
||||
export default {
|
||||
inProduction: false,
|
||||
inDevelopment: true,
|
||||
inDevelopment: false,
|
||||
inPublic: false,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
@@ -42,7 +42,7 @@ export default {
|
||||
const clan = interaction.options.getString('clan') as keyof typeof CLANS;
|
||||
const name = interaction.options.getString('username')!;
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
const blitzAccount = await validateUsername(interaction, name, server);
|
||||
const blitzAccount = await getBlitzAccount(interaction, name, server);
|
||||
|
||||
if (!blitzAccount) return;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import { client } from '../index.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
|
||||
+14
-20
@@ -2,33 +2,26 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
||||
import { BlitzServer } from '../constants/servers.js';
|
||||
import getClan from '../core/blitz/getClan.js';
|
||||
import clanAutocomplete from '../core/autocomplete/clan.js';
|
||||
import getBlitzClan from '../core/blitz/getBlitzClan.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import addServerChoices from '../core/options/addServerChoices.js';
|
||||
import addClanOption from '../core/options/addClanOption.js';
|
||||
import { args } from '../core/process/args.js';
|
||||
import { AccountInfo } from '../types/accountInfo.js';
|
||||
import { ClanInfo } from '../types/clanInfo.js';
|
||||
import { Clan } from '../types/clanList.js';
|
||||
|
||||
const DEFAULT_THRESHOLD = 7;
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
.setName(cmdName('inactive'))
|
||||
.setDescription('Lists all inactive players')
|
||||
.addStringOption(addServerChoices)
|
||||
.addStringOption((option) =>
|
||||
option
|
||||
.setName('clan')
|
||||
.setDescription('The clan name or tag you are checking')
|
||||
.setRequired(true),
|
||||
)
|
||||
.addStringOption(addClanOption)
|
||||
.addNumberOption((option) =>
|
||||
option
|
||||
.setName('threshold')
|
||||
@@ -40,19 +33,18 @@ export default {
|
||||
|
||||
async execute(interaction) {
|
||||
const clanName = interaction.options.getString('clan')!;
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
|
||||
const clan = (await getClan(interaction, clanName, server)) as Clan;
|
||||
const clan = await getBlitzClan(interaction, clanName);
|
||||
if (!clan) return;
|
||||
const { server, id } = clan;
|
||||
|
||||
const threshold =
|
||||
interaction.options.getNumber('threshold')! ?? DEFAULT_THRESHOLD;
|
||||
const time = new Date().getTime() / 1000;
|
||||
const clanInfo = await getWargamingResponse<ClanInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/info/?application_id=${args['wargaming-application-id']}&clan_id=${clan.clan_id}`,
|
||||
`https://api.wotblitz.${server}/wotb/clans/info/?application_id=${args['wargaming-application-id']}&clan_id=${id}`,
|
||||
);
|
||||
if (!clanInfo) return;
|
||||
const memberIds = clanInfo[clan.clan_id].members_ids;
|
||||
const memberIds = clanInfo[id].members_ids;
|
||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${
|
||||
args['wargaming-application-id']
|
||||
@@ -82,8 +74,8 @@ export default {
|
||||
.setColor(hasInactiveMembers ? NEGATIVE_COLOR : POSITIVE_COLOR)
|
||||
.setTitle(
|
||||
hasInactiveMembers
|
||||
? `${markdownEscape(clan.name)}'s inactive members`
|
||||
: `No inactive members in ${markdownEscape(clan.name)}`,
|
||||
? `${markdownEscape(clanInfo[id].name)}'s inactive members`
|
||||
: `No inactive members in ${markdownEscape(clanInfo[id].name)}`,
|
||||
)
|
||||
.setDescription(
|
||||
hasInactiveMembers
|
||||
@@ -96,7 +88,9 @@ export default {
|
||||
});
|
||||
|
||||
console.log(
|
||||
`Displaying inactive members in ${clan.name} for ${threshold} days`,
|
||||
`Displaying inactive members in ${clanInfo[id].name} for ${threshold} days`,
|
||||
);
|
||||
},
|
||||
|
||||
autocomplete: clanAutocomplete,
|
||||
} satisfies CommandRegistry;
|
||||
@@ -7,10 +7,10 @@ import cmdName from '../core/interaction/cmdName.js';
|
||||
import addServerChoices from '../core/options/addServerChoices.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { args } from '../core/process/args.js';
|
||||
import { AccountList } from '../types/players.js';
|
||||
import { AccountList } from '../types/accountList.js';
|
||||
|
||||
export default {
|
||||
inDevelopment: true,
|
||||
inDevelopment: false,
|
||||
inProduction: true,
|
||||
inPublic: true,
|
||||
|
||||
@@ -47,9 +47,7 @@ export default {
|
||||
`\`\`\`${
|
||||
players.length === 0
|
||||
? 'No players found.'
|
||||
: players
|
||||
.map((player) => markdownEscape(player.nickname))
|
||||
.join('\n')
|
||||
: players.map((player) => player.nickname).join('\n')
|
||||
}\`\`\``,
|
||||
),
|
||||
],
|
||||
|
||||
+13
-25
@@ -2,16 +2,14 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { SKILLED_COLOR } from '../constants/colors.js';
|
||||
import { BlitzServer } from '../constants/servers.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import validateUsername from '../core/blitz/validateUsername.js';
|
||||
import blitzStarsLinks from '../core/blitzstars/blitzStarsLinks.js';
|
||||
import getBlitzStarsAccount from '../core/blitzstars/getBlitzStarsAccount.js';
|
||||
import poweredByBlitzStars from '../core/blitzstars/poweredByBlitzStars.js';
|
||||
import cleanTable from '../core/interaction/cleanTable.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import addServerChoices from '../core/options/addServerChoices.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { args } from '../core/process/args.js';
|
||||
import { AccountInfo, AllStats } from '../types/accountInfo.js';
|
||||
@@ -21,7 +19,7 @@ type Period = 'today' | '30' | '90' | 'career';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
@@ -39,29 +37,25 @@ export default {
|
||||
)
|
||||
.setRequired(true),
|
||||
)
|
||||
.addStringOption(addServerChoices)
|
||||
.addStringOption(addUsernameOption),
|
||||
|
||||
async execute(interaction) {
|
||||
const period = interaction.options.getString('period') as Period;
|
||||
const username = interaction.options.getString('username')!;
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
const blitzAccount = await validateUsername(interaction, username, server);
|
||||
const blitzAccount = await getBlitzAccount(interaction, username);
|
||||
if (!blitzAccount) return;
|
||||
const { id, server } = blitzAccount;
|
||||
let stats: BlitzStartsComputedPeriodicStatistics;
|
||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${blitzAccount.account_id}`,
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
if (!accountInfo) return;
|
||||
const blitzStarsAccount = await getBlitzStarsAccount(
|
||||
interaction,
|
||||
blitzAccount.account_id,
|
||||
);
|
||||
const blitzStarsAccount = await getBlitzStarsAccount(interaction, id);
|
||||
if (!blitzStarsAccount) return;
|
||||
|
||||
if (period === 'today') {
|
||||
const a1 = blitzStarsAccount.statistics;
|
||||
const a2 = accountInfo[blitzAccount.account_id].statistics;
|
||||
const a2 = accountInfo[id].statistics;
|
||||
const battles = a2.all.battles - a1.all.battles;
|
||||
|
||||
function pb(value: (allStats: AllStats) => number) {
|
||||
@@ -70,14 +64,6 @@ export default {
|
||||
function diff(value: (allStats: AllStats) => number) {
|
||||
return value(a2.all) - value(a1.all);
|
||||
}
|
||||
function span(
|
||||
value1: (allStats: AllStats) => number,
|
||||
value2: (allStats: AllStats) => number,
|
||||
) {
|
||||
return (
|
||||
(value1(a2.all) - value1(a1.all)) / (value2(a2.all) - value2(a1.all))
|
||||
);
|
||||
}
|
||||
|
||||
stats = {
|
||||
all: {
|
||||
@@ -119,8 +105,10 @@ export default {
|
||||
new EmbedBuilder()
|
||||
.setColor(SKILLED_COLOR)
|
||||
.setTitle(
|
||||
`${markdownEscape(blitzAccount.nickname)}'s ${
|
||||
period === 'career' ? period : `${period} day`
|
||||
`${markdownEscape(blitzStarsAccount.nickname)}'s ${
|
||||
period === 'career'
|
||||
? period
|
||||
: `${period === 'today' ? 'today' : `${period} day`}`
|
||||
} stats`,
|
||||
)
|
||||
.setDescription(
|
||||
@@ -195,14 +183,14 @@ export default {
|
||||
(stats.all.battles - stats.all.survived_battles)
|
||||
).toFixed(2),
|
||||
],
|
||||
])}\n\n${blitzStarsLinks(server, blitzAccount.nickname)}`
|
||||
])}\n\n${blitzStarsLinks(server, blitzStarsAccount.nickname)}`
|
||||
: 'No battles played in this period.',
|
||||
),
|
||||
),
|
||||
],
|
||||
});
|
||||
|
||||
console.log(`Showing stats for ${blitzAccount.nickname}`);
|
||||
console.log(`Showing stats for ${blitzStarsAccount.nickname}`);
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
|
||||
+15
-11
@@ -2,15 +2,14 @@ import { EmbedBuilder, SlashCommandBuilder } from 'discord.js';
|
||||
import markdownEscape from 'markdown-escape';
|
||||
import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { SKILLED_COLOR } from '../constants/colors.js';
|
||||
import { BlitzServer } from '../constants/servers.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import validateUsername from '../core/blitz/validateUsername.js';
|
||||
import { TANK_TYPE_EMOJIS, tankopedia } from '../core/blitzstars/tankopedia.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import addServerChoices from '../core/options/addServerChoices.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
import { args } from '../core/process/args.js';
|
||||
import { AccountInfo } from '../types/accountInfo.js';
|
||||
import { TanksStats } from '../types/tanksStats.js';
|
||||
import resolveTankName from '../utilities/resolveTankName.js';
|
||||
|
||||
@@ -37,7 +36,7 @@ const COMP_TANKS = [
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
@@ -51,20 +50,23 @@ export default {
|
||||
.setMaxValue(10)
|
||||
.setRequired(true),
|
||||
)
|
||||
.addStringOption(addServerChoices)
|
||||
.addStringOption(addUsernameOption),
|
||||
|
||||
async execute(interaction) {
|
||||
const tier = interaction.options.getInteger('tier')!;
|
||||
const name = interaction.options.getString('username')!;
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
const account = await validateUsername(interaction, name, server);
|
||||
const account = await getBlitzAccount(interaction, name);
|
||||
if (!account) return;
|
||||
const { id, server } = account;
|
||||
const accountInfo = await getWargamingResponse<AccountInfo>(
|
||||
`https://api.wotblitz.${server}/wotb/account/info/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
if (!accountInfo) return;
|
||||
const tankStats = await getWargamingResponse<TanksStats>(
|
||||
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${account.account_id}`,
|
||||
`https://api.wotblitz.${server}/wotb/tanks/stats/?application_id=${args['wargaming-application-id']}&account_id=${id}`,
|
||||
);
|
||||
if (!tankStats) return;
|
||||
const tanks = tankStats[account.account_id]
|
||||
const tanks = tankStats[id]
|
||||
.map((tankData) => tankopedia.data[tankData.tank_id])
|
||||
.filter((tank) => tank.tier === tier);
|
||||
|
||||
@@ -72,7 +74,7 @@ export default {
|
||||
embeds: [
|
||||
new EmbedBuilder()
|
||||
.setTitle(
|
||||
`${markdownEscape(account.nickname)}'s owned ${
|
||||
`${markdownEscape(accountInfo[id].nickname)}'s owned ${
|
||||
tier === null ? '' : `tier ${tier} `
|
||||
}tanks`,
|
||||
)
|
||||
@@ -102,7 +104,9 @@ export default {
|
||||
],
|
||||
});
|
||||
|
||||
console.log(`Displaying ${account.nickname}'s owned tanks in tier ${tier}`);
|
||||
console.log(
|
||||
`Displaying ${accountInfo[id].nickname}'s owned tanks in tier ${tier}`,
|
||||
);
|
||||
},
|
||||
|
||||
autocomplete: usernameAutocomplete,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { BlitzServer } from '../constants/servers.js';
|
||||
import tanksAutocomplete from '../core/autocomplete/tanks.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import validateUsername from '../core/blitz/validateUsername.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import { tankopedia } from '../core/blitzstars/tankopedia.js';
|
||||
import getPeriodicStats, {
|
||||
Period,
|
||||
@@ -22,7 +22,7 @@ type Periods = '30' | '60' | '90';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
@@ -48,7 +48,7 @@ export default {
|
||||
const name = interaction.options.getString('username')!;
|
||||
const tankId = interaction.options.getString('tank')!;
|
||||
const period = interaction.options.getString('period') as Periods;
|
||||
const blitzAccount = await validateUsername(interaction, name, server);
|
||||
const blitzAccount = await getBlitzAccount(interaction, name, server);
|
||||
if (!blitzAccount) return;
|
||||
const tank = tankopedia.data[tankId as unknown as number];
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import { CommandRegistry } from '../behaviors/interactionCreate.js';
|
||||
import { NEGATIVE_COLOR, POSITIVE_COLOR } from '../constants/colors.js';
|
||||
import { BlitzServer } from '../constants/servers.js';
|
||||
import usernameAutocomplete from '../core/autocomplete/username.js';
|
||||
import getBlitzAccount from '../core/blitz/getBlitzAccount.js';
|
||||
import getWargamingResponse from '../core/blitz/getWargamingResponse.js';
|
||||
import validateUsername from '../core/blitz/validateUsername.js';
|
||||
import cmdName from '../core/interaction/cmdName.js';
|
||||
import addServerChoices from '../core/options/addServerChoices.js';
|
||||
import addUsernameOption from '../core/options/addUsernameOption.js';
|
||||
@@ -15,7 +15,7 @@ import { PlayerClanData } from '../types/playerClanData.js';
|
||||
|
||||
export default {
|
||||
inProduction: true,
|
||||
inDevelopment: true,
|
||||
inDevelopment: false,
|
||||
inPublic: true,
|
||||
|
||||
command: new SlashCommandBuilder()
|
||||
@@ -27,7 +27,7 @@ export default {
|
||||
async execute(interaction) {
|
||||
const name = interaction.options.getString('username')!;
|
||||
const server = interaction.options.getString('server') as BlitzServer;
|
||||
const account = await validateUsername(interaction, name, server);
|
||||
const account = await getBlitzAccount(interaction, name, server);
|
||||
if (!account) return;
|
||||
const clanData = await getWargamingResponse<PlayerClanData>(
|
||||
`https://api.wotblitz.${server}/wotb/clans/accountinfo/?application_id=${args['wargaming-application-id']}&account_id=${account.account_id}&extra=clan`,
|
||||
|
||||
Reference in new issue
Block a user