always choose random word

This commit is contained in:
Loic Bersier 2018-11-28 17:09:24 +01:00
parent ee36afeaf9
commit 2af5a1e7a7

View file

@ -24,21 +24,25 @@ module.exports = class RandomCommand extends Command {
if(blacklistJson[message.author.id])
return blacklist(blacklistJson[message.author.id] , message)
// Load all the different files
const verb = require('../../dictionary/verbs.json')
const noun = require('../../dictionary/nouns.json')
const adverb = require('../../dictionary/adjectives.json')
const adjective = require('../../dictionary/adverbs.json')
// Generate a random number for each files
let verbRand = Math.floor((Math.random() * verb.length) + 1);
let nounRand = Math.floor((Math.random() * noun.length) + 1);
let adverbRand = Math.floor((Math.random() * adverb.length) + 1);
let adjectiveRand = Math.floor((Math.random() * adjective.length) + 1);
// Generate a random number
function randNumber(file) {
let Rand = Math.floor((Math.random() * file.length) + 1);
return Rand;
}
// Replace with a random word from the json
text = text.replace('[verb]', verb[verbRand])
text = text.replace('[adverb]', adverb[adverbRand])
text = text.replace('[noun]', noun[nounRand])
text = text.replace('[adjective]', adjective[adjectiveRand])
do {
text = text.replace(/\[verb\]/, verb[randNumber(verb)])
text = text.replace(/\[adverb\]/, adverb[randNumber(adverb)])
text = text.replace(/\[noun\]/, noun[randNumber(noun)])
text = text.replace(/\[adjective\]/, adjective[randNumber(adjective)])
} while( text.includes('[verb]') || text.includes('[adverb]') || text.includes('[noun]') || text.includes('[adjective]') )
// Send the final text
message.say(text);
}