diff --git a/commands/CommandInfoCovid.js b/commands/CommandInfoCovid.js new file mode 100644 index 0000000000000000000000000000000000000000..ce6b03bb842d83e444b1b86332788c4af02c1552 --- /dev/null +++ b/commands/CommandInfoCovid.js @@ -0,0 +1,99 @@ + +class CommandInfoCovid{ + constructor(client){ + this.client = client; + this.infoCovidRegExp = new RegExp('info[ -]covid', 'i'); + + this.situations = ["êtes cas contact","êtes muni d'un schéma vaccinal complet","êtes positif","êtes non vacciné","avez contracté la covid il y a plus de <random_int> mois", "avez contracté le virus il y a moins de <random_int> mois"]; + this.actions = ["effectuer <random_int_m> test<s> à J<signe><random_int>","vous confiner pendant <random_int_f> semaine<s>", "Effectuer <random_int_m> autotest<s>", "Recevoir <random_int_f> dose<s> vaccinale<s> supplémentaire<s>"]; + this.temps = ["dans les prochaines <random_int>h", "dans les dernières <random_int>h", "il y a moins de <random_int> mois", "il y a plus de <random_int> mois", "il y a entre <random_int> et <random_int> mois", "dans les <random_int> à <random_int> prochaines heures"]; + this.connecteurs = ["et", "ou", "et / ou", "mais également"]; + this.amplificateurs = ["sauf si vous <situation>", "à moins que vous <situation>", "sauf si vous avez déjà <action> <temps>"]; + } + + getRandomInt(x,y){ + return Math.floor(Math.random()*(y-x) +x) + } + + replaceRandomIntString(str, min, max){ + return str.replaceAll('<random_int>', ()=>getRandomInt(min,max)); + } + + replaceSmallRandomIntString(str){ + const smallRandom = getRandomInt(1,5); + const plur = (smallRandom > 1) ? 's' : ''; + let newStr = null; + + if(smallRandom === 1){ + newStr = str.replaceAll('<random_int_f>', 'une').replaceAll('<random_int_m>', 'un');; + }else{ + newStr = str.replaceAll('<random_int_f>', smallRandom).replaceAll('<random_int_m>',smallRandom); + } + + return newStr.replaceAll('<s>', plur); + } + + getRandomSituation(){ + const situation = this.situations[Math.floor(Math.random()*this.situations.length)]; + return replaceRandomIntString(situation, 1, 24); + } + + getRandomAction(){ + const action = this.actions[Math.floor(Math.random()*this.actions.length)]; + return replaceRandomIntString(replaceSmallRandomIntString(action), 1, 24); + } + + getRandomTemps(){ + const temps = this.temps[Math.floor(Math.random()*this.temps.length)]; + return replaceRandomIntString(temps, 2, 24); + } + + getRandomConnecteur(){ + return this.connecteurs[Math.floor(Math.random()*this.connecteurs.length)]; + } + + getRandomAmplificateur(){ + const amplificateur = this.amplificateurs[Math.floor(Math.random()*this.amplificateur.length)]; + const action = this.getRandomAction(); + const situation = this.getRandomSituation(); + const temps = this.getRandomTemps(); + return amplificateur.replaceAll('<action>', action).replaceAll('<situation>', situation).replaceAll('<temps>', temps); + } + + getRandomOptionalPart(getRandomPart){ + const connecteur = this.getRandomConnecteur(); + const part = getRandomPart(); + const amplificateur = getRandomInt(0,2) ? ` ${this.getRandomAmplificateur()}` : ''; + return `${connecteur} ${part}${amplificateur}`; + } + + getAllOptionalPart(getRandomPart){ + const optionalPartCount = this.getRandomInt(0,4); //0 à 3 + let output = (optionalPartCount > 0) ? ' ' : ''; //On commence avec un espace si on a quelque chose + for(int i = 0; i < optionalSituationCount; i++){ + output += this.getRandomOptionalPart(getRandomPart) + (i < (optionalPartCount - 1) ? ' ' : ''); + } + return output; + } + + getRandomInfo(){ + const situation = this.getRandomSituation(); + const optionalSituations = this.getAllOptionalPart(this.getRandomSituation); + const action = this.getRandomAction(); + const optionalsActions = this.getAllOptionalPart(this.getRandomAction); + return `Si vous ${situation}${optionalSituations}, alors vous devez ${action}${optionalsActions}.` ; + } + + parse(message){ + if(this.shouldRespond(message)){ + message.reply(this.getRandomInfo()); + } + } + + shouldRespond(message){ + const resRE = message.content.match(this.quiRegExp); + return resRE !== null; + } +} + +module.exports = CommandQui; \ No newline at end of file