Permalink
Browse files

[beer] Add basic beer listener (issue #64)

  • Loading branch information...
1 parent 37ac40f commit 94b70c9a096dae718938e0929c44a6a4d54c225b @mmalecki mmalecki committed Oct 14, 2011
Showing with 35 additions and 0 deletions.
  1. +35 −0 lib/listeners/beer.js
View
@@ -0,0 +1,35 @@
+/*
+ *
+ * listeners/beer.js - Event listener for IRC events, providing you with cold
+ * beer
+ *
+ * (c) 2011 Nodejitsu Inc.
+ *
+ */
+
+var beer = module.exports = function () {
+ var self = this;
+
+ self.karma = {};
+
+ self.on('*::gotMessage', function (data) {
+ var re = /(\w+)(\+\+|--)/,
+ res;
+
+ if (res = re.exec(data.text)) {
+ self.karma[res[1]] || (self.karma[res[1]] = 0);
+ if (res[2] == '++') {
+ ++self.karma[res[1]];
+ }
+ else if (res[2] == '--') {
+ --self.karma[res[1]];
+ }
+ return self.emit('sendMsg', {
+ dest: data.to,
+ msg: res[1] + ' has ' + self.karma[res[1]] + ' beer' +
+ ((Math.abs(self.karma[res[1]]) > 1) ? 's' : '')
+ });
+ }
+ });
+};
+

0 comments on commit 94b70c9

Please sign in to comment.