1
0
Fork 0

always choose random word

Commando
Loic Bersier 6 years ago
parent ee36afeaf9
commit 2af5a1e7a7

@ -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);
} }

Loading…
Cancel
Save