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",
"./emotes" : "emotes",
"./chat" : "chat",
"./drink" : "drink",
"./filters" : "filters",
"./customization" : "customization",
"./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));
};
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();
}