1 // TODO: figure out what to do with this module
2 // it serves a very niche use case and is only a core module because of
3 // legacy reasons (early channels requested it before I had criteria
4 // around what to include in core)
5 var ChannelModule
= require("./module");
7 function DrinkModule(_channel
) {
8 ChannelModule
.apply(this, arguments
);
12 DrinkModule
.prototype = Object
.create(ChannelModule
.prototype);
14 DrinkModule
.prototype.onUserPostJoin = function (user
) {
15 user
.socket
.emit("drinkCount", this.drinks
);
18 DrinkModule
.prototype.onUserPreChat = function (user
, data
, cb
) {
20 var perms
= this.channel
.modules
.permissions
;
21 if (msg
.match(/^\/d-?[0-9]*/) && perms
.canCallDrink(user
)) {
22 msg
= msg
.substring(2);
23 var m
= msg
.match(/^(-?[0-9]+)/);
26 count
= parseInt(m
[1]);
27 if (isNaN(count
) || count
< -10000 || count
> 10000) {
31 msg
= msg
.replace(m
[1], "").trim();
32 if (msg
|| count
> 0) {
33 msg
+= " drink! (x" + count
+ ")";
36 this.channel
.broadcastAll("drinkCount", this.drinks
);
37 return cb(null, ChannelModule
.DENY
);
40 msg
= msg
.trim() + " drink!";
45 this.channel
.broadcastAll("drinkCount", this.drinks
);
47 data
.meta
.addClass
= "drink";
48 data
.meta
.forceShowName
= true;
49 cb(null, ChannelModule
.PASSTHROUGH
);
51 cb(null, ChannelModule
.PASSTHROUGH
);
55 DrinkModule
.prototype.onMediaChange = function () {
57 this.channel
.broadcastAll("drinkCount", 0);
60 module
.exports
= DrinkModule
;