feat: new eligible format

This commit is contained in:
TresAbhi committed 2023-04-23 00:50:46 +00:00
1 parent cda843003c
commit b4ae5c045a
1 file changed
+80 -67
+80 -67
View File
@@ -11,6 +11,11 @@ import getBlitzAccount from '../utilities/getBlitzAccount.js';
import getBlitzStarsAccount from '../utilities/getBlitzStarsAccount.js';
import poweredByBlitzStars from '../utilities/poweredByBlitzStars.js';
export const CLANS = {
sklld: 'Skilled',
smri: 'Samurai',
};
export async function execute(
interaction: ChatInputCommandInteraction<CacheType>,
) {
@@ -18,93 +23,91 @@ export async function execute(
const server = interaction.options.getString(
'server',
) as keyof typeof SERVERS;
const clan = interaction.options.getString('clan') as keyof typeof CLANS;
getBlitzAccount(interaction, ign, server, async (account) => {
getBlitzStarsAccount(interaction, account.account_id, ign, async (data) => {
const sklldIssues: string[] = [];
const smriIssues: string[] = [];
const issues: string[] = [];
if (data.period30d.all.battles < 150) {
sklldIssues.push(
`**Battles**: ${data.period30d.all.battles} (${
data.period30d.all.battles - 150
})`,
);
}
if (data.period30d.avg_tier < 8) {
sklldIssues.push(
`**Tier**: ${data.period30d.avg_tier.toFixed(2)} (${(
data.period30d.avg_tier - 8
).toFixed(2)})`,
);
}
if (data.period30d.special.winrate < 60) {
sklldIssues.push(
`**Winrate**: ${data.period30d.special.winrate.toFixed(2)}% (${(
data.period30d.special.winrate - 60
).toFixed(2)}%)`,
);
}
if (data.period30d.wn8 < 2100) {
sklldIssues.push(
`**WN8**: ${data.period30d.wn8.toFixed(0)} (${(
data.period30d.wn8 - 2100
).toFixed(0)})`,
);
}
if (data.period30d.special.dpb < 2400) {
sklldIssues.push(
`**Damage per battle**: ${data.period30d.special.dpb.toFixed(0)} (${(
data.period30d.special.dpb - 2400
).toFixed(0)})`,
);
if (clan === 'sklld') {
if (data.period30d.all.battles < 150) {
issues.push(
`**Battles**: ${data.period30d.all.battles} (${
data.period30d.all.battles - 150
})`,
);
}
if (data.period30d.avg_tier < 8) {
issues.push(
`**Tier**: ${data.period30d.avg_tier.toFixed(2)} (${(
data.period30d.avg_tier - 8
).toFixed(2)})`,
);
}
if (data.period30d.special.winrate < 60) {
issues.push(
`**Winrate**: ${data.period30d.special.winrate.toFixed(2)}% (${(
data.period30d.special.winrate - 60
).toFixed(2)}%)`,
);
}
if (data.period30d.wn8 < 2100) {
issues.push(
`**WN8**: ${data.period30d.wn8.toFixed(0)} (${(
data.period30d.wn8 - 2100
).toFixed(0)})`,
);
}
if (data.period30d.special.dpb < 2400) {
issues.push(
`**Damage per battle**: ${data.period30d.special.dpb.toFixed(
0,
)} (${(data.period30d.special.dpb - 2400).toFixed(0)})`,
);
}
} else {
if (data.statistics.all.battles < 1500) {
issues.push(
`**Battles**: ${data.statistics.all.battles} (${
data.statistics.all.battles - 1500
})`,
);
}
if (data.statistics.special.winrate < 53) {
issues.push(
`**Winrate**: ${data.statistics.special.winrate.toFixed(2)}% (${(
data.statistics.special.winrate - 53
).toFixed(2)}%)`,
);
}
}
if (data.statistics.all.battles < 1500) {
smriIssues.push(
`**Battles**: ${data.statistics.all.battles} (${
data.statistics.all.battles - 1500
})`,
);
}
if (data.statistics.special.winrate < 53) {
smriIssues.push(
`**Winrate**: ${data.statistics.special.winrate.toFixed(2)}% (${(
data.statistics.special.winrate - 53
).toFixed(2)}%)`,
);
}
const eligible = issues.length === 0;
await interaction.reply({
embeds: [
poweredByBlitzStars(
new EmbedBuilder()
.setTitle(`${data.nickname}'s eligibility for Skilled clans`)
.setColor(
sklldIssues.length === 0 || smriIssues.length === 0
? POSITIVE_COLOR
: NEGATIVE_COLOR,
.setTitle(
`${data.nickname} is ${eligible ? '' : 'not '}eligible for ${
CLANS[clan]
}`,
)
.setColor(eligible ? POSITIVE_COLOR : NEGATIVE_COLOR)
.setDescription(
`${
sklldIssues.length === 0
? '**✅ Player is eligible for `[SKLLD]`**'
: `**❌ \`[SKLLD] short by (30 days):\`**\n${sklldIssues.join(
'\n',
)}`
}\n\n${
smriIssues.length === 0
? '**✅ Player is eligible for `[SMRI]`**'
: `**❌ \`[SMRI] short by (career):\`**\n${smriIssues.join(
'\n',
)}`
eligible
? `${data.nickname} meets all the requirements set for ${CLANS[clan]}.`
: `${data.nickname}'s shortcomings for ${CLANS[clan]} (${
clan === 'sklld' ? '30 days stats' : 'career stats'
}):\n\n${issues.join('\n')}`
}\n\n${blitzLinks(data)}`,
),
),
],
});
console.log(`Showing ${data.nickname}'s eligibility for Skilled clans`);
console.log(`Showing ${data.nickname}'s eligibility for ${CLANS[clan]}`);
});
});
}
@@ -112,6 +115,16 @@ export async function execute(
export const data = new SlashCommandBuilder()
.setName('eligible')
.setDescription("Gets the user's eligibility for Skilled clans")
.addStringOption((option) =>
option
.setName('clan')
.setDescription('The Skilled clan you are checking')
.addChoices(
{ name: CLANS.sklld, value: 'sklld' },
{ name: CLANS.smri, value: 'smri' },
)
.setRequired(true),
)
.addStringOption((option) =>
option
.setName('server')