forked from AriaHV/juul-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
54 lines (41 loc) · 1.61 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const { readdirSync, statSync, Dirent } = require('fs');
const Discord = require('discord.js');
const { authorId } = require('./config.json');
const getCommands = () => {
const commands = {};
const directories = readdirSync('./commands').filter(x => statSync(`./commands/${x}`).isDirectory());
for (const dir of directories) {
commands[dir] = new Discord.Collection();
const files = readdirSync(`./commands/${dir}`).filter(x => x.endsWith('.js'));
for (const file of files) {
const command = require(`./commands/${dir}/${file}`);
commands[dir].set(command.name, command);
}
}
return commands;
};
const isBotAuthor = (user) => {
return user.id == authorId;
};
const sendResponseCommand = (message, entry, args) => {
const variables = {};
variables['${mentioned}'] = message.mentions.members
.map(member => member.nickname || member.user.username)
.join(', ');
variables['${author}'] = message.member.nickname || message.author.username;
// eslint-disable-next-line no-useless-escape
const matches = entry.embed_description.match(/\$\{\w+\}/g);
let embedDescription = entry.embed_description;
for (const match of matches) {
const value = variables[match];
if (value) embedDescription = embedDescription.replace(match, value);
}
const embed = new Discord.RichEmbed()
.setImage(entry.embed_image)
.setDescription(embedDescription);
return message.channel.send(embed);
};
const getExclusionString = (scope, excluded) => {
return (excluded ? '-' : '+') + ` [${scope}]: ` + (excluded ? 'deny' : 'allow');
};
module.exports = { getCommands, isBotAuthor, sendResponseCommand, getExclusionString };