Skip to content
Extraits de code Groupes Projets
Valider e294304d rédigé par Adrien NUNES's avatar Adrien NUNES
Parcourir les fichiers

CommandInfoCovid

parent 5edf0450
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
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
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter