forked from TATDK/LiteBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.js
More file actions
123 lines (121 loc) · 4.9 KB
/
run.js
File metadata and controls
123 lines (121 loc) · 4.9 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var plugAPI = require('plugapi');
var Utils = require('./Utils.js');
var util = require('util')
var config = require('./config.json');
var bot = new plugAPI(config.auth);
var lastCommand = {};
var startupTime = Date.now();
bot.connect(config.room);
bot.preCommandHandler = function(data) {
if (lastCommand[data.fromID] !== undefined) {
if (lastCommand[data.fromID] > Date.now() - 2e3)
return false;
}
lastCommand[data.fromID] = Date.now();
return true;
};
bot.on(plugAPI.messageTypes.ROOM_JOIN, function(roomName) {
bot.log('Joined Room', roomName);
}).on('command:shutdown', function(data) {
data.havePermission(bot.ROLE.COHOST, function() {
bot.close();
process.exit(0);
});
}).on('command:move', function(data) {
data.havePermission(bot.ROLE.MANAGER, function() {
if (data.args.length > 2) {
var userID = data.args[0].id;
if (userID !== undefined) {
var pos = ~~data.args[1];
if (!isNaN(pos) && pos > 0 && pos < 50) {
bot.moderateMoveDJ(userID, pos);
} else bot.sendChat('Missing position');
} else bot.sendChat('Missing user');
} else bot.sendChat('Missing parameters');
});
}).on('command:skip', function(data) {
if (bot.getDJ() === null) return;
data.havePermission(bot.ROLE.BOUNCER, function() {
bot.moderateForceSkip();
});
}).on('command:lockskip', function(data) {
if (bot.getDJ() === null) return;
data.havePermission(bot.ROLE.MANAGER, function() {
var userID = bot.getDJ().id;
var executeSkip = function() {
bot.moderateForceSkip(function() {
bot.moderateLockBooth(false, false, function() {
bot.moderateMoveDJ(userID, 1);
});
});
};
if (!bot.moderateLockBooth(true, false, executeSkip))
executeSkip();
});
}).on('command:ban', function(data) {
data.havePermission(bot.ROLE.MANAGER, function() {
if (data.args.length > 2) {
var userID = data.args[0].id;
if (userID !== undefined) {
var duration = data.args[1].toLowerCase();
if (['hour', 'day', 'perma'].indexOf(duration) > -1) {
bot.moderateBanUser(userID, 0, duration == 'hour' ? bot.BAN.HOUR : duration == 'day' ? bot.BAN.DAY : bot.BAN.PERMA);
} else bot.sendChat('Wrong duration');
} else bot.sendChat('Missing user');
} else bot.sendChat('Missing parameters');
});
}).on('command:kick', function(data) {
data.havePermission(bot.ROLE.MANAGER, function() {
if (data.args.length > 1) {
var userID = data.args[0].id;
if (userID !== undefined) {
bot.moderateBanUser(userID, 0, 60, function() {
bot.moderateUnbanUser(userID);
});
} else bot.sendChat('Missing user');
} else bot.sendChat('Missing parameters');
});
}).on(bot.messageTypes.DJ_ADVANCE, function(data) {
if (data.media !== null) {
bot.getHistory(function(history) {
for (var i in history) {
if (history.hasOwnProperty(i)) {
if (history[i].id == data.media.id) {
bot.moderateForceSkip();
bot.sendChat("/me Song skipped because it was in history!");
}
}
}
});
}
}).on('command:eta', function(data) {
if (bot.getDJ() === null)
return data.respondTimeout('If you join the waitlist now, you would be DJing!', 10);
var a = bot.getDJ().id === data.from.id,
b = bot.getWaitListPosition(data.from.id),
c = 0;
bot.getHistory(function(history) {
for (var i in history) {
if (history.hasOwnProperty(i))
c += Math.min(history[i].info === undefined || history[i].info.duration === 0 ? 240 : history[i].info.duration, config.maxSongLength * 60);
}
c = Math.round(c / history.length);
if (a === true)
return data.respondTimeout('You are already DJing!', 10);
if (b < 0)
return data.respondTimeout(util.format(
'If you join the waitlist now, you would be DJing in about %s!',
Utils.secondsToTime(bot.getWaitList().length * c + bot.getTimeRemaining())
), 10);
return data.respondTimeout(util.format(
'You are in the waitlist %d of %d, you will be DJing in about %s!',
b + 1,
bot.getWaitList().length,
Utils.secondsToTime((b + 1) * c + bot.getTimeRemaining())
), 10);
});
}).on('command:info', function(data) {
data.respond('Bot build on top of LiteBot by TAT');
}).on('command:uptime', function() {
data.respond('Bot have been running for ' + Utils.secondsToTime((Date.now() - startupTime) / 1e3) + '.');
});