ajout de la fonctionnalité wordwar + modifs

This commit is contained in:
Nemo 2021-11-10 00:49:27 +01:00
parent e5c6c4b553
commit 0a28d3303d
2 changed files with 138 additions and 0 deletions

132
commands/wordwar.js Normal file
View File

@ -0,0 +1,132 @@
const { SlashCommandBuilder, blockQuote, userMention } = require('@discordjs/builders');
const { MessageActionRow, MessageButton, Message } = require('discord.js');
const ongoingww = [];
/**
* 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.
* First argument is the time of duration of the wordwar.
* Second argument is the waiting time before the wordwar.
**/
module.exports = {
data: new SlashCommandBuilder()
.setName('wordwar')
.setDescription('Pour faire des WordWar comme au NaNoWriMo')
.addStringOption(option =>
option.setName('duree')
.setDescription('Durée de la wordwar. Par défaut 20min, max 30min.')
.setRequired(false)
)
.addStringOption(option =>
option.setName('attente')
.setDescription('Attente avant la wordwar. Par défaut 2min, max 15min.')
.setRequired(false)
),
async execute(interaction) {
if (ongoingww.includes(interaction.user.id)) {
interaction.channel.send("<@" + interaction.user.id + "> a déjà une wordwar en cours, merci de patienter pour en relancer une nouvelle !")
return;
} else {
var wwtimer;
var wwdelay;
if (interaction.options.get('duree') == null) {
wwtimer = 20;
} else {
wwtimer = interaction.options.get('duree').value;
if (isNormalInteger(wwtimer)) {
if (wwtimer > 30) {
interaction.channel.send("Le temps d'une wordwar ne peux pas excéder **30 minutes** sur ce channel. Merci de réessayer !");
return;
} else if (wwtimer < 1) {
return;
}
} else {
interaction.channel.send("Le temps d'une wordwar doit être un entier positif compris entre **1 minute** et **30 minutes**. Merci de réessayer !")
return;
} // && Number.isInteger(args[1])
}
if (interaction.options.get('attente') == null) {
wwdelay = 2;
} else {
wwdelay = interaction.options.get('attente').value;
if (isNormalInteger(wwdelay)) {
if (wwdelay > 15) {
interaction.channel.send("Le temps d'attente d'une wordwar ne peux pas excéder **15 minutes** sur ce channel. Merci de réessayer !");
return;
} else if (wwdelay < 1) {
interaction.channel.send("Le temps d'attente d'une wordwar ne peux pas être inférieur à **1 minute** sur ce channel. Merci de réessayer !")
return;
}
} else {
interaction.channel.send("Le temps d'attente d'une wordwar doit être un entier positif compris entre **1 minute** et **15 minutes**. Merci de réessayer !")
return;
}
}
memberid = interaction.user.id;
ongoingww.push(memberid);
commandReply = "Une wordwar a été initiée par " + userMention(memberid) + " . Elle commencera dans " + wwdelay + " minutes et durera " + wwtimer + " minutes.";
const row = new MessageActionRow()
.addComponents(
new MessageButton()
.setCustomId('primary')
.setLabel('Participer')
.setStyle('SUCCESS')
)
.addComponents(
new MessageButton()
.setCustomId('secondary')
.setLabel('Annuler')
.setStyle('DANGER')
.setDisabled(true)
);
message = await interaction.reply({ content: commandReply, components: [row] })
.then(function (message) {
/* const collector = message.createMessageComponentCollector({
time: (1000 * 60 * (wwtimer + wwdelay))
})
collector.on('collect', (buttonClick) => {
buttonClick.reply({
content: 'Enregistré pour la wordwar',
ephemeral: true
})
});
*/
/* interaction.react('');
setTimeout(() => {
reaction = interaction.reactions.cache.find(r => r.name = '✅');
users = reaction.users.cache;
var participantStart = "";
users.forEach(element => {
participantStart += userMention(element.id);
});
interaction.channel.send("\nLa wordwar initiée par " + userMention(memberid) + " commence. Vous pouvez toujours la rejoindre si vous le désirez. Bonne chance à tou.te.s !!\n" + participantStart)
var participantTab = [];
setTimeout(function () {
participantTab += 'La wordwar initiée par ' + userMention(memberid) + ' est maintenant terminée, merci d\'y avoir participé \!\n';
reaction = interaction.reactions.cache.find(r => r.name = '✅');
users = reaction.users.cache;
users.forEach(element => {
participantTab += userMention(element.id);
});
interaction.channel.send(participantTab);
}, wwtimer * 60000);
ongoingww.splice(ongoingww.indexOf(memberid), 1);
}, wwdelay * 60000); */
});
}
},
};
function isNormalInteger(str) {
var n = Math.floor(Number(str));
return n !== Infinity && String(n) === str && n >= 0;
}

View File

@ -1,6 +1,12 @@
module.exports = {
name: 'interactionCreate',
async execute(interaction) {
if(interaction.isButton()){
console.log(interaction);
interaction.reply({ content: `${interaction.user.tag} clicked me`, ephemeral : true });
}
if (!interaction.isCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);