summaryrefslogtreecommitdiff
path: root/atom-bot
diff options
context:
space:
mode:
Diffstat (limited to 'atom-bot')
-rw-r--r--atom-bot/index.js25
1 files changed, 15 insertions, 10 deletions
diff --git a/atom-bot/index.js b/atom-bot/index.js
index 470786c..7de99bc 100644
--- a/atom-bot/index.js
+++ b/atom-bot/index.js
@@ -34,10 +34,14 @@ var irc = function() {
return new Proxy(IrcClient.prototype, 'irc', channel);
}();
+function log(message) {
+ console.log(('log ' + message).green);
+}
+
var parserOptions = {};
// Config
-var channel = '#bitraf2';
+var channel = '#dynobot';
var feeds = [
// "http://search.twitter.com/search.atom?q=from:AgileBorat",
// "http://search.twitter.com/search.atom?q=from:KongenDin",
@@ -62,15 +66,15 @@ var state = {
var eventEmitter = new events.EventEmitter;
function updateFeed(feedState) {
- console.log("Fetching " + feedState.url);
+ log("Fetching " + feedState.url);
if(feedState.updatingFeed)
- console.log("Already working");
+ log("Already working");
feedState.updatingFeed = true;
parser.parseURL(feedState.url, parserOptions, function(err, feed) {
- console.log("Fetched " + feedState.url + ", status=" + (err ? "failure" : "success"));
+ log("Fetched " + feedState.url + ", status=" + (err ? "failure" : "success"));
if(err) {
- console.log(err);
+ log(err);
return;
}
var newest = processFeed(feed);
@@ -86,7 +90,8 @@ function processFeed(feed) {
// TODO: Use something better than blindparser to parse atom so that
// each entry has an author too to get the full name.
if(typeof feed.items[0] == "undefined") {
- console.log("feed does not contain any items", feed);
+ log("feed does not contain any items");
+ log(feed);
return undefined;
}
var match = /^http:\/\/twitter.com\/([a-zA-Z0-9_]+)\/.*$/.exec(feed.items[0].link)
@@ -104,14 +109,14 @@ eventEmitter.on("feedChanged", function(url, newest) {
state.feeds[url] = newest;
if(state.newest.timestamp >= newest.timestamp) {
- console.log("oold: " + newest.text);
+ log("oold: " + newest.text);
return;
}
/*
*/
var text = newest.author + ": " + newest.text;
- console.log("New topic", newest.timestamp, url, text);
+ log("New topic: " + newest.timestamp + ", url=" + url + ", text=" + text);
state.newest = newest;
/*
if(state.channelTopic != text) {
@@ -122,7 +127,7 @@ eventEmitter.on("feedChanged", function(url, newest) {
});
function setup() {
- console.log("Stopping " + cronJobs.length + " cron jobs");
+ log("Stopping " + cronJobs.length + " cron jobs");
_.each(cronJobs, function(job) { job.stop(); });
cronJobs = [];
_.each(feeds, function(feed) {
@@ -143,7 +148,7 @@ irc.join(channel, function(c) {
});
irc.on('topic', function(channel, topic) {
- console.log("new topic: " + topic);
+ 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).