diff --git a/vote/channels_conf.json b/channels_conf.json similarity index 72% rename from vote/channels_conf.json rename to channels_conf.json index 3de59052a83b215e527f4e3d5d668deab7aaef30..d83993856971f7be2b05e2343c74ad7a4c914e99 100644 --- a/vote/channels_conf.json +++ b/channels_conf.json @@ -4,5 +4,6 @@ "reason" : "895047902123143210", "source" : "896855116425072711", "sentence": "896854956286558218", - "base": "895047755800641576" + "base": "895047755800641576", + "welcome": "886264368948445244" } \ No newline at end of file diff --git a/commands/InformeMoi.js b/commands/InformeMoi.js index fe23e3c65cc7aa3db94c1b33055c101340acfe2e..33e689337f268c80a6a07a7a626f58ab97aa1286 100644 --- a/commands/InformeMoi.js +++ b/commands/InformeMoi.js @@ -1,5 +1,7 @@ const complotDB = require('../database/ComplotDB.js'); +const channelsID = require('../channels_conf.json'); + class InformeMoi{ constructor(client){ @@ -24,9 +26,7 @@ class InformeMoi{ return newSentence; } - getRandomComplot(){ - let sentence = complotDB.getRandomSentence(); - + 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)); @@ -36,6 +36,19 @@ class InformeMoi{ return sentence; } + getRandomComplot(){ + return this.getRandomSentenceFilled(complotDB.getRandomSentence()); + } + + getRandomWelcome(){ + return this.getRandomSentenceFilled(complotDB.getRandomWelcome()); + } + + sayWelcome(userID){ + let message = this.getRandomWelcome().replace('<new_user>', `<@${userID}>`); + this.client.channels.cache.get(channelsID.welcome).send(message); + } + parse(message){ if(this.shouldRespond(message)){ message.reply(this.getRandomComplot()); diff --git a/database/ComplotDB.js b/database/ComplotDB.js index 52701b9de70bbdec44bdc5aaca0455b93547848e..1ed291ebf5dd561e6317aaf078448165e264055b 100644 --- a/database/ComplotDB.js +++ b/database/ComplotDB.js @@ -8,6 +8,7 @@ class ComplotDB{ this.reasons = []; this.sentences = []; this.sources = []; + this.welcome = []; this.readFile(); } @@ -48,6 +49,10 @@ class ComplotDB{ return this.reasons; } + getAllWelcome(){ + return this.welcome; + } + #getRandomItem(liste){ return liste[Math.floor(Math.random()*liste.length)]; } @@ -72,6 +77,10 @@ class ComplotDB{ return this.#getRandomItem(this.sentences); } + getRandomWelcome(){ + return this.#getRandomItem(this.welcome); + } + #enumListString(list){ let string = ''; for(let i = 0; i < list.length; i++){ @@ -125,6 +134,7 @@ class ComplotDB{ this.actions = json.actions ? json.actions : []; this.sources = json.sources ? json.sources : []; this.sentences = json.sentences ? json.sentences : []; + this.welcome = json.welcome ? json.welcome : []; }); } @@ -136,6 +146,7 @@ class ComplotDB{ reasons: this.reasons, sources : this.sources, sentences : this.sentences, + welcome: this.welcome, }); fs.writeFile(this.filename, data, (err)=>{ diff --git a/index.js b/index.js index 69c710901ee646745af4bb1ca0e3f368232ce2c0..04de1aaf2042ef70d48868e04a15970a298df47d 100644 --- a/index.js +++ b/index.js @@ -5,7 +5,7 @@ const CommandParser = require('./commands/CommandParser.js'); const complotDB = require('./database/ComplotDB.js'); const VoteParser = require('./vote/VoteParser'); -const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS], +const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_MEMBERS], partials: ['MESSAGE', 'CHANNEL', 'REACTION'] }); let parser = null; @@ -38,4 +38,9 @@ client.on('messageReactionAdd', async (reaction, user) => { } voteParser.parse(reaction.message); }); + + +client.on('guildMemberAdd', member => { + parser.informeMoi.sayWelcome(member.user.id); +}); client.login(token); diff --git a/vote/VoteParser.js b/vote/VoteParser.js index ec3c8b3b07636319f9c716759fbc01e04e87c98c..cc55aca607c56d4da39b4628a3c82b60592a7022 100644 --- a/vote/VoteParser.js +++ b/vote/VoteParser.js @@ -1,4 +1,4 @@ -const channelsID = require('./channels_conf.json'); +const channelsID = require('../channels_conf.json'); const complotDB = require('../database/ComplotDB.js'); const CATEGORY = {