From 88199173bd38039d58f636dd823b863d7730b5e9 Mon Sep 17 00:00:00 2001 From: Gavin Sharp Date: Tue, 14 Jun 2011 08:55:17 -0700 Subject: [PATCH 1/2] philor is not philringalda@gmail.com --- committers.json | 1 - 1 file changed, 1 deletion(-) diff --git a/committers.json b/committers.json index 4a59e0c..0eab26f 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", From d0e53532df6862a00c0209eb38505c38c4f17791 Mon Sep 17 00:00:00 2001 From: Sam Liu Date: Fri, 5 Aug 2011 11:18:06 -0700 Subject: [PATCH 2/2] listing watches feature added --- README | 9 --------- README.md | 42 ++++++++++++++++++++++++++++++++++++++++++ bot.js | 2 +- channels.js | 24 +++++++++++++++++++++++- committers.json | 6 +++--- session.json | 7 +++++++ temporalcache.js | 16 +++++++++++++++- 7 files changed, 91 insertions(+), 15 deletions(-) delete mode 100644 README create mode 100644 README.md 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 0eab26f..e563b53 100644 --- a/committers.json +++ b/committers.json @@ -41,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;