diff --git a/README b/README deleted file mode 100644 index 6b5455f..0000000 --- a/README +++ /dev/null @@ -1,9 +0,0 @@ -afrosdwilsh's IRC manifestation. - -Things it may understand if addressed in the channel: -watch -unwatch -watch on (for ) -unwatch on (for ) - is -I am diff --git a/README.md b/README.md new file mode 100644 index 0000000..bda330c --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +Tree-Bot +========== +afrosdwilsh's IRC manifestation -- IRC bot for watching trees for Mozilla. + +Setup +========== +Requires nodejs. Use npm to install dependencies: +``` +npm install irc shorturl pulse translate +``` + +Usage +========== +To test / emulate single-channel, +```node console.js``` + +To start the actual bot, +```node bot.js``` + +Configurations can be found in sessions.json. Settings are automatically saved. + +You can invite the bot into a channel with +```/invite afrosdwilsh``` +when you're in a particular channel. + + +Available Commands +========== +```watch ``` starts watching a tree + +```unwatch ``` stops watching a tree + +```watch on (for )``` + +```unwatch on (for )``` + +``` is ``` and ```I am ``` set name associations + +```list``` or ```currently``` shows all current user-specific watches + +```help``` displays help file + diff --git a/bot.js b/bot.js index b023efc..8601862 100644 --- a/bot.js +++ b/bot.js @@ -7,7 +7,7 @@ var session = require("./sessionrestore"); // Connect to IRC var kNick = 'afrosdwilsh'; var kAuthorizedUsers = [ - 'sdwilsh', 'robarnold' + 'sdwilsh', 'robarnold', 'samliu' ]; function isAuthorizedUser(user) { diff --git a/channels.js b/channels.js index 2b373b9..47f6eed 100644 --- a/channels.js +++ b/channels.js @@ -14,6 +14,9 @@ var eliza = require("./eliza"); var kIssueTrackerUrl = 'https://github.com/sdwilsh/tree-bot/issues/new'; var treeNames = require('./jsondb')('treenames.json').db; +var kSession = "session.json"; +var sessioninfo = require("./jsondb")(kSession); + function canonicalizeTreeName(name) { if (treeNames.hasOwnProperty(name)) return treeNames[name]; @@ -129,7 +132,7 @@ Channel.prototype = { watcher.on("warning", filterEventsByRev(rev, reporter.warning.bind(reporter, cb))); watcher.on("failure", filterEventsByRev(rev, reporter.failure.bind(reporter, cb))); // Watch for 12 hours - then no more - this.watches.add(key, watcher, 12); + this.watches.add(key, watcher, 12, treeName, rev, who); this.configDidChange(); }, unwatchChangeset: function (treeName, rev, who) { @@ -253,6 +256,23 @@ ChannelController.prototype = { if (this.channel.backend.isAuthorizedUser(from)) updater.restart(); }, + currently: function(from){ + var trees = textutils.naturalJoin(Object.keys(this.channel.trees)); + this.channel.tell(from)("I'm currently watching: {0}", trees); + + this.channel.tell(from)("Listing user-specific watches:"); + var watches = this.channel.watches.show(); + var count = 0; + for (var x in watches){ + this.channel.tell(from)("* Watching revision {0} for {1} on {2}",watches[x].rev,watches[x].name,watches[x].tree); + count++; + } + if(count == 0){ + this.channel.tell(from)("Not watching any user-specific watches!"); + }else{ + this.channel.tell(from)("...and that's all I'm watching right now."); + } + }, handleCommand: function (from, text) { var self = this; function tryCommand(matcher, name) { @@ -286,6 +306,8 @@ ChannelController.prototype = { [/^version$/, "version"], [/^update/, "update"], [/^restart$/, "restart"], + [/^currently$/, "currently"], + [/^list$/, "currently"], ] }; diff --git a/committers.json b/committers.json index 4a59e0c..e563b53 100644 --- a/committers.json +++ b/committers.json @@ -1,6 +1,5 @@ { "mfinkle@mozilla.com": "mfinkle", - "philringalda@gmail.com": "philor", "Ms2ger@gmail.com": "Ms2ger", "dgottwald@mozilla.com": "dao", "mwu@mozilla.com": "mwu", @@ -42,11 +41,11 @@ "mventnor@mozilla.com": "Ventron", "jblandy@mozilla.com": "jimb", "david.humphrey@senecac.on.ca": "humph", - "jmaher@mozilla.com": "jmaher", "tglek@mozilla.com": "taras", "cpearce@mozilla.com": "cpearce", "bturner@mozilla.com": "bent", "honzab.moz@firemni.cz": "mayhemer", "trev.saunders@gmail.com": "tbsaunde", - "bherland@mozilla.com": "bjarne" -} \ No newline at end of file + "bherland@mozilla.com": "bjarne", + "sliu@mozilla.com": "samliu" +} diff --git a/session.json b/session.json index 30110a6..92ccd38 100644 --- a/session.json +++ b/session.json @@ -1,6 +1,13 @@ { "channels": { "": { + "state": { + "trees": [ + "mozilla-central" + ] + } + }, + "#bottesting": { "state": { "trees": [ "try", diff --git a/temporalcache.js b/temporalcache.js index e2ee93f..faa2da9 100644 --- a/temporalcache.js +++ b/temporalcache.js @@ -6,6 +6,7 @@ var kMSPerCacheUnit = 1000 * 60 * 60; function Cache() { this.cache = {}; + this.info = {}; } Cache.prototype = { @@ -22,13 +23,18 @@ Cache.prototype = { assert.ok(this.has(name)); return this.cache[name]; }, - add: function (name, value, time) { + add: function (name, value, time, treeName, rev, who) { if (this.has(name)) this.remove(name); this.cache[name] = { value: value, timer: setTimeout(this.remove.bind(this, name), kMSPerCacheUnit * time) }; + this.info[name]={ + rev: rev, + name: who, + tree: treeName + }; }, remove: function (name) { assert.ok(this.has(name)); @@ -36,8 +42,16 @@ Cache.prototype = { if (entry.timer) clearTimeout(entry.timer); delete this.cache[name]; + delete this.info[name]; return entry.value; }, + show: function(){ + //for(var x in this.cache){ + // console.log(x); + // console.log(this.info[x]) + //} + return this.info; + }, }; module.exports = Cache;