From 46b288d6ee76014cce29e02aa6baf6e9ea907739 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Wed, 21 May 2014 08:42:09 -0700 Subject: [PATCH] Fixes --- lib/channel/channel.js | 1 + lib/channel/drink.js | 56 +++++++++++++++++++++++++++++++++++++++++ lib/channel/playlist.js | 31 ++++++++++++++++------- 3 files changed, 79 insertions(+), 9 deletions(-) create mode 100644 lib/channel/drink.js diff --git a/lib/channel/channel.js b/lib/channel/channel.js index f9e22c48..09b53494 100644 --- a/lib/channel/channel.js +++ b/lib/channel/channel.js @@ -108,6 +108,7 @@ Channel.prototype.initModules = function () { "./permissions" : "permissions", "./emotes" : "emotes", "./chat" : "chat", + "./drink" : "drink", "./filters" : "filters", "./customization" : "customization", "./opts" : "options", diff --git a/lib/channel/drink.js b/lib/channel/drink.js new file mode 100644 index 00000000..bb702f43 --- /dev/null +++ b/lib/channel/drink.js @@ -0,0 +1,56 @@ +var ChannelModule = require("./module"); + +function DrinkModule(channel) { + ChannelModule.apply(this, arguments); + this.drinks = 0; +} + +DrinkModule.prototype = Object.create(ChannelModule.prototype); + +DrinkModule.prototype.onUserPostJoin = function (user) { + user.socket.emit("drinkCount", this.drinks); +}; + +DrinkModule.prototype.onUserChat = function (user, data, cb) { + var msg = data.msg; + var perms = this.channel.modules.permissions; + if (msg.match(/^\/d-?[0-9]*/) && perms.canCallDrink(user)) { + msg = msg.substring(2); + var m = msg.match(/^(-?[0-9]+)/); + var count; + if (m) { + count = parseInt(m[1]); + if (isNaN(count) || count < -10000 || count > 10000) { + return; + } + + msg = msg.replace(m[1], "").trim(); + if (msg || count > 0) { + msg += " drink! (x" + count + ")"; + } else { + this.drinks += count; + this.channel.broadcastAll("drinkCount", this.drinks); + return cb(null, ChannelModule.DENY); + } + } else { + msg = msg.trim() + " drink!"; + count = 1; + } + + this.drinks += count; + this.channel.broadcastAll("drinkCount", this.drinks); + data.msg = msg; + data.meta.addClass = "drink"; + data.meta.forceShowName = true; + cb(null, ChannelModule.PASSTHROUGH); + } else { + cb(null, ChannelModule.PASSTHROUGH); + } +}; + +DrinkModule.prototype.onMediaChange = function () { + this.drinks = 0; + this.channel.broadcastAll("drinkCount", 0); +}; + +module.exports = DrinkModule; diff --git a/lib/channel/playlist.js b/lib/channel/playlist.js index 476018c9..d5c3bdfa 100644 --- a/lib/channel/playlist.js +++ b/lib/channel/playlist.js @@ -198,6 +198,21 @@ PlaylistModule.prototype.onUserPostJoin = function (user) { user.socket.typecheckedOn("queuePlaylist", TYPE_QUEUE_PLAYLIST, this.handleQueuePlaylist.bind(this, user)); }; +PlaylistModule.prototype.onUserPart = function (user) { + if (this.leader === user) { + this.channel.broadcastAll("setLeader", ""); + + this.channel.logger.log("[playlist] Resuming autolead"); + if (this.current !== null) { + this.current.media.paused = false; + if (!this._leadInterval) { + this._lastUpdate = Date.now(); + this._leadInterval = setInterval(this._leadLoop.bind(this), 1000); + } + } + } +}; + /** * == Functions for sending various playlist data to users == */ @@ -573,7 +588,7 @@ PlaylistModule.prototype.handleJumpTo = function (user, data) { this.startPlayback(); this.channel.logger.log("[playlist] " + user.getName() + " skipped" + title); - if (old.temp) { + if (old && old.temp) { this._delete(old.uid); } } @@ -754,7 +769,7 @@ PlaylistModule.prototype._delete = function (uid) { if (!item) { return false; } - var next = item.next; + var next = item.next || this.items.first; var success = self.items.remove(uid); @@ -770,9 +785,11 @@ PlaylistModule.prototype._delete = function (uid) { }); } - if (self.current === item) { + if (self.current === item && item !== next) { self.current = next; self.startPlayback(); + } else { + self.current = null; } return success; @@ -1038,13 +1055,9 @@ PlaylistModule.prototype._playNext = function () { var next = this.current.next || this.items.first; if (this.current.temp) { - if (next === this.current) { - next = null; - } + /* The _delete handler will take care of starting the next video */ this._delete(this.current.uid); - } - - if (next) { + } else if (next) { this.current = next; this.startPlayback(); }