From 81b41aa8731d9035425c1735e07090bdbbd6dd25 Mon Sep 17 00:00:00 2001
From: Adrien Nunes <adrien.nunes@ensiie.fr>
Date: Mon, 25 Oct 2021 19:35:38 +0200
Subject: [PATCH] Multiple object (actor, source, etc)

---
 commands/InformeMoi.js   | 39 +++++++++++++++++++++++++++++++--------
 database/complot_db.json |  2 +-
 2 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/commands/InformeMoi.js b/commands/InformeMoi.js
index 2eeb960..1eb79fa 100644
--- a/commands/InformeMoi.js
+++ b/commands/InformeMoi.js
@@ -5,17 +5,40 @@ class InformeMoi{
     constructor(client){
         this.client = client;
         this.channels = this.client.channels.cache;
+        this.actorRE = new RegExp('<actor>', 'gi'); 
+        this.wantRE = new RegExp('<want>', 'gi'); 
+        this.reasonRE = new RegExp('<reason>', 'gi'); 
+        this.sourceRE = new RegExp('<source>', 'gi'); 
+        this.actionRE = new RegExp('<action>', 'gi'); 
+    }
+
+    fillAllRandomObject(sentence, regularExpr, randomMethode){
+        const matches = sentence.matchAll(regularExpr);
+        const size = matches.length;
+        let objectString = "";
+        let newSentence = sentence;
+        for(let match of matches){
+            objectString = randomMethode();
+            newSentence = newSentence.replace(match, objectString);
+        }
+        if(size === 1 && regularExpr === this.actorRE){
+            const want = objectString.startsWith("Les ") ? "veulent" : "veut";
+            newSentence = newSentence.remplace(match, want );
+        }
+        
+        return newSentence;
     }
 
     getRandomComplot(){
-        const actor = complotDB.getRandomActor();
-        const action = complotDB.getRandomAction();
-        const reason = complotDB.getRandomReason();
-        const source = complotDB.getRandomSource();
-        const sentence = complotDB.getRandomSentence();
-        const want = actor.startsWith("Les ") ? "veulent" : "veut";
-
-        return sentence.replace('<actor>', actor).replace('<want>', want).replace('<reason>', reason).replace('<source>', source).replace('<action>', action);
+        let sentence = complotDB.getRandomSentence();
+
+        sentence = this.fillAllRandomObject(sentence, this.actorRE, complotDB.getRandomActor.bind(complotDB));
+        sentence = this.fillAllRandomObject(sentence, this.actionRE, complotDB.getRandomAction.bind(complotDB));
+        sentence = this.fillAllRandomObject(sentence, this.reasonRE, complotDB.getRandomReason.bind(complotDB));
+        sentence = this.fillAllRandomObject(sentence, this.sourceRE, complotDB.getRandomSource.bind(complotDB));
+        
+        sentence.replaceAll(this.wantRE, 'veut'); /**Todo, change */
+        return sentence;
     }
 
     parse(message){
diff --git a/database/complot_db.json b/database/complot_db.json
index b7a7653..6e3dad1 100644
--- a/database/complot_db.json
+++ b/database/complot_db.json
@@ -1 +1 @@
-{"actors":["Macron","TSP","Le BDE","Les Francs-Maçons","La CIA","Laurent Prével","Mouilleron","Rioboo","Forest","Jean Lassalle","Sylvain Duriff","Rocket","Titi","Nathalie Arthaud","Le fantôme d'Hitler","JeanMarIIE","Le Bar-C","Le C-19","Michel Drucker","Sardoche","i-TV","Ta mère","Diiese","Le CBDE","Le MEDEF","L'artiste Gaber","Le grand Patronat","Te Deum","Frédéric Chaumont","Didier Raoult","Alain Soral","Cortex 91 des pyramides","Les témoins de Jéhovah","Génération identitaire","Michel"],"actions":["pirater Arise","vacciner la population","installer des antennes 5G","creer un nouveau variant du coronavirus","détruire Evry","bombarder TSP","faire des TikTok","comprendre les cours de Rioboo","vendre des informations aux Japonais","racheter MyPizza","annexer l'IMT-BS","radier le tout le BdE de l'AEIIE","interdire la vente d'alcool à Le Bar (c)","installer Windows sur les PCs de l'école","enlever les hentai du Baka","mettre Jean MarIIE à la tête du Bde","soudoyer des iiens","payer des petits chinois","lancer une shitstorm par mail","investir dans l'immobilier","débrancher un switch pendant une NJV","spéculer sur l'effondrement de l'économie africaine"],"reasons":["gagner l'élection 2022","contrôler l'humanité","éradiquer l'humanité","instaurer une dictature","capter la 5G","gagner contre Pignôle au babyfoot","faire fermer l'ENSIIE","deban tigriz","dissoudre le Bakaclub","supprimer internet","gagner le carambar d'or","intégrer TSP","éradiquer tous les viieux","gagner la campagne BdE","prendre la place de tactac","rouvrir l'antenne de Strasbourg","obtenir tous les boucliers verts","passer master sur LoL","faire gagnér l'emote fipa","faire arriver le RER D à l'heure","préserver les iiens de souche","imposer un régime communiste","empêcher pignôle (<@590627154400903228> ) de faire des blagues"],"sources":["QAnon","IImondE","une amie qui travaille au gouvernement","Réinfo Covid","FranceSoir","Médiavenir","LesMoutonsRebelles","un poste Facebook","un twittos","Kim Glow","l'AFP","ma maman","Jean-Jacques Bourdin","Stéphane Bern","CNews","Louis Fouché","Didier Raoult","Francis Lalane","Eddy Malou","mon oncle sur Whatsapp","un ami directeur de production à France Télévisions","un prix nobel désavoué par sa profession","démotivateur","Madmoizelle.com","Buzz feed","intuition"],"sentences":["<actor> <want> <action> pour <reason> !","Selon <source>, <actor> <want> <action> afin de <reason>.","<actor> <want> <action> rien que pour <reason>.....","Grâce à <source>, je sais que <actor> <want> <action> pour <reason>.","On dit que <actor> <want> <action>, tout ça pour <reason>...","<actor> <want> <action> afin de <reason>, ça fait réfléchir...","Vous verrez que <actor> va <action> pour <reason>, vous l'aurez lu ici en premier...","🚨ALERTE INFO🚨 :\n <actor> <want> <action> pour <reason> \n (Source : <source>)","<actor> <want> <action> rien que pour <reason>.....","Je sais par <source> que <actor> <want> <action> pour <reason>!!!","<actor> <want> <reason>, ça dit beaucou au sujé de sociéter"]}
\ No newline at end of file
+{"actors":["Macron","TSP","Le BDE","Les Francs-Maçons","La CIA","Laurent Prével","Mouilleron","Rioboo","Forest","Jean Lassalle","Sylvain Duriff","Rocket","Titi","Nathalie Arthaud","Le fantôme d'Hitler","JeanMarIIE","Le Bar-C","Le C-19","Michel Drucker","Sardoche","i-TV","Ta mère","Diiese","Le CBDE","Le MEDEF","L'artiste Gaber","Le grand Patronat","Te Deum","Frédéric Chaumont","Didier Raoult","Alain Soral","Cortex 91 des pyramides","Les témoins de Jéhovah","Génération identitaire","Michel"],"actions":["pirater Arise","vacciner la population","installer des antennes 5G","creer un nouveau variant du coronavirus","détruire Evry","bombarder TSP","faire des TikTok","comprendre les cours de Rioboo","vendre des informations aux Japonais","racheter MyPizza","annexer l'IMT-BS","radier le tout le BdE de l'AEIIE","interdire la vente d'alcool à Le Bar (c)","installer Windows sur les PCs de l'école","enlever les hentai du Baka","mettre Jean MarIIE à la tête du Bde","soudoyer des iiens","payer des petits chinois","lancer une shitstorm par mail","investir dans l'immobilier","débrancher un switch pendant une NJV","spéculer sur l'effondrement de l'économie africaine"],"reasons":["gagner l'élection 2022","contrôler l'humanité","éradiquer l'humanité","instaurer une dictature","capter la 5G","gagner contre Pignôle au babyfoot","faire fermer l'ENSIIE","deban tigriz","dissoudre le Bakaclub","supprimer internet","gagner le carambar d'or","intégrer TSP","éradiquer tous les viieux","gagner la campagne BdE","prendre la place de tactac","rouvrir l'antenne de Strasbourg","obtenir tous les boucliers verts","passer master sur LoL","faire gagnér l'emote fipa","faire arriver le RER D à l'heure","préserver les iiens de souche","imposer un régime communiste","empêcher pignôle (<@590627154400903228> ) de faire des blagues"],"sources":["QAnon","IImondE","une amie qui travaille au gouvernement","Réinfo Covid","FranceSoir","Médiavenir","LesMoutonsRebelles","un poste Facebook","un twittos","Kim Glow","l'AFP","ma maman","Jean-Jacques Bourdin","Stéphane Bern","CNews","Louis Fouché","Didier Raoult","Francis Lalane","Eddy Malou","mon oncle sur Whatsapp","un ami directeur de production à France Télévisions","un prix nobel désavoué par sa profession","démotivateur","Madmoizelle.com","Buzz feed","intuition"],"sentences":["<Actor> <Actor> !"]}
\ No newline at end of file
-- 
GitLab