This commit is contained in:
Calvin Montgomery 2014-05-21 08:42:09 -07:00
parent b6dcbe4d46
commit 46b288d6ee
3 changed files with 79 additions and 9 deletions

View File

@ -108,6 +108,7 @@ Channel.prototype.initModules = function () {
"./permissions" : "permissions", "./permissions" : "permissions",
"./emotes" : "emotes", "./emotes" : "emotes",
"./chat" : "chat", "./chat" : "chat",
"./drink" : "drink",
"./filters" : "filters", "./filters" : "filters",
"./customization" : "customization", "./customization" : "customization",
"./opts" : "options", "./opts" : "options",

56
lib/channel/drink.js Normal file
View File

@ -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;

View File

@ -198,6 +198,21 @@ PlaylistModule.prototype.onUserPostJoin = function (user) {
user.socket.typecheckedOn("queuePlaylist", TYPE_QUEUE_PLAYLIST, this.handleQueuePlaylist.bind(this, 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 == * == Functions for sending various playlist data to users ==
*/ */
@ -573,7 +588,7 @@ PlaylistModule.prototype.handleJumpTo = function (user, data) {
this.startPlayback(); this.startPlayback();
this.channel.logger.log("[playlist] " + user.getName() + " skipped" + title); this.channel.logger.log("[playlist] " + user.getName() + " skipped" + title);
if (old.temp) { if (old && old.temp) {
this._delete(old.uid); this._delete(old.uid);
} }
} }
@ -754,7 +769,7 @@ PlaylistModule.prototype._delete = function (uid) {
if (!item) { if (!item) {
return false; return false;
} }
var next = item.next; var next = item.next || this.items.first;
var success = self.items.remove(uid); 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.current = next;
self.startPlayback(); self.startPlayback();
} else {
self.current = null;
} }
return success; return success;
@ -1038,13 +1055,9 @@ PlaylistModule.prototype._playNext = function () {
var next = this.current.next || this.items.first; var next = this.current.next || this.items.first;
if (this.current.temp) { if (this.current.temp) {
if (next === this.current) { /* The _delete handler will take care of starting the next video */
next = null;
}
this._delete(this.current.uid); this._delete(this.current.uid);
} } else if (next) {
if (next) {
this.current = next; this.current = next;
this.startPlayback(); this.startPlayback();
} }