2019-02-08 18:59:18 +01:00
|
|
|
exports.random = function (text, message) {
|
|
|
|
// Generate a random number
|
|
|
|
function randNumber(file) {
|
|
|
|
let Rand = Math.floor((Math.random() * file.length) + 1);
|
|
|
|
return Rand;
|
|
|
|
}
|
2019-03-29 05:21:58 +01:00
|
|
|
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
fs.readdirSync('./dictionary/').forEach(file => {
|
|
|
|
file = file.slice(0, -5);
|
|
|
|
const dictionary = require(`./dictionary/${file}`);
|
|
|
|
const re = new RegExp('\\[' + file + '\\]');
|
|
|
|
do {
|
|
|
|
text = text.replace(re, dictionary[randNumber(dictionary)]);
|
|
|
|
} while(text.includes(`[${file}]`));
|
|
|
|
return text;
|
|
|
|
});
|
|
|
|
|
2019-02-08 18:59:18 +01:00
|
|
|
do {
|
2019-02-09 01:25:33 +01:00
|
|
|
text = text.replace(/\[member\]/g, message.guild.members.random().user.username);
|
|
|
|
text = text.replace(/\[memberRand\]/, message.guild.members.random().user.username);
|
2019-02-08 18:59:18 +01:00
|
|
|
text = text.replace(/\[number\]/, Math.floor((Math.random() * 9) + 1));
|
2019-02-08 19:45:01 +01:00
|
|
|
text = text.replace(/\[author\]/, message.author.username);
|
2019-02-08 20:01:24 +01:00
|
|
|
text = text.replace(/\[kick\]/, ' ');
|
|
|
|
text = text.replace(/\[ban\]/, ' ');
|
2019-04-05 19:47:06 +02:00
|
|
|
text = text.replace(/\[delete\]/, ' ');
|
2019-02-10 02:06:57 +01:00
|
|
|
text = text.replace(/\{n\}/, '\n');
|
2019-02-08 18:59:18 +01:00
|
|
|
// Verify if it replaced everything
|
2019-04-05 19:47:06 +02:00
|
|
|
} while( text.includes('[member]') || text.includes('[memberRand]') || text.includes('[number]') || text.includes('[author]') || text.includes('[kick]') || text.includes('[ban]') || text.includes('{n}' || text.includes('[delete]')));
|
2019-02-08 18:59:18 +01:00
|
|
|
|
|
|
|
return text;
|
2019-02-17 20:15:23 +01:00
|
|
|
};
|