Skip to content

Commit

Permalink
trying to normalize room calls but ... big task
Browse files Browse the repository at this point in the history
  • Loading branch information
dcsan committed Aug 25, 2015
1 parent 8788ba8 commit b3ef350
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 40 deletions.
2 changes: 1 addition & 1 deletion nap/data/fcc.wiki
71 changes: 32 additions & 39 deletions nap/lib/bot/GBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,27 +219,39 @@ var GBot = {
clog("announce", opts);
// this.scanRooms();
// Utils.clog("announce -->", opts);
this.joinRoom(opts, true);
this.joinAndListenToRoom(opts, true);
// Utils.clog("announce <ok", opts);
},

joinRoom: function(opts, announceFlag) {
var roomUrl = opts.roomObj.name;
joinAndListenToRoom: function(opts, announceFlag) {
var roomUrl,
delay = 0,
apiSpacing = 1000; // spacing per call

GBot.gitter.rooms.join(roomUrl, function(err, room) {
if (err) {
console.warn("Not possible to join the room: ", err, roomUrl);
// return null; // check - will this add nulls to the list of rooms?
}
GBot.roomList.push(room);
// have to stagger this for gitter rate limit
GBot.listenToRoom(room);
var text = GBot.getAnnounceMessage(opts);
GBot.say(text, room);
// clog("joined> ", room.uri);
return room;
});
return false;
// ugh inconsistent api
if (typeof opts == "string") {
roomUrl = opts;
} else {
roomUrl = opts.roomObj.name;
}
delay += apiSpacing;

setTimeout(function() {
GBot.gitter.rooms.join(roomUrl, function(err, room) {
if (err) {
console.warn("Not possible to join the room: ", err, roomUrl);
// return null; // check - will this add nulls to the list of rooms?
}
GBot.roomList.push(room);
// have to stagger this for gitter rate limit
GBot.listenToRoom(room);
var text = GBot.getAnnounceMessage(opts);
GBot.say(text, room);
// clog("joined> ", room.uri);
return room;
});
}, delay);

},

// checks if joined already, otherwise adds
Expand Down Expand Up @@ -302,25 +314,12 @@ var GBot = {
// this joins rooms contained in the data/RoomData.js file
// ie a set of bot specific discussion rooms
joinKnownRooms: function() {
var apiDelay = 500; // spacing per call
var that = this;
clog("botname on rooms", AppConfig.getBotName() );
clog("joinKnownRooms", AppConfig.getBotName() );
var delay = 0;
RoomData.rooms().map(function(oneRoomData) {
var roomUrl = oneRoomData.name;
delay += apiDelay;
setTimeout(function() {
// clog("oneRoomData", oneRoomData);
// clog("gitter.rooms", that.gitter.rooms);
that.gitter.rooms.join(roomUrl, function(err, room) {
if (err) {
// Utils.warn("Not possible to join the room:", err, roomUrl);
return;
}
that.listenToRoom(room);
clog("joined> ", room.name);
});
}, delay);
that.joinAndListenToRoom(roomUrl);
});
},

Expand All @@ -330,13 +329,7 @@ var GBot = {
Bonfires.allDashedNames().map(function(name) {
var roomUrl = AppConfig.getBotName() + "/" + name;
// Utils.clog("bf room", roomUrl);
that.gitter.rooms.join(roomUrl, function(err, room) {
if (err) {
// Utils.warn("Not possible to join the room:", err, roomUrl);
return;
}
that.listenToRoom(room);
});
that.joinAndListenToRoom(roomUrl);
});
},

Expand Down

0 comments on commit b3ef350

Please sign in to comment.