feat(utils): don't asks for grinders if rewards are disabled
Some checks failed
Build and Push Docker Image / build (push) Failing after 18s

This commit is contained in:
Pihkaal
2025-12-21 11:49:48 +01:00
parent d3561c019d
commit 1cbd752977

View File

@@ -12,97 +12,101 @@ export const askForGrinders = async (quest: QuestResult, client: Client) => {
return questLogger.fatal("Invalid 'DISCORD_ADMIN_CHANNEL'");
}
const top10 = quest.participants
.filter((x) => !env.QUEST_EXCLUDE.includes(x.username))
.sort((a, b) => b.xp - a.xp)
.slice(0, 10)
.map((p, i) => `${i + 1}. ${p.username} - ${p.xp}xp`)
.join("\n");
let exclude: string[] = [];
if (env.QUEST_REWARDS) {
const top10 = quest.participants
.filter((x) => !env.QUEST_EXCLUDE.includes(x.username))
.sort((a, b) => b.xp - a.xp)
.slice(0, 10)
.map((p, i) => `${i + 1}. ${p.username} - ${p.xp}xp`)
.join("\n");
const color = parseInt(quest.quest.promoImagePrimaryColor.substring(1), 16);
const color = parseInt(quest.quest.promoImagePrimaryColor.substring(1), 16);
await adminChannel.send({
content: `-# ||${env.DISCORD_ADMIN_MENTION}||`,
embeds: [
{
title: "Quête terminée !",
color,
},
{
title: "Top 10 XP",
description: top10,
color,
},
{
title: "Qui a grind ?",
description:
"Merci d'entrer les pseudos des joueurs qui ont grind.\n\nFormat:```@LBF laulau,Yuno,...```\n**Attention les majuscules comptent**\nPour entrer la liste des joueurs, il faut __mentionner le bot__, si personne n'a grind, `@LBF tg`",
color,
},
],
});
const filter = (msg: Message) =>
msg.channel.id === adminChannel.id &&
!msg.author.bot &&
msg.content.startsWith(`<@${client.user!.id}>`);
let confirmed = false;
let answer: string | null = null;
while (!confirmed) {
const collected = await adminChannel.awaitMessages({ filter, max: 1 });
answer = collected.first()?.content || null;
if (!answer) continue;
answer = answer.replace(`<@${client.user!.id}>`, "").trim();
if (answer.toLowerCase() === "tg") {
answer = "";
break;
}
const players = answer
.split(",")
.map((x) => x.trim())
.filter(Boolean);
await adminChannel.send({
content: `-# ||${env.DISCORD_ADMIN_MENTION}||`,
embeds: [
{
title: "Joueurs entrés",
description: players.length
? players.map((name) => `- ${name}`).join("\n")
: "*Aucun joueur entré*",
title: "Quête terminée !",
color,
},
{
title: "Top 10 XP",
description: top10,
color,
},
{
title: "Qui a grind ?",
description:
"Merci d'entrer les pseudos des joueurs qui ont grind.\n\nFormat:```@LBF laulau,Yuno,...```\n**Attention les majuscules comptent**\nPour entrer la liste des joueurs, il faut __mentionner le bot__, si personne n'a grind, `@LBF tg`",
color,
},
],
content: `Est-ce correct ? (oui/non)`,
});
const confirmFilter = (msg: Message) =>
const filter = (msg: Message) =>
msg.channel.id === adminChannel.id &&
!msg.author.bot &&
["oui", "non", "yes", "no"].includes(msg.content.toLowerCase());
const confirmCollected = await adminChannel.awaitMessages({
filter: confirmFilter,
max: 1,
});
const confirmation = confirmCollected.first()?.content.toLowerCase();
if (confirmation === "oui" || confirmation === "yes") {
confirmed = true;
await adminChannel.send({ content: "Ok" });
} else {
msg.content.startsWith(`<@${client.user!.id}>`);
let confirmed = false;
let answer: string | null = null;
while (!confirmed) {
const collected = await adminChannel.awaitMessages({ filter, max: 1 });
answer = collected.first()?.content || null;
if (!answer) continue;
answer = answer.replace(`<@${client.user!.id}>`, "").trim();
if (answer.toLowerCase() === "tg") {
answer = "";
break;
}
const players = answer
.split(",")
.map((x) => x.trim())
.filter(Boolean);
await adminChannel.send({
content: "D'accord, veuillez réessayer. Qui a grind ?",
embeds: [
{
title: "Joueurs entrés",
description: players.length
? players.map((name) => `- ${name}`).join("\n")
: "*Aucun joueur entré*",
color,
},
],
content: `Est-ce correct ? (oui/non)`,
});
const confirmFilter = (msg: Message) =>
msg.channel.id === adminChannel.id &&
!msg.author.bot &&
["oui", "non", "yes", "no"].includes(msg.content.toLowerCase());
const confirmCollected = await adminChannel.awaitMessages({
filter: confirmFilter,
max: 1,
});
const confirmation = confirmCollected.first()?.content.toLowerCase();
if (confirmation === "oui" || confirmation === "yes") {
confirmed = true;
await adminChannel.send({ content: "Ok" });
} else {
await adminChannel.send({
content: "D'accord, veuillez réessayer. Qui a grind ?",
});
}
}
if (answer === null) {
return questLogger.fatal("Answer was 'null', this should be unreachable");
}
exclude = answer
.split(",")
.map((x) => x.trim())
.filter(Boolean);
}
if (answer === null) {
return questLogger.fatal("Answer was 'null', this should be unreachable");
}
const exclude = answer
.split(",")
.map((x) => x.trim())
.filter(Boolean);
const embed = await makeResultEmbed(quest, [
...env.QUEST_EXCLUDE,
...exclude,
@@ -116,6 +120,8 @@ export const askForGrinders = async (quest: QuestResult, client: Client) => {
return questLogger.fatal("Invalid 'DISCORD_REWARDS_CHANNEL'");
}
await adminChannel.send("Envoyé !");
if (env.QUEST_EXCLUDE) {
await adminChannel.send("Envoyé !");
}
questLogger.info(`Results posted at: ${new Date().toISOString()}`);
};