Haha-Yes/commands/fun/say.js

51 lines
2.1 KiB
JavaScript
Raw Normal View History

2018-09-18 15:35:06 +02:00
const { Command } = require('discord.js-commando');
2018-11-28 01:35:26 +01:00
const SelfReloadJSON = require('self-reload-json');
const blacklist = require('../../blacklist');
2018-09-18 15:35:06 +02:00
module.exports = class sayCommand extends Command {
constructor(client) {
super(client, {
name: 'say',
2018-11-28 20:27:29 +01:00
aliases: ['repeat'],
2018-09-18 15:35:06 +02:00
group: 'fun',
memberName: 'say',
2018-11-28 20:27:29 +01:00
description: `Repeat the text you send ( can also use [verb] [noun] [adverb] [adjective] [member] and [number] to get random thing )`,
2018-09-18 15:35:06 +02:00
args: [
{
key: 'text',
prompt: 'What do you want me to say',
type: 'string',
}
]
});
}
async run(message, { text }) {
2018-11-28 01:35:26 +01:00
let blacklistJson = new SelfReloadJSON('json/blacklist.json');
if(blacklistJson[message.author.id])
return blacklist(blacklistJson[message.author.id] , message)
2018-11-28 20:27:29 +01:00
// 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
function randNumber(file) {
let Rand = Math.floor((Math.random() * file.length) + 1);
return Rand;
}
// Replace with a random word from the json
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)])
text = text.replace(/\[member\]/, message.guild.members.random().user.username)
2018-11-28 21:53:11 +01:00
text = text.replace(/\[number\]/, Math.floor((Math.random() * 9) + 1))
2018-11-28 20:29:04 +01:00
} while( text.includes('[verb]') || text.includes('[adverb]') || text.includes('[noun]') || text.includes('[adjective]') || text.includes('[member]') || text.includes('[number]') )
2018-11-28 20:27:29 +01:00
// Send the final text
message.say(text);
2018-09-18 15:35:06 +02:00
}
};