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
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -9,6 +9,8 @@ class DatabaseCommand{
this.commandAddAction = '!complot add action ';
this.commandAddReason = '!complot add reason ';
this.commandAddActor = '!complot add actor ';
this.commandAddSource = '!complot add source ';
this.commandAddSentence = '!complot add sentence ';
}
......@@ -23,10 +25,26 @@ class DatabaseCommand{
this.addAction(message);
}else if(content.startsWith(this.commandAddReason)){
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){
const actor = message.content.slice(this.commandAddActor.length);
complotDB.addActor(actor);
......
......@@ -5,26 +5,15 @@ class InformeMoi{
constructor(client){
this.client = client;
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(){
const actor = complotDB.getRandomActor();
const action = complotDB.getRandomAction();
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 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);
}
......
......@@ -6,9 +6,21 @@ class ComplotDB{
this.actors = [];
this.actions = [];
this.reasons = [];
this.sentences = [];
this.sources = [];
this.readFile();
}
addSentence(sentence){
this.sentences.push(sentence);
this.saveFile();
}
addSource(source){
this.sources.push(source);
this.saveFile();
}
addActor(actor){
this.actors.push(actor);
this.saveFile();
......@@ -52,6 +64,14 @@ class ComplotDB{
return this.#getRandomItem(this.reasons);
}
getRandomSource(){
return this.#getRandomItem(this.sources);
}
getRandomSentence(){
return this.#getRandomItem(this.sentences);
}
#enumListString(list){
let string = '';
for(let i = 0; i < list.length; i++){
......@@ -61,18 +81,38 @@ class ComplotDB{
return string;
}
toString(){
listToString(list, title){
let content = "```\n";
content += "======== Actors =========\n";
content += this.#enumListString(this.actors);
content += "======== Actions ========\n";
content += this.#enumListString(this.actions);
content += "======== Reasons ========\n";
content += this.#enumListString(this.reasons);
content += "```";
content += `======== ${title} =========\n`;
content += this.#enumListString(list);
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(){
let data = fs.readFile(this.filename, (err, data)=>{
if (err){
......@@ -80,9 +120,11 @@ class ComplotDB{
throw err;
}
const json = JSON.parse(data);
this.actors = json.actors;
this.reasons = json.reasons;
this.actions = json.actions;
this.actors = json.actors ? json.actors : [];
this.reasons = json.reasons ? json.reasons : [];
this.actions = json.actions ? json.actions : [];
this.sources = json.sources ? json.sources : [];
this.sentences = json.sentences ? json.sentences : [];
});
}
......@@ -91,7 +133,9 @@ class ComplotDB{
let data = JSON.stringify({
actors: this.actors,
actions: this.actions,
reasons: this.reasons
reasons: this.reasons,
sources : this.sources,
sentences : this.sentences,
});
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"]}
\ 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"],"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
......@@ -4,7 +4,9 @@ const complotDB = require('../database/ComplotDB.js');
const CATEGORY = {
ACTION : 0,
REASON : 1,
ACTOR : 2
ACTOR : 2,
SOURCE : 3,
SENTENCE : 4
};
class VoteParser{
......@@ -16,10 +18,17 @@ class VoteParser{
this.categories = new Map([
[channelsID.actor, CATEGORY.ACTOR],
[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);
}
......@@ -38,28 +47,52 @@ class VoteParser{
}
}
async add(message, category){
let content = message.content;
categoryCase(category, content){
if(category === CATEGORY.SOURCE || category === CATEGORY.SENTENCE){
return content;
}
const char = content.charAt(0);
const reste = content.slice(1);
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);
message.delete();
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();
this.channelBase.send(dbString).then(message =>{
this.infoMessage = message;
});
this.infoMessageActor = await this.channelBase.send(actor);
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{
this.infoMessage.edit(dbString);
switch(category){
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{
case CATEGORY.ACTOR: complotDB.addActor(messageString); break;
case CATEGORY.ACTION: complotDB.addAction(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 @@
"actor" : "895047791645179944",
"action" : "895047929713266709",
"reason" : "895047902123143210",
"source" : "896855116425072711",
"sentence": "896854956286558218",
"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