-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroullete.js
66 lines (56 loc) · 1.83 KB
/
roullete.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
var lang = require(process.cwd() + '/lang.json');
var auxapi = require(process.cwd() + '/auxapi');
var utils = require(process.cwd() + '/utils/utils');
var histsession = require(process.cwd() + '/utils/histsession');
function roulleteThread(pp) {
var users = histsession.chat.data
.filter(function(data) {
var user = auxapi.users.getCachedUsersByID(data.id);
return roullete.ignore.indexOf(data.id) == -1 && user &&
(pp ? (roullete.bot.getWaitlist() || []).indexOf(data.id) != -1 : user.role == 0);
})
.sort(function(a,b){
if (a.counter > b.counter) return -1; if (a.counter < b.counter) return 1; return 0;
});
if (users.length) {
var target = users.shift();
var user = auxapi.users.getUserByID(target.id);
if (!user) return;
roullete.ignore.push(target.id);
if (!pp) {
roullete.bot.sendChat(utils.replaceString(lang.roullete.lotteryWinner, {
user: user.username
}));
roullete.bot.moveDJ(target.id, 0);
} else {
roullete.bot.sendChat(utils.replaceString(lang.roullete.ppWinner, {
user: user.username
}));
}
} else {
roullete.bot.sendChat(lang.roullete.noUsers);
}
}
var roullete = {
commands: ['roullete'],
cooldown: 5,
lastUsed: 0,
thread: null,
listActivity: {},
bot: null,
ignore: [],
roleRequired: 'manager',
init: function(bot) {
roullete.bot = bot;
clearInterval(roullete.thread);
roullete.thread = setInterval(roulleteThread, 60 * 60 * 1e3);
},
exec: function(bot, chat, data) {
if (data.params.length == 0) {
roullete.init(bot);
}
if (data.params[0] == 'pp')
roulleteThread('pp');
}
};
module.exports = roullete;