From fe5d64d4fa2258fedd12ccd428c807b69c7688fd Mon Sep 17 00:00:00 2001
From: Adrien NUNES <anunes.etudiant@gmail.com>
Date: Tue, 14 Nov 2023 17:53:17 +0100
Subject: [PATCH] Ref+ Database Command admin

---
 .gitignore                    |   3 +-
 channels_conf.json            |  15 +--
 commands/CommandParser.js     |   5 +-
 commands/CommandPourquoi.js   |   4 +-
 commands/CommandQui.js        |   3 +-
 commands/CommandVoteParser.js |   6 +-
 commands/DatabaseCommand.js   | 181 +++++++++++++++++++++++++---------
 commands/InformeMoi.js        |  17 ++--
 database/BaseInfo.js          |  81 +++++++++++++++
 database/Category.js          |  20 ++++
 database/ComplotDB.js         | 124 +++++++----------------
 index.js                      |   8 +-
 vote/VoteParser.js            | 153 +++-------------------------
 13 files changed, 318 insertions(+), 302 deletions(-)
 create mode 100644 database/BaseInfo.js
 create mode 100644 database/Category.js

diff --git a/.gitignore b/.gitignore
index 44e33d9..3efeb32 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
 config.json
 /node_modules
-/database/complot_db.json
\ No newline at end of file
+/database/complot_db.json
+channels_conf.json
\ No newline at end of file
diff --git a/channels_conf.json b/channels_conf.json
index d839938..0af3f17 100644
--- a/channels_conf.json
+++ b/channels_conf.json
@@ -1,9 +1,10 @@
 {
-    "actor" : "895047791645179944",
-    "action" : "895047929713266709",
-    "reason" : "895047902123143210",
-    "source" : "896855116425072711",
-    "sentence": "896854956286558218",
-    "base": "895047755800641576",
-    "welcome": "886264368948445244"
+    "actor" : "1163914261257539647",
+    "action" : "1163914293641760789",
+    "reason" : "1163914323773640716",
+    "source" : "1163914221986271332",
+    "sentence": "1163914376777044108",
+    "base": "1163914178042527844",
+    "welcome": "1161725093353898036",
+    "admin": "1173957185617801236"
 }
\ No newline at end of file
diff --git a/commands/CommandParser.js b/commands/CommandParser.js
index 3bf83fc..f40601f 100644
--- a/commands/CommandParser.js
+++ b/commands/CommandParser.js
@@ -8,10 +8,11 @@ const CommandInfoCovid = require('./CommandInfoCovid.js');
 
 class CommandParser {
 
-    constructor(client, voteParser) {
+    constructor(client, voteParser, baseInfo) {
         this.client = client;
+        this.baseInfo = baseInfo;
         this.informeMoi = new InformeMoi(client);
-        this.databaseCommand = new DatabaseCommand(client);
+        this.databaseCommand = new DatabaseCommand(client, baseInfo);
         this.commandVoteParser = new CommandVoteParser(voteParser);
         this.commandQui = new CommandQui(client);
         this.commandPourquoi = new CommandPourquoi(client);
diff --git a/commands/CommandPourquoi.js b/commands/CommandPourquoi.js
index 8e67d2e..746d6e9 100644
--- a/commands/CommandPourquoi.js
+++ b/commands/CommandPourquoi.js
@@ -1,4 +1,5 @@
 const complotDB = require('../database/ComplotDB.js');
+const {Category} = require('../database/Category.js');
 
 class CommandPourquoi{
     constructor(client){
@@ -8,8 +9,7 @@ class CommandPourquoi{
     }
 
     getRandomPourquoi(){
-        const reason = complotDB.getRandomReason();
-
+        const reason = complotDB.getRandom(Category.REASON);
         return this.sentences[Math.floor(Math.random()*this.sentences.length)].replace('<why>', reason);
     }
 
diff --git a/commands/CommandQui.js b/commands/CommandQui.js
index 6790c9d..c17819b 100644
--- a/commands/CommandQui.js
+++ b/commands/CommandQui.js
@@ -1,5 +1,6 @@
 
 const complotDB = require('../database/ComplotDB.js');
+const {Category} = require('../database/Category.js');
 
 class CommandQui{
     constructor(client){
@@ -9,7 +10,7 @@ class CommandQui{
     }
 
     getRandomQui(){
-        const actor = complotDB.getRandomActor();
+        const actor = complotDB.getRandom(Category.ACTOR);
 
         return this.sentences[Math.floor(Math.random()*this.sentences.length)].replace('<who>', actor);
     }
diff --git a/commands/CommandVoteParser.js b/commands/CommandVoteParser.js
index 10b4339..21b2b31 100644
--- a/commands/CommandVoteParser.js
+++ b/commands/CommandVoteParser.js
@@ -1,14 +1,16 @@
 
+const channelsID = require('../channels_conf.json');
+
+const ADMIN_CHAN = channelsID.admin;
 
 class CommandVoteParser{
     constructor(voteParser){
         this.voteParser = voteParser;
         this.command = "!complot score ";
-        this.channel = '892676980699455500'; /**TODO CONF */
     }
 
     parse(message){
-        if(message.channelId === this.channel){
+        if(message.channelId === ADMIN_CHAN){
             const content = message.content.toLowerCase();
             if(content.startsWith(this.command)){
                 const score = parseInt(content.slice(this.command.length));
diff --git a/commands/DatabaseCommand.js b/commands/DatabaseCommand.js
index 700c58c..1401a11 100644
--- a/commands/DatabaseCommand.js
+++ b/commands/DatabaseCommand.js
@@ -1,70 +1,159 @@
 
 const complotDB = require('../database/ComplotDB');
+const channelsID = require('../channels_conf.json');
+const {Category} = require('../database/Category.js');
+
+const COMMAND_LIST = '!list';
+const COMMAND_ADD = '!add';
+const COMMAND_REMOVE = '!remove';
+const ADMIN_CHAN = channelsID.admin;
 
 class DatabaseCommand{
-    constructor(client){
+    constructor(client, baseInfo){
         this.client = client;
-        this.channel = '892676980699455500';
-        this.commandList = '!complot list';
-        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 ';
-
+        this.baseInfo = baseInfo;
+        this.adminChan = this.client.channels.cache.get(ADMIN_CHAN);
     }
 
     parse(message){
-        if(message.channelId === this.channel){
-            const content = message.content.toLowerCase();
-            if(content == this.commandList){
-                this.showList(message);
-            }else if(content.startsWith(this.commandAddActor)){
-                this.addActor(message);
-            }else if(content.startsWith(this.commandAddAction)){
-                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);
+        if(message.channelId === ADMIN_CHAN){
+            const content = message.content;
+            if(content.startsWith(COMMAND_LIST)){
+                this.sendList();
+            }else if(content.startsWith(COMMAND_ADD)){
+                this.parseAdd(message);
+            }else if(content.startsWith(COMMAND_REMOVE)){
+                this.parseRemove(message);
             }
         }
     }
 
-    addSource(message){
-        const source = message.content.slice(this.commandAddSource.length);
-        complotDB.addSource(source);
-        message.reply(`"${source}" added to sources`);
+    async parseRemove(message) {
+        let category, indexes;
+        const params = message.content.split(' ');
+        if(params.length < 3){
+            this.sendHelpRemove(message);
+            return;
+        }
+        try{
+            category = params[1].toLowerCase();
+            const value = params.slice(2).join(' ');
+            if(value.includes(',')){
+                indexes = JSON.parse(`[${value}]`);
+            }else{
+                indexes = [value];
+            }
+            indexes = this.#toInteger(indexes);
+        }catch(e){
+            console.log(e);
+            this.sendHelpRemove(message);
+            return;
+        }
+
+        if(indexes.length < 1){
+            this.sendHelpRemove(message);
+            return;
+        }
+        const response = await this.remove(category, indexes);
+        message.reply(response);
+    }
+
+
+    async parseAdd(message) {
+        let category, content;
+        const params = message.content.split(' ');
+        if(params.length < 3){
+            this.sendHelpAdd(message);
+            return;
+        }
+        category = params[1].toLowerCase();
+        content = params.slice(2).join(' ');
+        
+        const reponse = await this.add(category, content);
+        message.reply(reponse);
     }
-    
-    addSentence(message){
-        const sentence = message.content.slice(this.commandAddSentence.length);
-        complotDB.addSentence(sentence);
-        message.reply(`"${sentence}" added to sentence`);
+
+    sendHelpRemove(message) {
+        message.reply('Utilisation : !remove <actor, action, reason, source,welcome, sentence> 0,1,2,3,4');
     }
 
-    addActor(message){
-        const actor = message.content.slice(this.commandAddActor.length);
-        complotDB.addActor(actor);
-        message.reply(`"${actor}" added to actors`);
+    sendHelpAdd(message) {
+        message.reply('Utilisation : !add <actor, action, reason, source, welcome, sentence> <content>');
     }
 
-    addAction(message){
-        const action = message.content.slice(this.commandAddAction.length);
-        complotDB.addAction(action);
-        message.reply(`"${action}" added to actions`);
+
+
+    wrongCatMessage(category){
+        return `'${category}' n'est pas 'actor', 'action', 'reason', 'source', 'welcome' ou 'sentence`;
     }
 
-    addReason(message){
-        const reason = message.content.slice(this.commandAddReason.length);
-        complotDB.addReason(reason);
-        message.reply(`"${reason}" added to reasons`);
+    async add(category, content) {
+        const list = complotDB.get(category);
+        if(list === null){
+            return wrongCatMessage(category);
+        }
+        list.push(content);
+
+        await this.baseInfo.updateBase(category);
+
+        complotDB.saveFile();
+
+        return `'${content}' a été ajouté à '${category}'`; 
     }
 
-    showList(message){
-        message.reply(complotDB.toString());
+    async remove(category, indexes) {
+        const list = complotDB.get(category);
+        if(list === null){
+            return wrongCatMessage(category);
+        }
+        const wrongIndexes = indexes.filter(index => index < 0 || index >= list.length);
+
+        console.log(list);
+        console.log(list.length);
+        console.log(wrongIndexes);
+
+        if(wrongIndexes.length > 0) return `${wrongIndexes.join(',')} invalides pour '${category}'`;
+
+        const newList = list.filter((_, index) => !indexes.includes(index));
+        const removedItems = list.filter((_, index) => indexes.includes(index)).map((e) => `'${e}'`).join(', ');
+
+        list.splice(0); //Empty
+        list.push(...newList);
+
+        await this.baseInfo.updateBase(category);
+
+        await this.sendCategory(category);
+
+        complotDB.saveFile();
+
+        return `Removed : ${removedItems}`;
+    }
+
+
+    #toInteger(stringList) {
+        const res = stringList.map((element, index) => {
+          const value = parseInt(element, 10);
+          if (isNaN(value)) {
+            throw new Error(`Not a number: ${element}.`);
+          }
+          return value;
+        });
+      
+        return res;
+      }
+
+    async sendList() {
+        const allCats = Object.values(Category);
+        for(let cat of allCats) {
+            this.sendCategory(cat);
+        }
+    }
+
+    async sendCategory(category){
+        let allMessages = complotDB.categoryToSplitMessage(category).map(el => '```' + el + '```');
+        for(let message of allMessages){
+            await this.adminChan.send(message);
+        }
     }
 }
 
diff --git a/commands/InformeMoi.js b/commands/InformeMoi.js
index 33e6893..477bb8e 100644
--- a/commands/InformeMoi.js
+++ b/commands/InformeMoi.js
@@ -1,6 +1,7 @@
 
 const complotDB = require('../database/ComplotDB.js');
 const channelsID = require('../channels_conf.json');
+const {Category} = require('../database/Category.js');
 
 
 class InformeMoi{
@@ -14,12 +15,12 @@ class InformeMoi{
         this.actionRE = new RegExp('<action>', 'gi'); 
     }
 
-    fillAllRandomObject(sentence, regularExpr, randomMethode){
+    fillAllRandomObject(sentence, regularExpr, category){
         const matches = sentence.matchAll(regularExpr);
         let objectString = "";
         let newSentence = sentence;
         for(let match of matches){
-            objectString = randomMethode();
+            objectString = complotDB.getRandom(category);
             newSentence = newSentence.replace(match, objectString);
         }
         
@@ -27,21 +28,21 @@ class InformeMoi{
     }
 
     getRandomSentenceFilled(sentence){
-        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 = this.fillAllRandomObject(sentence, this.actorRE, Category.ACTOR);
+        sentence = this.fillAllRandomObject(sentence, this.actionRE, Category.ACTION);
+        sentence = this.fillAllRandomObject(sentence, this.reasonRE, Category.REASON);
+        sentence = this.fillAllRandomObject(sentence, this.sourceRE, Category.SOURCE);
         
         sentence = sentence.replaceAll(this.wantRE, 'veut'); /**Todo, change */
         return sentence;
     }
 
     getRandomComplot(){
-        return this.getRandomSentenceFilled(complotDB.getRandomSentence());
+        return this.getRandomSentenceFilled(complotDB.getRandom(Category.SENTENCE));
     }
 
     getRandomWelcome(){
-        return this.getRandomSentenceFilled(complotDB.getRandomWelcome());
+        return this.getRandomSentenceFilled(complotDB.getRandom(Category.WELCOME));
     }
 
     sayWelcome(userID){
diff --git a/database/BaseInfo.js b/database/BaseInfo.js
new file mode 100644
index 0000000..f10535e
--- /dev/null
+++ b/database/BaseInfo.js
@@ -0,0 +1,81 @@
+const channelsID = require('../channels_conf.json');
+const complotDB = require('./ComplotDB.js');
+const {Category} = require('./Category.js');
+
+class BaseInfo{
+    constructor(client){
+        this.client = client;
+        this.#resetStoredMessages();
+        this.channelBase = this.client.channels.cache.get(channelsID.base);
+    }
+
+    #resetStoredMessages() {
+        this.infoMessagesActor = [];
+        this.infoMessagesReason = [];
+        this.infoMessagesAction = [];
+        this.infoMessagesSource = [];
+        this.infoMessagesSentence = [];
+    }
+
+    getInfoMessageFromCategory(category){
+        switch(category){
+            case Category.ACTION : return this.infoMessagesAction;
+            case Category.REASON : return this.infoMessagesReason;
+            case Category.SENTENCE : return this.infoMessagesSentence;
+            case Category.SOURCE : return this.infoMessagesSource;
+            case Category.ACTOR : return this.infoMessagesActor;
+        }
+        return null;
+    }
+
+
+    async initAllBase(){
+        const cats = [
+            Category.ACTOR, Category.ACTION, Category.REASON, Category.SOURCE, Category.SENTENCE
+        ];
+
+        await this.deleteAllMessageInfo();
+
+        for(let category of cats){
+            const splitMessages = complotDB.categoryToSplitMessage(category).map(el => '```' + el + '```');
+            for(let messagePart of splitMessages){
+                this.getInfoMessageFromCategory(category).push(await this.channelBase.send(messagePart));
+            }
+        }
+    }
+
+    async updateBase(category){   
+        if (!(this.infoMessagesActor instanceof Array) || this.infoMessagesActor.length === 0) {
+            this.initAllBase();
+        }else{
+            const infoMessages = this.getInfoMessageFromCategory(category);
+            const splitMessages = complotDB.categoryToSplitMessage(category).map(el => '```' + el + '```');
+            // If we had more messages before the update, we get rid of them here
+            infoMessages.splice(splitMessages.length)
+            // If in the opposite we have more messages now, we re-send everything
+            if (splitMessages.length > infoMessages.length) {
+                this.#resetStoredMessages();
+                return await this.updateBase(category);
+            }
+            // Now we edit!
+            for (let i = 0; i < splitMessages.length; i++)
+                infoMessages[i].edit(splitMessages[i]);
+        }
+    }
+
+    async deleteAllMessageInfo(){
+        let messages = await this.channelBase.messages.fetch();
+        let workers = [];
+        messages.forEach(m=>{
+            workers.push(m.delete());
+        });
+        try{
+            await Promise.all(workers);
+        }catch(e){
+            console.error(e);
+        }
+    }
+
+}
+
+module.exports = BaseInfo;
diff --git a/database/Category.js b/database/Category.js
new file mode 100644
index 0000000..698a2d4
--- /dev/null
+++ b/database/Category.js
@@ -0,0 +1,20 @@
+const Category = {
+    ACTION : 'action',
+    REASON : 'reason',
+    ACTOR : 'actor',
+    SOURCE : 'source',
+    SENTENCE : 'sentence',
+    WELCOME : 'welcome'
+};
+
+
+function stringToCategory(cat){
+    cat = cat.toLowerCase();
+    return Object.values(Category).includes(cat) ? cat : null;
+}
+
+module.exports = 
+{
+    Category,
+    stringToCategory
+};
\ No newline at end of file
diff --git a/database/ComplotDB.js b/database/ComplotDB.js
index dab40e4..cc6389d 100644
--- a/database/ComplotDB.js
+++ b/database/ComplotDB.js
@@ -1,4 +1,6 @@
 const fs = require('fs');
+const {Category} = require('./Category');
+
 
 class ComplotDB{
     constructor(){
@@ -12,77 +14,33 @@ class ComplotDB{
         this.readFile();
     }
 
-    addSentence(sentence){
-        this.sentences.push(sentence);
-        this.saveFile();
-    }
-
-    addSource(source){
-        this.sources.push(source);
+    add(category, content){
+        this.get(category).push(content);
         this.saveFile();
     }
 
-    addActor(actor){
-        this.actors.push(actor);
-        this.saveFile();
-    }
-
-    addAction(action){
-        this.actions.push(action);
-        this.saveFile();
-    }
-
-    addReason(reason){
-        this.reasons.push(reason);
-        this.saveFile();
-    }
-
-    getAllActors(){
-        return this.actors;
-    }
-
-    getAllActions(){
-        return this.actions;
-    }
-
-    getAllReasons(){
-        return this.reasons;
-    }
-
-    getAllWelcome(){
-        return this.welcome;
-    }
-
-    #getRandomItem(liste){
-        return liste[Math.floor(Math.random()*liste.length)];
-    }
-
-    getRandomActor(){
-        return this.#getRandomItem(this.actors);
-    }
-
-    getRandomAction(){
-        return this.#getRandomItem(this.actions);
-    }
-
-    getRandomReason(){
-        return this.#getRandomItem(this.reasons);
-    }
-
-    getRandomSource(){
-        return this.#getRandomItem(this.sources);
-    }
+    get(category){
+        switch (category){
+            case Category.ACTION : return this.actions;
+            case Category.REASON : return this.reasons;
+            case Category.SENTENCE : return this.sentences;
+            case Category.WELCOME : return this.welcome;
+            case Category.SOURCE : return this.sources;
+            case Category.ACTOR : return this.actors;
+        }
 
-    getRandomSentence(){
-        return this.#getRandomItem(this.sentences);
+        return null;
     }
 
-    getRandomWelcome(){
-        return this.#getRandomItem(this.welcome);
+    getRandom(category){
+        const list = this.get(category);
+        return list[Math.floor(Math.random()*list.length)];
     }
 
-    #enumListString(list){
-        let string = '';
+    categoryToString(category){
+        const list = this.get(category);
+        const title = category.charAt(0).toUpperCase() + category.slice(1);
+        let string = `======== ${title} =========\n`;
         for(let i = 0; i < list.length; i++){
             string += `${i} - ${list[i]}\n`;
         }
@@ -90,34 +48,22 @@ class ComplotDB{
         return string;
     }
 
-    listToString(list, title){
-        let content = `======== ${title} =========\n`;
-        content += this.#enumListString(list);
-        return content;
-    }
+    categoryToSplitMessage(category) {
+        const text = this.categoryToString(category);
+        
+        let textLines = text.split("\n");
+        let splitArray = [];
+        let currentTextPart = "";
 
-    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');
-    }
+        for (let line of textLines) {
+            if ((currentTextPart + line).length > 1950) {
+                splitArray.push(currentTextPart);
+                currentTextPart = line;
+            } else currentTextPart += ("\n" + line);
+        }
 
-    toString(){
-        return 'See Base du bot...';
+        splitArray.push(currentTextPart);
+        return splitArray;
     }
 
     readFile(){
diff --git a/index.js b/index.js
index 0cab476..38b3a18 100644
--- a/index.js
+++ b/index.js
@@ -3,6 +3,8 @@ const {token, clientId} = require('./config.json');
 
 const CommandParser = require('./commands/CommandParser.js');
 const VoteParser = require('./vote/VoteParser');
+const BaseInfo = require('./database/BaseInfo.js');
+
 
 const client = new Client({
   intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_MEMBERS],
@@ -11,10 +13,12 @@ const client = new Client({
 
 let parser = null;
 let voteParser = null;
+let baseInfo = null;
 
 client.once('ready', () => {
-  voteParser = new VoteParser(client);
-  parser = new CommandParser(client, voteParser);
+  baseInfo = new BaseInfo(client);
+  voteParser = new VoteParser(client, baseInfo);
+  parser = new CommandParser(client, voteParser, baseInfo);
   console.log('Ready!');
 
 });
diff --git a/vote/VoteParser.js b/vote/VoteParser.js
index abe3e63..6ffd954 100644
--- a/vote/VoteParser.js
+++ b/vote/VoteParser.js
@@ -1,40 +1,24 @@
 const channelsID = require('../channels_conf.json');
 const complotDB = require('../database/ComplotDB.js');
+const {Category} = require('../database/Category.js');
 
-const CATEGORY = {
-    ACTION : 0,
-    REASON : 1,
-    ACTOR : 2,
-    SOURCE : 3,
-    SENTENCE : 4
-};
 
 class VoteParser{
     
-    constructor(client){
+    constructor(client, baseInfo){
+        this.baseInfo = baseInfo;
         this.client = client;
         this.upVote = '👍';
         this.score = 3;
         this.categories = new Map([
-            [channelsID.actor, CATEGORY.ACTOR],
-            [channelsID.reason, CATEGORY.REASON],
-            [channelsID.action, CATEGORY.ACTION],
-            [channelsID.source, CATEGORY.SOURCE],
-            [channelsID.sentence, CATEGORY.SENTENCE]
+            [channelsID.actor, Category.ACTOR],
+            [channelsID.reason, Category.REASON],
+            [channelsID.action, Category.ACTION],
+            [channelsID.source, Category.SOURCE],
+            [channelsID.sentence, Category.SENTENCE]
         ]);
-
-        this.#resetStoredMessages();
-
-        this.channelBase = this.client.channels.cache.get(channelsID.base);
     }
 
-    #resetStoredMessages() {
-        this.infoMessagesActor = [];
-        this.infoMessagesReason = [];
-        this.infoMessagesAction = [];
-        this.infoMessagesSource = [];
-        this.infoMessagesSentence = [];
-    }
 
     setScore(score) {
         this.score = score;
@@ -67,128 +51,13 @@ class VoteParser{
     async add(message, category){
         let content = this.categoryCase(category, message.content);
         
-        this.addFormatedString(content, category);
+        complotDB.add(category, messageString)
+
         message.delete();
         message.channel.send(`"${content}" ajouté ! \n Par <@${message.author.id}>`);
         
-        this.updateBase(category);
+        this.baseInfo.updateBase(category);
     }
-
-    #splitMessage(text) {
-        let textLines = text.split("\n");
-        let splitArray = [];
-        let currentTextPart = "";
-
-        for (let line of textLines) {
-            if ((currentTextPart + line).length > 1950) {
-                splitArray.push(currentTextPart);
-                currentTextPart = line;
-            } else currentTextPart += ("\n" + line);
-        }
-
-        splitArray.push(currentTextPart);
-        return splitArray;
-    }
-
-    async updateBase(category){
-        // Gosh this fucking code needs to be factored, so many repetitions
-
-        const actor = this.#splitMessage(complotDB.actorToString()).map(el => '```' + el + '```');
-        const action = this.#splitMessage(complotDB.actionToString()).map(el => '```' + el + '```');
-        const reason = this.#splitMessage(complotDB.reasonToString()).map(el => '```' + el + '```');
-        const source = this.#splitMessage(complotDB.sourceToString()).map(el => '```' + el + '```');
-        const sentence = this.#splitMessage(complotDB.sentenceToString()).map(el => '```' + el + '```');
-
-        if (!(this.infoMessagesActor instanceof Array) || this.infoMessagesActor.length === 0) {
-            this.#resetStoredMessages();
-            await this.deleteAllMessageInfo();
-
-            for (let messagePart of actor)
-                this.infoMessagesActor.push(await this.channelBase.send(messagePart));
-            for (let messagePart of action)
-                this.infoMessagesAction.push(await this.channelBase.send(messagePart));
-            for (let messagePart of reason)
-                this.infoMessagesReason.push(await this.channelBase.send(messagePart));
-            for (let messagePart of source)
-                this.infoMessagesSource.push(await this.channelBase.send(messagePart));
-            for (let messagePart of sentence)
-                this.infoMessagesSentence.push(await this.channelBase.send(messagePart));
-        } else {
-            switch (category) {
-                case CATEGORY.ACTOR:
-                    // If we had more messages before the update, we get rid of them here
-                    this.infoMessagesActor.splice(actor.length)
-                    // If in the opposite we have more messages now, we re-send everything
-                    if (actor.length > this.infoMessagesActor.length) {
-                        this.#resetStoredMessages();
-                        return await this.updateBase(category);
-                    }
-                    // Now we edit!
-                    for (let i = 0; i < actor.length; i++)
-                        this.infoMessagesActor[i].edit(actor[i]);
-
-                    break;
-                case CATEGORY.ACTION:
-                    this.infoMessagesAction.splice(action.length)
-                    if (action.length > this.infoMessagesAction.length) {
-                        this.#resetStoredMessages();
-                        return await this.updateBase(category);
-                    }
-                    for (let i = 0; i < action.length; i++)
-                        this.infoMessagesAction[i].edit(action[i]);
-                    break;
-                case CATEGORY.REASON:
-                    this.infoMessagesReason.splice(reason.length)
-                    if (reason.length > this.infoMessagesReason.length) {
-                        this.#resetStoredMessages();
-                        return await this.updateBase(category);
-                    }
-                    for (let i = 0; i < reason.length; i++)
-                        this.infoMessagesReason[i].edit(reason[i]);
-                    break;
-                case CATEGORY.SOURCE:
-                    this.infoMessagesSource.splice(source.length)
-                    if (source.length > this.infoMessagesSource.length) {
-                        this.#resetStoredMessages();
-                        return await this.updateBase(category);
-                    }
-                    for (let i = 0; i < source.length; i++)
-                        this.infoMessagesSource[i].edit(source[i]);
-                    break;
-                case CATEGORY.SENTENCE:
-                    this.infoMessagesSentence.splice(sentence.length)
-                    if (sentence.length > this.infoMessagesSentence.length) {
-                        this.#resetStoredMessages();
-                        return await this.updateBase(category);
-                    }
-                    for (let i = 0; i < sentence.length; i++)
-                        this.infoMessagesSentence[i].edit(sentence[i]);
-                    break;
-            }
-        }
-    }
-
-
-    addFormatedString(messageString, category){
-        switch (category){
-            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;
-        }
-    }
-
-    async deleteAllMessageInfo(){
-
-        let messages = await this.channelBase.messages.fetch();
-        let workers = [];
-        messages.forEach(m=>{
-            workers.push(m.delete());
-        });
-        await Promise.all(workers);
-    }
-
 }
 
 module.exports = VoteParser;
-- 
GitLab