summaryrefslogtreecommitdiff
path: root/atom-bot
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-06-04 13:09:40 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-06-04 13:09:40 +0200
commitdff4a1ffd7cf9ca3097ea0227a82d18184bbca25 (patch)
tree57d6aac3670e1ebd250d80b857e440a36fd51a3c /atom-bot
parent18c5b3ceac115200f994c440b78ceccda9a9862d (diff)
downloaddynobot-irc-dff4a1ffd7cf9ca3097ea0227a82d18184bbca25.tar.gz
dynobot-irc-dff4a1ffd7cf9ca3097ea0227a82d18184bbca25.tar.bz2
dynobot-irc-dff4a1ffd7cf9ca3097ea0227a82d18184bbca25.tar.xz
dynobot-irc-dff4a1ffd7cf9ca3097ea0227a82d18184bbca25.zip
o Updating the atom plugin to the latest API.
Diffstat (limited to 'atom-bot')
-rw-r--r--atom-bot/index.js100
1 files changed, 45 insertions, 55 deletions
diff --git a/atom-bot/index.js b/atom-bot/index.js
index 37d073c..470786c 100644
--- a/atom-bot/index.js
+++ b/atom-bot/index.js
@@ -20,20 +20,37 @@
*/
require('tinycolor');
-var node_irc = require('../node_modules/node-irc/IRC.js')
- , cron = require('cron').CronJob
+var cron = require('cron').CronJob
, parser = require('blindparser')
, events = require('events')
, _ = require('underscore');
+var irc = function() {
+ var Proxy = require('../node_modules/dynobot/proxy');
+ var Channel = require('../node_modules/dynobot/channel');
+ var IrcClient = require('../irc-client.js').IrcClient;
+
+ var channel = new Channel();
+ return new Proxy(IrcClient.prototype, 'irc', channel);
+}();
+
var parserOptions = {};
-var config;
+// Config
+var channel = '#bitraf2';
+var feeds = [
+// "http://search.twitter.com/search.atom?q=from:AgileBorat",
+// "http://search.twitter.com/search.atom?q=from:KongenDin",
+// "http://search.twitter.com/search.atom?q=from:NestenSivJensen",
+ "http://search.twitter.com/search.atom?q=ndc2012"
+// "http://search.twitter.com/search.atom?q=awesome",
+// "http://search.twitter.com/search.atom?q=eurovision",
+];
var cronJobs = [];
var state = {
channelTopic: undefined,
- irc: undefined,
+ topic: undefined,
updatingFeed: false,
feeds: [],
newest: {
@@ -41,35 +58,9 @@ var state = {
text: undefined
}
};
-module.exports.state = state;
var eventEmitter = new events.EventEmitter;
-function startIrc() {
- irc = new node_irc.IRC(config.host, config.port);
- irc.on('raw', function(data) { console.log(data) });
- irc.on('connected', function(server) {
- console.log('Connected to ' + server);
- irc.join(config.channel, function(error) {
- irc.notice(config.channel, 'well hello yall');
- });
- });
- irc.topic = function(channel, topic) {
- irc._socket.write('topic ' + channel + ' :' + topic + '\r\n');
- };
-
- irc.on('topic', function(channel, topic) {
- console.log("new topic: " + topic);
- /* If we're not storing this, it is possible for people to set
- * the topic after the bot has set it and it will persist (until
- * next update from the feed).
- topic = t;
- */
-
- state.channelTopic = topic;
- });
-}
-
function updateFeed(feedState) {
console.log("Fetching " + feedState.url);
if(feedState.updatingFeed)
@@ -77,7 +68,7 @@ function updateFeed(feedState) {
feedState.updatingFeed = true;
parser.parseURL(feedState.url, parserOptions, function(err, feed) {
-// console.log("Fetched " + feedState.url + ", status=" + (err ? "failure" : "success"));
+ console.log("Fetched " + feedState.url + ", status=" + (err ? "failure" : "success"));
if(err) {
console.log(err);
return;
@@ -108,33 +99,33 @@ function processFeed(feed) {
timestamp: feed.items[0].date
};
}
-module.exports.processFeed = processFeed;
eventEmitter.on("feedChanged", function(url, newest) {
state.feeds[url] = newest;
if(state.newest.timestamp >= newest.timestamp) {
-// console.log("oold: " + newest.text);
+ console.log("oold: " + newest.text);
return;
}
+ /*
+ */
var text = newest.author + ": " + newest.text;
console.log("New topic", newest.timestamp, url, text);
state.newest = newest;
- if(config.connect && state.topic != text) {
- irc.topic(config.channel, text);
+ /*
+ if(state.channelTopic != text) {
+ irc.topic(channel, text);
}
-});
-
-eventEmitter.on("configUpdated", function(c) {
- setup();
+ */
+ irc.notice(channel, text);
});
function setup() {
console.log("Stopping " + cronJobs.length + " cron jobs");
_.each(cronJobs, function(job) { job.stop(); });
cronJobs = [];
- _.each(config.feeds, function(feed) {
+ _.each(feeds, function(feed) {
var state = {
url: feed,
updatingFeed: false,
@@ -147,20 +138,19 @@ function setup() {
});
}
-function start(c) {
- config = c;
- startIrc();
- setup();
- if(config.connect) {
- console.log('Connecting to ' + config.host + ':' + config.port);
- irc.connect(config.nick);
- } else {
- console.log('Not connecting to IRC');
- }
-}
+irc.join(channel, function(c) {
+ irc.notice(channel, 'well hello yall: ' + c);
+});
-module.exports.start = start;
+irc.on('topic', function(channel, topic) {
+ console.log("new topic: " + topic);
+ /* If we're not storing this, it is possible for people to set
+ * the topic after the bot has set it and it will persist (until
+ * next update from the feed).
+ topic = t;
+ */
-module.exports.emit = function(config) {
- eventEmitter.emit("configUpdated", config);
-}
+ state.channelTopic = topic;
+});
+
+setup();