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

First Commit

parent
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline #2291 en échec
config.json
/node_modules
Pour connecter le bot, ajouter un fichier config.json avec :
{
"clientId": "<ID>",
"token": "<TOKEN>"
}
const { parse } = require('dotenv');
const InformeMoi = require('./InformeMoi.js');
const DatabaseCommand = require('./DatabaseCommand.js');
class CommandParser{
constructor(client){
this.client = client;
this.informeMoi = new InformeMoi(client);
this.databaseCommand = new DatabaseCommand(client);
}
parse(message){
this.informeMoi.parse(message);
this.databaseCommand.parse(message);
}
}
module.exports = CommandParser;
\ No newline at end of file
const complotDB = require('../database/ComplotDB');
class DatabaseCommand{
constructor(client){
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 ';
}
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);
}
}
}
addActor(message){
const actor = message.content.slice(this.commandAddActor.length);
complotDB.addActor(actor);
message.reply(`"${actor}" added to actors`);
}
addAction(message){
const action = message.content.slice(this.commandAddAction.length);
complotDB.addAction(action);
message.reply(`"${action}" added to actions`);
}
addReason(message){
const reason = message.content.slice(this.commandAddReason.length);
complotDB.addReason(reason);
message.reply(`"${reason}" added to reasons`);
}
showList(message){
message.reply(complotDB.toString());
}
}
module.exports = DatabaseCommand;
\ No newline at end of file
const complotDB = require('../database/ComplotDB.js');
class InformeMoi{
constructor(client){
this.client = client;
this.channels = this.client.channels.cache;
}
getRandomComplot(){
const actor = complotDB.getRandomActor();
const action = complotDB.getRandomAction();
const reason = complotDB.getRandomReason();
const vouloir = actor.startsWith("Les ") ? "veulent" : "veut";
return `${actor} ${vouloir} ${action} pour ${reason} !`;
}
parse(message){
if(this.shouldRespond(message)){
message.reply(this.getRandomComplot());
}
}
shouldRespond(message){
return message.content.toLowerCase().includes("informe moi");
}
}
module.exports = InformeMoi;
\ No newline at end of file
const fs = require('fs');
class ComplotDB{
constructor(){
this.filename = "./database/complot_db.json";
this.actors = [];
this.actions = [];
this.reasons = [];
this.readFile();
}
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;
}
#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);
}
#enumListString(list){
let string = '';
for(let i = 0; i < list.length; i++){
string += `${i} - ${list[i]}\n`;
}
string += "\n";
return string;
}
toString(){
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 += "```";
return content;
}
readFile(){
let data = fs.readFile(this.filename, (err, data)=>{
if (err){
console.log("ERROR READ FILE", err);
throw err;
}
const json = JSON.parse(data);
this.actors = json.actors;
this.reasons = json.reasons;
this.actions = json.actions;
});
}
saveFile(){
let data = JSON.stringify({
actors: this.actors,
actions: this.actions,
reasons: this.reasons
});
fs.writeFile(this.filename, data, (err)=>{
if(err){
console.log("SAVE FILE ERROR", err);
}
});
}
}
const instance = new ComplotDB();
module.exports = instance;
\ 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"]}
\ No newline at end of file
const { Client, Intents } = require('discord.js');
const { token, clientId } = require('./config.json');
const CommandParser = require('./commands/CommandParser.js');
const complotDB = require('./database/ComplotDB.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
let parser = null;
client.once('ready', () => {
parser = new CommandParser(client);
console.log('Ready!');
});
client.on("messageCreate", (message)=>{
if(!parser) return;
if(message.author.id !== clientId){
parser.parse(message);
}
});
client.login(token);
Ce diff est replié.
{
"name": "complobot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Michel",
"license": "ISC",
"dependencies": {
"@discordjs/builders": "^0.6.0",
"@discordjs/rest": "^0.1.0-canary.0",
"axios": "^0.21.4",
"discord-api-types": "^0.23.1",
"discord.js": "^13.1.0",
"dotenv": "^10.0.0",
"node": "^16.10.0"
}
}
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