Update README.md
[KisSync.git] / src / channel / drink.js
blob320e9324abababd7aee64c8c2e645f27c4119bbb
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);
9 this.drinks = 0;
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) {
19 var msg = data.msg;
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]+)/);
24 var count;
25 if (m) {
26 count = parseInt(m[1]);
27 if (isNaN(count) || count < -10000 || count > 10000) {
28 return;
31 msg = msg.replace(m[1], "").trim();
32 if (msg || count > 0) {
33 msg += " drink! (x" + count + ")";
34 } else {
35 this.drinks += count;
36 this.channel.broadcastAll("drinkCount", this.drinks);
37 return cb(null, ChannelModule.DENY);
39 } else {
40 msg = msg.trim() + " drink!";
41 count = 1;
44 this.drinks += count;
45 this.channel.broadcastAll("drinkCount", this.drinks);
46 data.msg = msg;
47 data.meta.addClass = "drink";
48 data.meta.forceShowName = true;
49 cb(null, ChannelModule.PASSTHROUGH);
50 } else {
51 cb(null, ChannelModule.PASSTHROUGH);
55 DrinkModule.prototype.onMediaChange = function () {
56 this.drinks = 0;
57 this.channel.broadcastAll("drinkCount", 0);
60 module.exports = DrinkModule;