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

Vote pour source/sentence

parent 49007390
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -9,6 +9,8 @@ class DatabaseCommand{ ...@@ -9,6 +9,8 @@ class DatabaseCommand{
this.commandAddAction = '!complot add action '; this.commandAddAction = '!complot add action ';
this.commandAddReason = '!complot add reason '; this.commandAddReason = '!complot add reason ';
this.commandAddActor = '!complot add actor '; this.commandAddActor = '!complot add actor ';
this.commandAddSource = '!complot add source ';
this.commandAddSentence = '!complot add sentence ';
} }
...@@ -23,10 +25,26 @@ class DatabaseCommand{ ...@@ -23,10 +25,26 @@ class DatabaseCommand{
this.addAction(message); this.addAction(message);
}else if(content.startsWith(this.commandAddReason)){ }else if(content.startsWith(this.commandAddReason)){
this.addReason(message); this.addReason(message);
}else if (content.startsWith(this.commandAddSource)){
this.addSource(message);
}else if(content.startsWith(this.commandAddSentence)){
this.addSentence(message);
} }
} }
} }
addSource(message){
const source = message.content.slice(this.commandAddSource.length);
complotDB.addSource(source);
message.reply(`"${source}" added to sources`);
}
addSentence(message){
const sentence = message.content.slice(this.commandAddSentence.length);
complotDB.addSentence(sentence);
message.reply(`"${sentence}" added to sentence`);
}
addActor(message){ addActor(message){
const actor = message.content.slice(this.commandAddActor.length); const actor = message.content.slice(this.commandAddActor.length);
complotDB.addActor(actor); complotDB.addActor(actor);
......
...@@ -5,26 +5,15 @@ class InformeMoi{ ...@@ -5,26 +5,15 @@ class InformeMoi{
constructor(client){ constructor(client){
this.client = client; this.client = client;
this.channels = this.client.channels.cache; this.channels = this.client.channels.cache;
this.sources = ['QAnon', 'IImondE', 'Réinfo Covid', 'FranceSoir', 'Madiavenir', 'LesMoutonsRebelles', 'une amie qui travaille au gouvernement', 'un poste Facebook', 'un twittos', 'Kim Glow', 'l\'AFP' ];
this.sentences= [
'<actor> <want> <action> pour <reason> !',
'Selon <source>, <actor> <want> <action> afin de <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>.....'
];
} }
getRandomComplot(){ getRandomComplot(){
const actor = complotDB.getRandomActor(); const actor = complotDB.getRandomActor();
const action = complotDB.getRandomAction(); const action = complotDB.getRandomAction();
const reason = complotDB.getRandomReason(); const reason = complotDB.getRandomReason();
const source = this.sources[Math.floor(Math.random()*this.sources.length)]; const source = complotDB.getRandomSource();
const sentence = complotDB.getRandomSentence();
const want = actor.startsWith("Les ") ? "veulent" : "veut"; const want = actor.startsWith("Les ") ? "veulent" : "veut";
const sentence = this.sentences[Math.floor(Math.random()*this.sentences.length)];
return sentence.replace('<actor>', actor).replace('<want>', want).replace('<reason>', reason).replace('<source>', source).replace('<action>', action); return sentence.replace('<actor>', actor).replace('<want>', want).replace('<reason>', reason).replace('<source>', source).replace('<action>', action);
} }
......
...@@ -6,9 +6,21 @@ class ComplotDB{ ...@@ -6,9 +6,21 @@ class ComplotDB{
this.actors = []; this.actors = [];
this.actions = []; this.actions = [];
this.reasons = []; this.reasons = [];
this.sentences = [];
this.sources = [];
this.readFile(); this.readFile();
} }
addSentence(sentence){
this.sentences.push(sentence);
this.saveFile();
}
addSource(source){
this.sources.push(source);
this.saveFile();
}
addActor(actor){ addActor(actor){
this.actors.push(actor); this.actors.push(actor);
this.saveFile(); this.saveFile();
...@@ -52,6 +64,14 @@ class ComplotDB{ ...@@ -52,6 +64,14 @@ class ComplotDB{
return this.#getRandomItem(this.reasons); return this.#getRandomItem(this.reasons);
} }
getRandomSource(){
return this.#getRandomItem(this.sources);
}
getRandomSentence(){
return this.#getRandomItem(this.sentences);
}
#enumListString(list){ #enumListString(list){
let string = ''; let string = '';
for(let i = 0; i < list.length; i++){ for(let i = 0; i < list.length; i++){
...@@ -61,18 +81,38 @@ class ComplotDB{ ...@@ -61,18 +81,38 @@ class ComplotDB{
return string; return string;
} }
toString(){ listToString(list, title){
let content = "```\n"; let content = "```\n";
content += "======== Actors =========\n"; content += `======== ${title} =========\n`;
content += this.#enumListString(this.actors); content += this.#enumListString(list);
content += "======== Actions ========\n"; content += '```';
content += this.#enumListString(this.actions);
content += "======== Reasons ========\n";
content += this.#enumListString(this.reasons);
content += "```";
return content; return content;
} }
actorToString(){
return this.listToString(this.actors, 'Actors');
}
actionToString(){
return this.listToString(this.actions, 'Action');
}
reasonToString(){
return this.listToString(this.reasons, 'Reasons');
}
sourceToString(){
return this.listToString(this.sources, 'Sources');
}
sentenceToString(){
return this.listToString(this.sentences, 'Sentences');
}
toString(){
return 'See Base du bot...';
}
readFile(){ readFile(){
let data = fs.readFile(this.filename, (err, data)=>{ let data = fs.readFile(this.filename, (err, data)=>{
if (err){ if (err){
...@@ -80,9 +120,11 @@ class ComplotDB{ ...@@ -80,9 +120,11 @@ class ComplotDB{
throw err; throw err;
} }
const json = JSON.parse(data); const json = JSON.parse(data);
this.actors = json.actors; this.actors = json.actors ? json.actors : [];
this.reasons = json.reasons; this.reasons = json.reasons ? json.reasons : [];
this.actions = json.actions; this.actions = json.actions ? json.actions : [];
this.sources = json.sources ? json.sources : [];
this.sentences = json.sentences ? json.sentences : [];
}); });
} }
...@@ -91,7 +133,9 @@ class ComplotDB{ ...@@ -91,7 +133,9 @@ class ComplotDB{
let data = JSON.stringify({ let data = JSON.stringify({
actors: this.actors, actors: this.actors,
actions: this.actions, actions: this.actions,
reasons: this.reasons reasons: this.reasons,
sources : this.sources,
sentences : this.sentences,
}); });
fs.writeFile(this.filename, data, (err)=>{ fs.writeFile(this.filename, data, (err)=>{
......
{"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"],"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"],"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"]} {"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"],"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"],"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"],"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"],"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>....."]}
\ No newline at end of file \ No newline at end of file
...@@ -4,7 +4,9 @@ const complotDB = require('../database/ComplotDB.js'); ...@@ -4,7 +4,9 @@ const complotDB = require('../database/ComplotDB.js');
const CATEGORY = { const CATEGORY = {
ACTION : 0, ACTION : 0,
REASON : 1, REASON : 1,
ACTOR : 2 ACTOR : 2,
SOURCE : 3,
SENTENCE : 4
}; };
class VoteParser{ class VoteParser{
...@@ -16,10 +18,17 @@ class VoteParser{ ...@@ -16,10 +18,17 @@ class VoteParser{
this.categories = new Map([ this.categories = new Map([
[channelsID.actor, CATEGORY.ACTOR], [channelsID.actor, CATEGORY.ACTOR],
[channelsID.reason, CATEGORY.REASON], [channelsID.reason, CATEGORY.REASON],
[channelsID.action, CATEGORY.ACTION] [channelsID.action, CATEGORY.ACTION],
[channelsID.source, CATEGORY.SOURCE],
[channelsID.sentence, CATEGORY.SENTENCE]
]); ]);
this.infoMessage = null; this.infoMessageActor = null;
this.infoMessageReason = null;
this.infoMessageAction = null;
this.infoMessageSource = null;
this.infoMessageSentence = null;
this.channelBase = this.client.channels.cache.get(channelsID.base); this.channelBase = this.client.channels.cache.get(channelsID.base);
} }
...@@ -38,28 +47,52 @@ class VoteParser{ ...@@ -38,28 +47,52 @@ class VoteParser{
} }
} }
async add(message, category){ categoryCase(category, content){
let content = message.content; if(category === CATEGORY.SOURCE || category === CATEGORY.SENTENCE){
return content;
}
const char = content.charAt(0); const char = content.charAt(0);
const reste = content.slice(1); const reste = content.slice(1);
content = (category === CATEGORY.ACTOR) ? char.toUpperCase() + reste: char.toLowerCase() + reste; content = (category === CATEGORY.ACTOR) ? char.toUpperCase() + reste: char.toLowerCase() + reste;
return content;
}
async add(message, category){
let content = this.categoryCase(category, message.content);
this.addFormatedString(content, category); this.addFormatedString(content, category);
message.delete(); message.delete();
message.channel.send(`"${content}" ajouté ! \n Par <@${message.author.id}>`); message.channel.send(`"${content}" ajouté ! \n Par <@${message.author.id}>`);
const dbString = complotDB.toString();
this.updateBase(category);
}
async updateBase(category){
const actor = complotDB.actorToString();
const action = complotDB.actionToString();
const reason = complotDB.reasonToString();
const source = complotDB.sourceToString();
const sentence = complotDB.sentenceToString();
if(!this.infoMessage){ if(!this.infoMessageActor){
await this.deleteAllMessageInfo(); await this.deleteAllMessageInfo();
this.channelBase.send(dbString).then(message =>{ this.infoMessageActor = await this.channelBase.send(actor);
this.infoMessage = message; this.infoMessageAction = await this.channelBase.send(action);
}); this.infoMessageReason = await this.channelBase.send(reason);
this.infoMessageSource = await this.channelBase.send(source);
this.infoMessageSentence = await this.channelBase.send(sentence);
}else{ }else{
switch(category){
this.infoMessage.edit(dbString); case CATEGORY.ACTION: this.infoMessageAction.edit(action); break;
case CATEGORY.REASON: this.infoMessageReason.edit(reason); break;
case CATEGORY.SOURCE: this.infoMessageSource.edit(source); break;
case CATEGORY.ACTOR: this.infoMessageActor.edit(actor); break;
case CATEGORY.SENTENCE: this.infoMessageSentence.edit(sentence);break;
} }
} }
}
...@@ -68,6 +101,8 @@ class VoteParser{ ...@@ -68,6 +101,8 @@ class VoteParser{
case CATEGORY.ACTOR: complotDB.addActor(messageString); break; case CATEGORY.ACTOR: complotDB.addActor(messageString); break;
case CATEGORY.ACTION: complotDB.addAction(messageString); break; case CATEGORY.ACTION: complotDB.addAction(messageString); break;
case CATEGORY.REASON: complotDB.addReason(messageString); break; case CATEGORY.REASON: complotDB.addReason(messageString); break;
case CATEGORY.SOURCE: complotDB.addSource(messageString); break;
case CATEGORY.SENTENCE: complotDB.addSentence(messageString); break;
} }
} }
......
...@@ -2,5 +2,7 @@ ...@@ -2,5 +2,7 @@
"actor" : "895047791645179944", "actor" : "895047791645179944",
"action" : "895047929713266709", "action" : "895047929713266709",
"reason" : "895047902123143210", "reason" : "895047902123143210",
"source" : "896855116425072711",
"sentence": "896854956286558218",
"base": "895047755800641576" "base": "895047755800641576"
} }
\ 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