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

Add vote system

parent 5c52410d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
const { parse } = require('dotenv');
const InformeMoi = require('./InformeMoi.js'); const InformeMoi = require('./InformeMoi.js');
const DatabaseCommand = require('./DatabaseCommand.js'); const DatabaseCommand = require('./DatabaseCommand.js');
const CommandVoteParser = require('./CommandVoteParser.js');
class CommandParser{ class CommandParser{
constructor(client){ constructor(client, voteParser){
this.client = client; this.client = client;
this.informeMoi = new InformeMoi(client); this.informeMoi = new InformeMoi(client);
this.databaseCommand = new DatabaseCommand(client); this.databaseCommand = new DatabaseCommand(client);
this.commandVoteParser = new CommandVoteParser(voteParser);
} }
parse(message){ parse(message){
this.informeMoi.parse(message); this.informeMoi.parse(message);
this.databaseCommand.parse(message); this.databaseCommand.parse(message);
this.commandVoteParser.parse(message);
} }
} }
......
class CommandVoteParser{
constructor(voteParser){
this.voteParser = voteParser;
this.command = "!complot score ";
this.channel = '892676980699455500'; /**TODO CONF */
}
parse(message){
if(message.channelId === this.channel){
const content = message.content.toLowerCase();
if(content.startsWith(this.command)){
const score = parseInt(content.slice(this.command.length));
if(score > 1){
this.voteParser.setScore(score);
message.reply(`Fait, score à ${score}`);
}
}
}
}
}
module.exports = CommandVoteParser;
\ 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"],"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"]} {"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 \ No newline at end of file
...@@ -3,13 +3,17 @@ const { token, clientId } = require('./config.json'); ...@@ -3,13 +3,17 @@ const { token, clientId } = require('./config.json');
const CommandParser = require('./commands/CommandParser.js'); const CommandParser = require('./commands/CommandParser.js');
const complotDB = require('./database/ComplotDB.js'); const complotDB = require('./database/ComplotDB.js');
const VoteParser = require('./vote/VoteParser');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] }); const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS],
partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
let parser = null; let parser = null;
let voteParser = null;
client.once('ready', () => { client.once('ready', () => {
parser = new CommandParser(client); voteParser = new VoteParser(client);
parser = new CommandParser(client, voteParser);
console.log('Ready!'); console.log('Ready!');
}); });
...@@ -23,4 +27,15 @@ client.on("messageCreate", (message)=>{ ...@@ -23,4 +27,15 @@ client.on("messageCreate", (message)=>{
} }
}); });
client.on('messageReactionAdd', async (reaction, user) => {
if (reaction.partial) {
try {
await reaction.fetch();
} catch (error) {
console.error('Something went wrong when fetching the message:', error);
return;
}
}
voteParser.parse(reaction.message);
});
client.login(token); client.login(token);
const channelsID = require('./channels_conf.json');
const complotDB = require('../database/ComplotDB.js');
const CATEGORY = {
ACTION : 0,
REASON : 1,
ACTOR : 2
};
class VoteParser{
constructor(client){
this.client = client;
this.upVote = '👍';
this.score = 3;
this.categories = new Map([
[channelsID.actor, CATEGORY.ACTOR],
[channelsID.reason, CATEGORY.REASON],
[channelsID.action, CATEGORY.ACTION]
]);
this.infoMessage = null;
this.channelBase = this.client.channels.cache.get(channelsID.base);
}
setScore(score) {
this.score = score;
}
parse(message){
if(this.categories.has(message.channelId)){
const category = this.categories.get(message.channelId);
const reactions = message.reactions.resolve(this.upVote);
if(reactions && reactions.count >= score){
this.add(message, category);
}
}
}
async add(message, category){
let content = message.content;
const char = content.charAt(0);
const reste = content.slice(1);
content = (category === CATEGORY.ACTOR) ? char.toUpperCase() + reste: char.toLowerCase() + reste;
this.addFormatedString(content, category);
message.delete();
message.channel.send(`"${content}" ajouté ! \n Par <@${message.author.id}>`);
const dbString = complotDB.toString();
if(!this.infoMessage){
this.channelBase.send(dbString).then(message =>{
this.infoMessage = message;
});
}else{
await this.deleteAllMessageInfo();
this.infoMessage.edit(dbString);
}
}
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;
}
}
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;
\ No newline at end of file
{
"actor" : "895047791645179944",
"action" : "895047929713266709",
"reason" : "895047902123143210",
"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.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter