From 1150d03474ac0fb563b9e518e01d9e6a88aa8c11 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sun, 28 Jul 2013 17:36:53 -0400 Subject: [PATCH] AFKers don't affect voteskip (#193) --- channel.js | 12 +++++++++++- chatcommand.js | 14 ++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/channel.js b/channel.js index c7bc8494..e16201b1 100644 --- a/channel.js +++ b/channel.js @@ -34,6 +34,7 @@ var Channel = function(name, Server) { // Initialize defaults this.registered = false; this.users = []; + this.afkcount = 0; this.playlist = new Playlist(this); this.library = {}; this.position = -1; @@ -958,6 +959,7 @@ Channel.prototype.broadcastChatFilters = function() { Channel.prototype.broadcastVoteskipUpdate = function() { var amt = this.voteskip ? this.voteskip.counts[0] : 0; var need = this.voteskip ? parseInt(this.users.length * this.opts.voteskip_ratio) : 0; + need -= this.afkcount; for(var i = 0; i < this.users.length; i++) { if(Rank.hasPermission(this.users[i], "seeVoteskip") || this.leader == this.users[i]) { @@ -1536,12 +1538,20 @@ Channel.prototype.tryVoteskip = function(user) { if(!this.opts.allow_voteskip) { return; } + // Voteskip = auto-unafk + if(user.meta.afk) { + user.meta.afk = false; + this.broadcastUserUpdate(user); + this.afkcount--; + } if(!this.voteskip) { this.voteskip = new Poll("voteskip", "voteskip", ["yes"]); } this.voteskip.vote(user.ip, 0); this.broadcastVoteskipUpdate(); - if(this.voteskip.counts[0] >= parseInt(this.users.length * this.opts.voteskip_ratio)) { + var need = parseInt(this.users.length * this.opts.voteskip_ratio); + need -= this.afkcount; + if(this.voteskip.counts[0] >= need) { this.playNext(); } } diff --git a/chatcommand.js b/chatcommand.js index 9c7233b1..bef06d9a 100644 --- a/chatcommand.js +++ b/chatcommand.js @@ -25,6 +25,20 @@ function handle(chan, user, msg, data) { } else if(msg.indexOf("/afk") == 0) { user.meta.afk = !user.meta.afk; + if(user.meta.afk) + chan.afkcount++; + else + chan.afkcount--; + if(chan.voteskip) { + var need = parseInt(chan.users.length * chan.opts.voteskip_ratio); + need -= chan.afkcount; + if(chan.voteskip.counts[0] >= need) { + chan.playNext(); + } + else { + chan.broadcastVoteskipUpdate(); + } + } chan.broadcastUserUpdate(user); } else if(msg.indexOf("/m ") == 0) {