Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Resolve Issue #13 - Add command to list current watches #21

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions README

This file was deleted.

42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <tree>``` starts watching a tree

```unwatch <tree>``` stops watching a tree

```watch <changset> on <tree> (for <person>)```

```unwatch <changset> on <tree> (for <person>)```

```<email> is <name>``` and ```I am <email>``` set name associations

```list``` or ```currently``` shows all current user-specific watches

```help``` displays help file

2 changes: 1 addition & 1 deletion bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var session = require("./sessionrestore");
// Connect to IRC
var kNick = 'afrosdwilsh';
var kAuthorizedUsers = [
'sdwilsh', 'robarnold'
'sdwilsh', 'robarnold', 'samliu'
];

function isAuthorizedUser(user) {
Expand Down
24 changes: 23 additions & 1 deletion channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -286,6 +306,8 @@ ChannelController.prototype = {
[/^version$/, "version"],
[/^update/, "update"],
[/^restart$/, "restart"],
[/^currently$/, "currently"],
[/^list$/, "currently"],
]
};

Expand Down
7 changes: 3 additions & 4 deletions committers.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"[email protected]": "mfinkle",
"[email protected]": "philor",
"[email protected]": "Ms2ger",
"[email protected]": "dao",
"[email protected]": "mwu",
Expand Down Expand Up @@ -42,11 +41,11 @@
"[email protected]": "Ventron",
"[email protected]": "jimb",
"[email protected]": "humph",
"[email protected]": "jmaher",
"[email protected]": "taras",
"[email protected]": "cpearce",
"[email protected]": "bent",
"[email protected]": "mayhemer",
"[email protected]": "tbsaunde",
"[email protected]": "bjarne"
}
"[email protected]": "bjarne",
"[email protected]": "samliu"
}
7 changes: 7 additions & 0 deletions session.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"channels": {
"<console>": {
"state": {
"trees": [
"mozilla-central"
]
}
},
"#bottesting": {
"state": {
"trees": [
"try",
Expand Down
16 changes: 15 additions & 1 deletion temporalcache.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var kMSPerCacheUnit = 1000 * 60 * 60;
function Cache()
{
this.cache = {};
this.info = {};
}

Cache.prototype = {
Expand All @@ -22,22 +23,35 @@ 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));
var entry = this._get(name);
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;