Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 94b70c9a096dae718938e0929c44a6a4d54c225b 1 parent 37ac40f
@mmalecki mmalecki authored
Showing with 35 additions and 0 deletions.
  1. +35 −0 lib/listeners/beer.js
View
35 lib/listeners/beer.js
@@ -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' : '')
+ });
+ }
+ });
+};
+
Please sign in to comment.
Something went wrong with that request. Please try again.