-
Adrien NUNES a rédigéAdrien NUNES a rédigé
CommandPourquoi.js 1,17 Kio
const complotDB = require('../database/ComplotDB.js');
const {Category} = require('../database/Category.js');
class CommandPourquoi{
constructor(client){
this.client = client;
this.sentences = ["Sûrement pour <why>...", "Afin de <why>", "Bah pour <why> !", "J'pense que c'est pour <why> ??", "Sans aucun doute, <why>.", "C'est simplement afin de <why>.", "Bah, pour <why>.", "Bah pour <why> connard", "Mmmh p'tetre pour <why> ?"];
this.pourquoiRegExp = new RegExp('([^a-z]|^)pourquoi[^a-z]', 'i'); /**'pourquoi' pas dans un mot */
}
getRandomPourquoi(){
const reason = complotDB.getRandom(Category.REASON);
return this.sentences[Math.floor(Math.random()*this.sentences.length)].replace('<why>', reason);
}
parse(message){
if(this.shouldRespond(message)){
message.reply(this.getRandomPourquoi());
}
}
shouldRespond(message){
const resRE = message.content.match(this.pourquoiRegExp);
if(resRE){
return message.content.slice(resRE.index).includes('?'); /**Contient un '?' après le ' qui ' */
}
return false;
}
}
module.exports = CommandPourquoi;