-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.js
49 lines (47 loc) · 1.3 KB
/
lib.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
var vm = require('vm');
var fs = require('fs');
module.exports = {
addPlugins: function (bot, me) {
eventList = [];
var plugins = fs.readdirSync('plugins');
for (i = 0; i < plugins.length; i++) {
var sandbox = {
bot: bot,
vm: vm,
console: console,
eventList: eventList,
fs: fs,
reload: me,
require: require
};
try {
vm.runInNewContext(fs.readFileSync('plugins/' + plugins[i]), sandbox);
eventList.push(Array(sandbox.listen, sandbox.process));
bot.commandList.push(sandbox.listen);
console.log('Added Script %s', plugins[i]);
} catch (err) {
console.log("error in script: %s", err);
}
}
return eventList;
},
secToTime: function (sec) {
var hr = Math.floor(sec / 3600);
var min = Math.floor((sec - (hr * 3600))/60);
sec -= ((hr * 3600) + (min * 60));
sec += ''; min += '';
while (min.length < 2) {min = '0' + min;}
while (sec.length < 2) {sec = '0' + sec;}
hr = (hr)?hr+':':'';
return hr + min + ':' + sec;
},
floodControl: function(bot, to, cmdString) {
bot.cmd[to]++;
var timer = setTimeout(function () {
bot.cmd[to]--;
console.log('Flood: ' + bot.cmd[to] + ' ' + JSON.stringify(this));
}, 1500 + bot.cmd[to] * 1000);
timer.cmd = cmdString;
return (bot.cmd[to] <= 5);
}
};