mirror of https://github.com/calzoneman/sync.git
Fix up voteskip a bit
This commit is contained in:
parent
7e9673425d
commit
9d445b8ffd
|
@ -1,3 +1,12 @@
|
||||||
|
Wed Sep 11 22:13 2013 CDT
|
||||||
|
* lib/channel.js, lib/user.js: Remove "afkers" array, replace afkcount
|
||||||
|
with a function that calculates how many users are eligible to
|
||||||
|
voteskip (not AFK + have permission). Check permission before
|
||||||
|
allowing voteskip
|
||||||
|
* lib/api.js: Replace "afkcount" in /api/channels/:channel with
|
||||||
|
voteskip_eligible
|
||||||
|
* www/assets/js/util.js: Add a permissions option for voteskip
|
||||||
|
|
||||||
Wed Sep 11 20:19 2013 CDT
|
Wed Sep 11 20:19 2013 CDT
|
||||||
* lib/poll.js: Add support for hidden polls
|
* lib/poll.js: Add support for hidden polls
|
||||||
* lib/channel.js: Check permissions for viewing hidden polls
|
* lib/channel.js: Check permissions for viewing hidden polls
|
||||||
|
|
|
@ -38,7 +38,7 @@ module.exports = function (Server) {
|
||||||
channel.playlist.current.media.pack() :
|
channel.playlist.current.media.pack() :
|
||||||
{};
|
{};
|
||||||
data.usercount = channel.users.length;
|
data.usercount = channel.users.length;
|
||||||
data.afkcount = channel.afkers.length;
|
data.voteskip_eligible = channel.calcVoteskipMax();
|
||||||
data.users = [];
|
data.users = [];
|
||||||
for(var i in channel.users)
|
for(var i in channel.users)
|
||||||
if(channel.users[i].name !== "")
|
if(channel.users[i].name !== "")
|
||||||
|
|
|
@ -34,7 +34,6 @@ var Channel = function(name, Server) {
|
||||||
// Initialize defaults
|
// Initialize defaults
|
||||||
self.registered = false;
|
self.registered = false;
|
||||||
self.users = [];
|
self.users = [];
|
||||||
self.afkers = [];
|
|
||||||
self.playlist = new Playlist(self);
|
self.playlist = new Playlist(self);
|
||||||
self.position = -1;
|
self.position = -1;
|
||||||
self.drinks = 0;
|
self.drinks = 0;
|
||||||
|
@ -67,6 +66,7 @@ var Channel = function(name, Server) {
|
||||||
pollctl: 1.5,
|
pollctl: 1.5,
|
||||||
pollvote: -1,
|
pollvote: -1,
|
||||||
viewhiddenpoll: 1.5,
|
viewhiddenpoll: 1.5,
|
||||||
|
voteskip: -1,
|
||||||
mute: 1.5,
|
mute: 1.5,
|
||||||
kick: 1.5,
|
kick: 1.5,
|
||||||
ban: 2,
|
ban: 2,
|
||||||
|
@ -842,9 +842,6 @@ Channel.prototype.userLeave = function(user) {
|
||||||
var idx = this.users.indexOf(user);
|
var idx = this.users.indexOf(user);
|
||||||
if(idx >= 0 && idx < this.users.length)
|
if(idx >= 0 && idx < this.users.length)
|
||||||
this.users.splice(idx, 1);
|
this.users.splice(idx, 1);
|
||||||
idx = this.afkers.indexOf(user.name.toLowerCase());
|
|
||||||
if(idx >= 0 && idx < this.afkers.length)
|
|
||||||
this.afkers.splice(idx, 1);
|
|
||||||
this.checkVoteskipPass();
|
this.checkVoteskipPass();
|
||||||
this.broadcastUsercount();
|
this.broadcastUsercount();
|
||||||
if(user.name != "") {
|
if(user.name != "") {
|
||||||
|
@ -1194,9 +1191,21 @@ Channel.prototype.broadcastChatFilters = function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Channel.prototype.calcVoteskipMax = function () {
|
||||||
|
var self = this;
|
||||||
|
// good ol' map-reduce
|
||||||
|
return self.users.map(function (u) {
|
||||||
|
if (!self.hasPermission(u, "voteskip"))
|
||||||
|
return 0;
|
||||||
|
return u.meta.afk ? 0 : 1;
|
||||||
|
}).reduce(function (a, b) {
|
||||||
|
return a + b;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
Channel.prototype.broadcastVoteskipUpdate = function() {
|
Channel.prototype.broadcastVoteskipUpdate = function() {
|
||||||
var amt = this.voteskip ? this.voteskip.counts[0] : 0;
|
var amt = this.voteskip ? this.voteskip.counts[0] : 0;
|
||||||
var count = this.users.length - this.afkers.length;
|
var count = this.calcVoteskipMax();
|
||||||
var need = this.voteskip ? Math.ceil(count * this.opts.voteskip_ratio) : 0;
|
var need = this.voteskip ? Math.ceil(count * this.opts.voteskip_ratio) : 0;
|
||||||
for(var i = 0; i < this.users.length; i++) {
|
for(var i = 0; i < this.users.length; i++) {
|
||||||
if(Rank.hasPermission(this.users[i], "seeVoteskip") ||
|
if(Rank.hasPermission(this.users[i], "seeVoteskip") ||
|
||||||
|
@ -1740,6 +1749,9 @@ Channel.prototype.tryVoteskip = function(user) {
|
||||||
if(!this.opts.allow_voteskip) {
|
if(!this.opts.allow_voteskip) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!this.hasPermission(user, "voteskip"))
|
||||||
|
return;
|
||||||
// Voteskip = auto-unafk
|
// Voteskip = auto-unafk
|
||||||
user.setAFK(false);
|
user.setAFK(false);
|
||||||
user.autoAFK();
|
user.autoAFK();
|
||||||
|
@ -1758,13 +1770,8 @@ Channel.prototype.checkVoteskipPass = function () {
|
||||||
if(!this.voteskip)
|
if(!this.voteskip)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var count = this.users.length - this.afkers.length;
|
var count = this.calcVoteskipMax();
|
||||||
var need = Math.ceil(count * this.opts.voteskip_ratio);
|
var need = Math.ceil(count * this.opts.voteskip_ratio);
|
||||||
if(this.server.cfg["debug"]) {
|
|
||||||
console.log("afkers=", this.afkers.length);
|
|
||||||
console.log("users =", this.users.length);
|
|
||||||
console.log("DBG", this.voteskip.counts[0], "/", need);
|
|
||||||
}
|
|
||||||
if(this.voteskip.counts[0] >= need)
|
if(this.voteskip.counts[0] >= need)
|
||||||
this.playNext();
|
this.playNext();
|
||||||
|
|
||||||
|
|
|
@ -89,14 +89,9 @@ User.prototype.setAFK = function (afk) {
|
||||||
var chan = this.channel;
|
var chan = this.channel;
|
||||||
this.meta.afk = afk;
|
this.meta.afk = afk;
|
||||||
if(afk) {
|
if(afk) {
|
||||||
if(chan.afkers.indexOf(this.name.toLowerCase()) == -1)
|
|
||||||
chan.afkers.push(this.name.toLowerCase());
|
|
||||||
if(chan.voteskip)
|
if(chan.voteskip)
|
||||||
chan.voteskip.unvote(this.ip);
|
chan.voteskip.unvote(this.ip);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if(chan.afkers.indexOf(this.name.toLowerCase()) != -1)
|
|
||||||
chan.afkers.splice(chan.afkers.indexOf(this.name.toLowerCase()), 1);
|
|
||||||
this.autoAFK();
|
this.autoAFK();
|
||||||
}
|
}
|
||||||
chan.checkVoteskipPass();
|
chan.checkVoteskipPass();
|
||||||
|
|
|
@ -1093,6 +1093,8 @@ function handlePermissionChange() {
|
||||||
|
|
||||||
|
|
||||||
setVisible("#newpollbtn", hasPermission("pollctl"));
|
setVisible("#newpollbtn", hasPermission("pollctl"));
|
||||||
|
$("#voteskip").attr("disabled", !hasPermission("voteskip") ||
|
||||||
|
!CHANNEL.opts.allow_voteskip);
|
||||||
|
|
||||||
$("#pollwrap .active").find(".btn-danger").remove();
|
$("#pollwrap .active").find(".btn-danger").remove();
|
||||||
if(hasPermission("pollctl")) {
|
if(hasPermission("pollctl")) {
|
||||||
|
@ -1598,6 +1600,7 @@ function genPermissionsEditor() {
|
||||||
makeOption("Open/Close poll", "pollctl", modleader, CHANNEL.perms.pollctl+"");
|
makeOption("Open/Close poll", "pollctl", modleader, CHANNEL.perms.pollctl+"");
|
||||||
makeOption("Vote", "pollvote", standard, CHANNEL.perms.pollvote+"");
|
makeOption("Vote", "pollvote", standard, CHANNEL.perms.pollvote+"");
|
||||||
makeOption("View hidden poll results", "viewhiddenpoll", standard, CHANNEL.perms.viewhiddenpoll+"");
|
makeOption("View hidden poll results", "viewhiddenpoll", standard, CHANNEL.perms.viewhiddenpoll+"");
|
||||||
|
makeOption("Voteskip", "voteskip", standard, CHANNEL.perms.voteskip+"");
|
||||||
|
|
||||||
addDivider("Moderation");
|
addDivider("Moderation");
|
||||||
makeOption("Mute users", "mute", modleader, CHANNEL.perms.mute+"");
|
makeOption("Mute users", "mute", modleader, CHANNEL.perms.mute+"");
|
||||||
|
|
Loading…
Reference in New Issue