-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.js
43 lines (40 loc) · 1.54 KB
/
functions.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
function toConsole(message_type, user, channel, message) {
var d = new Date();
var date = ("0" + d.getDate()).slice(-2) + "/" + ("0" + (d.getMonth() + 1)).slice(-2) + "/" + d.getFullYear() + " @ " + ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2) + ":" + ("0" + d.getSeconds()).slice(-2);
if (channels[channel] != null) {
var chan = '#' + channels[channel];
} else {
var chan = "private";
}
switch (message_type) {
case 'system':
console.log(c.cyan(date) + ' ' + c.green('[*]') + c.white(' ' + message));
break;
case 'message':
console.log(c.cyan(date) + ' ' + c.green('[*]') + c.white(' ' + chan + ':<' + users[user].realname + ' (' + users[user].username + ')> ' + message));
break;
case 'bot':
bot.postMessage(channel, message, params);
console.log(c.cyan(date) + ' ' + c.green('[*]') + c.white(' ' + chan + ':<Bot> ' + message));
break;
}
}
function loadCommands(reload = false) {
fs.readdirSync('commands/').forEach(function(file) {
if (file.endsWith('.js') && !file.endsWith('.min.js')) {
eval(fs.readFileSync('commands/' + file) + '');
}
})
}
function flushMarkovCache() {
toConsole('system', '', '', 'Flushing Markov Cache to file');
// Move cache to temp storage and then wipe the live one
var markovFlushCache = markovCache;
markovCache = [];
for (var x in markovFlushCache) {
fs.appendFileSync('markov.txt', markovFlushCache[x] + '\n');
}
toConsole('system', '', '', 'Flush Completed - ' + markovFlushCache.length + ' lines flushed');
// Clean memory
markovFlushCache = null;
}