Allow limiting # items per user
This commit is contained in:
parent
084b1cf16f
commit
e13e695077
5 changed files with 36 additions and 3 deletions
|
|
@ -24,7 +24,8 @@ function OptionsModule(channel) {
|
|||
password: false, // Channel password (false -> no password required for entry)
|
||||
allow_dupes: false, // Allow duplicate videos on the playlist
|
||||
torbanned: false, // Block connections from Tor exit nodes
|
||||
allow_ascii_control: false // Allow ASCII control characters (\x00-\x1f)
|
||||
allow_ascii_control: false,// Allow ASCII control characters (\x00-\x1f)
|
||||
playlist_max_per_user: 0 // Maximum number of playlist items per user
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -254,6 +255,13 @@ OptionsModule.prototype.handleSetOptions = function (user, data) {
|
|||
this.opts.allow_ascii_control = Boolean(data.allow_ascii_control);
|
||||
}
|
||||
|
||||
if ("playlist_max_per_user" in data && user.account.effectiveRank >= 3) {
|
||||
var max = parseInt(data.playlist_max_per_user);
|
||||
if (!isNaN(max) && max >= 0) {
|
||||
this.opts.playlist_max_per_user = max;
|
||||
}
|
||||
}
|
||||
|
||||
this.channel.logger.log("[mod] " + user.getName() + " updated channel options");
|
||||
this.sendOpts(this.channel.users);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ const DEFAULT_PERMISSIONS = {
|
|||
leaderctl: 2, // Give/take leader
|
||||
drink: 1.5, // Use the /d command
|
||||
chat: 0, // Send chat messages
|
||||
chatclear: 2 // Use the /clear command
|
||||
chatclear: 2, // Use the /clear command
|
||||
exceedmaxitems: 2 // Exceed maximum items per user limit
|
||||
};
|
||||
|
||||
function PermissionsModule(channel) {
|
||||
|
|
@ -342,6 +343,10 @@ PermissionsModule.prototype.canUncache = function (actor) {
|
|||
return actor.effectiveRank >= 2;
|
||||
};
|
||||
|
||||
PermissionsModule.prototype.canExceedMaxItemsPerUser = function (actor) {
|
||||
return this.hasPermission(actor, "exceedmaxitems");
|
||||
};
|
||||
|
||||
PermissionsModule.prototype.loadUnregistered = function () {
|
||||
var perms = {
|
||||
seeplaylist: -1,
|
||||
|
|
@ -373,7 +378,8 @@ PermissionsModule.prototype.loadUnregistered = function () {
|
|||
leaderctl: 0, // Give/take leader
|
||||
drink: 0, // Use the /d command
|
||||
chat: 0, // Send chat messages
|
||||
chatclear: 2 // Use the /clear command
|
||||
chatclear: 2, // Use the /clear command
|
||||
exceedmaxitems: 2 // Exceed max items per user
|
||||
};
|
||||
|
||||
for (var key in perms) {
|
||||
|
|
|
|||
|
|
@ -868,6 +868,19 @@ PlaylistModule.prototype._addItem = function (media, data, user, cb) {
|
|||
return qfail("This item is already on the playlist");
|
||||
}
|
||||
|
||||
var usersItems = this.items.findAll(function (item) {
|
||||
return item.queueby.toLowerCase() === user.getLowerName();
|
||||
});
|
||||
|
||||
if (this.channel.modules.options &&
|
||||
this.channel.modules.options.get("playlist_max_per_user") &&
|
||||
usersItems.length >= this.channel.modules.options.get("playlist_max_per_user")) {
|
||||
|
||||
if (!this.channel.modules.permissions.canExceedMaxItemsPerUser(user)) {
|
||||
return qfail("Channel limit exceeded: maximum number of videos per user");
|
||||
}
|
||||
}
|
||||
|
||||
/* Warn about blocked countries */
|
||||
if (media.meta.restricted) {
|
||||
user.socket.emit("queueWarn", {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue