Compare commits

..

3 Commits

View File

@ -6,7 +6,7 @@ var wwId = 1;
/**
* This function aims to do word wars inside a discord channel.
* Someone launches a wordwar and other people can join in by clicking on the react icon.
* Someone launches a wrdwar and other people can join in by clicking on the react icon.
* First argument is the time of duration of the wordwar.
* Second argument is the waiting time before the wordwar.
**/
@ -85,7 +85,7 @@ module.exports = {
ongoingww.set(interaction.user.id, wwRole.name);
interaction.member.roles.add(wwRole.id);
commandReply = "la " + wwRole.name + " a été initiée. Elle commencera dans " + wwdelay + " minutes et durera " + wwtimer + " minutes.";
const commandReply = getRegistered(wwRole.name,wwdelay,wwtimer);
const row = new MessageActionRow()
.addComponents(
@ -119,8 +119,9 @@ module.exports = {
OnlyReply('Vous êtes déjà enregistré.e dans la wordwar ' + ongoingww.get(i.user.id), i, wwRole);
} else {
i.member.roles.add(wwRole);
ongoingww.set(i.user.ida, wwRole);
OnlyReply('Participation enregistrée', i, wwRole);
ongoingww.set(i.user.id, wwRole.name);
i.message.edit(getRegistered(wwRole.name, wwdelay, wwtimer));
i.deferUpdate();
}
});
@ -134,9 +135,10 @@ module.exports = {
if (!i.member.roles.cache.has(wwRole.id)) {
OnlyReply('Vous n\'êtes pas enregistré pour cette wordwar', i, wwRole);
} else {
OnlyReply('Participation annulée', i, wwRole);
i.member.roles.remove(wwRole);
ongoingww.delete(i.user.id);
console.log(ongoingww);
i.deferUpdate();
// Si l'utilisateur qui annule est le dernier dans cette wordwar
if (typeof ongoingww.find(wordWar => wordWar == wwRole.name) == "undefined") {
@ -152,6 +154,8 @@ module.exports = {
}
console.log(wwRole.name + ' canceled');
return;
}else{
i.message.edit(getRegistered(wwRole.name, wwdelay, wwtimer));
}
}
});
@ -199,3 +203,13 @@ function OnlyReply(str, int, ww) {
int.deferUpdate();
}
}
function getRegistered(ww,d, t) {
var str = "";
ongoingww.forEach(async (value, key) => {
if (value == ww){
str += userMention(key) + ' ';
}
});
return "la " + ww + " a été initiée. Elle commencera dans " + d + " minutes et durera " + t + " minutes.\nInscrits : " + str;
}