From 14bb252a73eea2214708c23e41b24f8d3adb8004 Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 27 Apr 2014 21:15:04 +0000 Subject: [PATCH] Announce module --- modules/announce/announce.js | 38 ++++++++++++++++++++++++++++++++++++ modules/announce/config.json | 10 ++++++++++ 2 files changed, 48 insertions(+) create mode 100644 modules/announce/announce.js create mode 100644 modules/announce/config.json diff --git a/modules/announce/announce.js b/modules/announce/announce.js new file mode 100644 index 0000000..e00a948 --- /dev/null +++ b/modules/announce/announce.js @@ -0,0 +1,38 @@ +/** + * Name: Announce + * Description: Announce things every now and again + */ +var _ = require('underscore')._; + +var announce = function(dbot) { + this.announces = dbot.config.modules.announce.announces; + this.lineCount = 0; + this.lastAnnounce = {}; + _.each(dbot.config.servers, function(v, k) { + this.lastAnnounce[k] = {}; + _.each(this.announces[k], function(announce, channel) { + this.lastAnnounce[k][channel] = announce.distance; + }, this) + }, this); + + this.listener = function(event) { + if(_.has(this.lastAnnounce[event.server], event.channel)) { + this.lastAnnounce[event.server][event.channel]--; + if(this.lastAnnounce[event.server][event.channel] == 0) { + var announce = this.config.announces[event.server][event.channel]; + this.lastAnnounce[event.server][event.channel] = announce.distance; + + dbot.api.quotes.getQuote(announce.category, function(quote) { + if(quote) { + dbot.say(event.server, event.channel, quote); + } + }); + } + } + }.bind(this); + this.on = 'PRIVMSG'; +}; + +exports.fetch = function(dbot) { + return new announce(dbot); +}; diff --git a/modules/announce/config.json b/modules/announce/config.json new file mode 100644 index 0000000..832282b --- /dev/null +++ b/modules/announce/config.json @@ -0,0 +1,10 @@ +{ + "announces": { + "aberwiki": { + "#test": { + "category": "test", + "distance": 1 + } + } + } +}