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]) if(blacklistJson[message.author.id])
return blacklist(blacklistJson[message.author.id] , message) return blacklist(blacklistJson[message.author.id] , message)
// Load all the different files // Load all the different files
const verb = require('../../dictionary/verbs.json') const verb = require('../../dictionary/verbs.json')
const noun = require('../../dictionary/nouns.json') const noun = require('../../dictionary/nouns.json')
const adverb = require('../../dictionary/adjectives.json') const adverb = require('../../dictionary/adjectives.json')
const adjective = require('../../dictionary/adverbs.json') const adjective = require('../../dictionary/adverbs.json')
// Generate a random number for each files // Generate a random number
let verbRand = Math.floor((Math.random() * verb.length) + 1); function randNumber(file) {
let nounRand = Math.floor((Math.random() * noun.length) + 1); let Rand = Math.floor((Math.random() * file.length) + 1);
let adverbRand = Math.floor((Math.random() * adverb.length) + 1); return Rand;
let adjectiveRand = Math.floor((Math.random() * adjective.length) + 1); }
// Replace with a random word from the json // Replace with a random word from the json
text = text.replace('[verb]', verb[verbRand]) do {
text = text.replace('[adverb]', adverb[adverbRand]) text = text.replace(/\[verb\]/, verb[randNumber(verb)])
text = text.replace('[noun]', noun[nounRand]) text = text.replace(/\[adverb\]/, adverb[randNumber(adverb)])
text = text.replace('[adjective]', adjective[adjectiveRand]) 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 // Send the final text
message.say(text); message.say(text);
} }