-
Notifications
You must be signed in to change notification settings - Fork 12
/
utils.js
73 lines (60 loc) · 1.75 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
var c = require('irc-colors');
var request = require('request');
var fs = require('fs');
var logging = require('./config/logger');
var constants = require('./constants');
var config = require('./config/config');
var cmdcfg = require('./command-config');
exports.isChannel = isChannel;
exports.commandExists = commandExists;
exports.adminCommand = adminCommand;
exports.commandEnabled = commandEnabled;
exports.clearCache = clearCache;
function isChannel(string) {
var channelsArray = config.channels;
if (~string.indexOf(channelsArray)) {
return true;
}
return false;
}
function commandExists(command) {
if (command in cmdcfg) {
return true;
}
return false;
}
function commandEnabled(command) {
if (cmdcfg[command].enabled === 1) {
return true;
}
return false;
}
function adminCommand (nick, command) {
if (!cmdcfg[command].admin) {
return false;
}
return isAdmin(nick, command);
}
function isAdmin(nick, command) {
console.log(command);
console.log(nick);
if (~nick.indexOf(config.admins) ) {
return false;
}
return true;
}
function clearCache(callback) {
fs.readdirSync('./commands/').forEach(function (file) {
delete require.cache[require.resolve('./commands/'+file)];
});
fs.readdirSync('./observers/').forEach(function (file) {
delete require.cache[require.resolve('./observers/'+file)];
});
delete require.cache[require.resolve('./nicks.json')];
delete require.cache[require.resolve('./command-config.json')];
delete require.cache[require.resolve('./greetings.js')];
delete require.cache[require.resolve('./config/config.js')];
//help.buildString();
// a message for the IRC bot to send to the admin user who called !reload
return callback('Commands, Observeres and configs are now reloaded!');
};