Skip to content

Commit

Permalink
refac for deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
dcsan committed Jul 31, 2015
1 parent d8f7893 commit ec89985
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 77 deletions.
11 changes: 5 additions & 6 deletions nap/bin/camperbot-run.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@



source bin/credentials-camperbot.sh

set -x

SERVER_ENV=prod \
BOT_APP_HOST=bot.freecodecamp.com \
GITTER_USER_TOKEN=${GITTER_USER_TOKEN} \
GITTER_APP_KEY=${GITTER_APP_KEY} \
GITTER_APP_SECRET=${GITTER_APP_SECRET} \
LOG_LEVEL=10 \
BOT_APP_HOST=bot.freecodecamp.com \
PORT=7891 \
BOTNAME=camperbot \
nodemon -x iojs app.js

# iojs app.js
# node --harmony app.js
# nodemon -x iojs app.js
2 changes: 1 addition & 1 deletion nap/bin/pm2-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ GITTER_APP_KEY=${GITTER_APP_KEY} \
GITTER_APP_SECRET=${GITTER_APP_SECRET} \
LOG_LEVEL=10 \
PORT=7891 \
pm2 start app.js --name bot --interpreter iojs
pm2 start --name bot --interpreter iojs app.js

# iojs app.js
# node --harmony app.js
Expand Down
2 changes: 0 additions & 2 deletions nap/bin/run-dev-bothelp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ source bin/credentials-bothelp.sh

set -x

BOTNAME=bothelp \
BOT_APP_HOST=bot.freecodecamp.com \
SERVER_ENV=local \
GITTER_USER_TOKEN=${GITTER_USER_TOKEN} \
GITTER_APP_KEY=${GITTER_APP_KEY} \
Expand Down
29 changes: 22 additions & 7 deletions nap/config/AppConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

var _ = require("lodash-node");

var Utils = require("../lib/utils/Utils");

var AppConfig = {
appHost: process.env.BOT_APP_HOST || "http://localhost:7000",
clientId: process.env.GITTER_APP_KEY,
token: process.env.GITTER_USER_TOKEN,
roomId: "55b1a9030fc9f982beaac901", // default room botzy
Expand All @@ -22,12 +23,19 @@ var AppConfig = {
wikiHost: "https://github.com/freecodecamp/freecodecamp/wiki/",
gitterHost: "https://gitter.im/",
mdn: "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/",
botVersion: "0.0.2",
botVersion: "0.0.3",
MAX_WIKI_LINES: 10,


// TODO cleanup
currentBot: function() {
// use as a function so it can be set at startup
// before other code calls it at runtime
getBotName: function() {
if (!AppConfig.botname) {
Utils.error("tried to call botname before it was set");
return "ERROR_BOTNAME"; // or crash?
}
// Utils.warn("getBotName()", AppConfig.botname );
return AppConfig.botname;
},

Expand Down Expand Up @@ -62,29 +70,29 @@ var AppConfig = {

};

// calculated items
AppConfig.dmLink = "https://gitter.im/" + AppConfig.botname;

var serverEnv = process.env.SERVER_ENV || "beta";

var envConfigs = {
test: {
appHost: "http://localhost:7000",
apiServer: "beta.freecodecamp.com",
appRedirectUrl: "http://localhost:7891/login/callback",
botname: "bothelp"
},

local: {
appHost: "http://localhost:7000",
apiServer: "beta.freecodecamp.com",
appRedirectUrl: "http://localhost:7891/login/callback",
botname: "bothelp"
},
beta: {
appHost: "http://localhost:7000",
apiServer: "beta.freecodecamp.com",
appRedirectUrl: "http://localhost:7891/login/callback",
botname: "bothelp"
},
prod: {
appHost: "http://bot.freecodecamp.com",
apiServer: "freecodecamp.com",
appRedirectUrl: "http://bot.freecodecamp.com/login/callback",
botname: "camperbot"
Expand All @@ -93,6 +101,10 @@ var envConfigs = {

// AppConfig.apiServer = envConfigs.apiServer[serverEnv];


var serverEnv = process.env.SERVER_ENV;
AppConfig.serverEnv = serverEnv;

var thisConfig = envConfigs[serverEnv];
if (!thisConfig) {
var msg = ("cant find env:", serverEnv);
Expand All @@ -102,6 +114,9 @@ if (!thisConfig) {

_.merge(AppConfig, thisConfig);

// calculated items
AppConfig.dmLink = "https://gitter.im/" + AppConfig.botname;

console.log("AppConfig", AppConfig);

module.exports = AppConfig;
Expand Down
50 changes: 25 additions & 25 deletions nap/data/RoomData.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ var AppConfig = require('../config/AppConfig');
// we find a matching room here with that topic
// and redirect them

var RoomData,
listenRoom;
var RoomData;


// TODO - read this from the JSON file
var bonfireTopics = [
Expand Down Expand Up @@ -86,12 +86,6 @@ var BotRoomData = {
topics: ["chitchat", "dm"]
},

{
title: "Botdiscussion",
name: "dcsan/botzy",
topics: ['bots', 'fcc', 'teaching']
},

{
title: "GeneralChat",
name: "bothelp/GeneralChat",
Expand All @@ -113,38 +107,44 @@ var BotRoomData = {
topics: bonfireTopics
},

{
title: "Help Bonfires",
name: "camperbot/HelpBonfires",
topics: bonfireTopics
},

{
title: "Help ZipLines",
name: "camperbot/HelpZiplines",
topics: ["ziplines"]
},

{
title: "Botdiscussion",
name: "dcsan/botzy",
topics: ['bots', 'fcc', 'teaching']
}

]

};

var botname = null;

RoomData = {
rooms: function() {
botname = botname || AppConfig.getBotName();
return BotRoomData[botname];
},

defaultRoom: function() {
return RoomData.rooms().rooms[0];
}

// filter rooms to listen to if a cmd line arg was passed in
// for development
var botname = AppConfig.botname;

console.log("loading RoomData for " + botname);
};

RoomData = BotRoomData[botname];

// if (listenRoom) {
// RoomData = AllRoomData.filter(function(rm) {
// return (rm.name === listenRoom);
// });
// console.log("LISTEN_ROOM only:", RoomData);
// } else {
// RoomData = AllRoomData;
// }

// alias
RoomData.defaultRoom = RoomData[0];

// console.log("RoomData", RoomData);
module.exports = RoomData;

8 changes: 4 additions & 4 deletions nap/lib/app/Rooms.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

// var _ = require("underscore");

var RoomData = require('../../data/RoomData.js'),
var RoomData = require('../../data/RoomData'),
Bonfires = require('./Bonfires'),
AppConfig = require('../../config/AppConfig');

var Rooms = {

findByTopic: function(topic) {

var rooms = RoomData.filter(function(rm) {
var rooms = RoomData.rooms().filter(function(rm) {
var topics = rm.topics;
if (!topics) {
return false;
Expand All @@ -36,14 +36,14 @@ var Rooms = {
// })

findByName: function(name) {
var rooms = RoomData.filter( function(rm) {
var rooms = RoomData.rooms().filter( function(rm) {
return (rm.name === name);
});
return (this.checkRoom(rooms[0], 'findByName', name));
},

names: function() {
this.roomList = RoomData.map(function(room) {
this.roomList = RoomData.rooms().map(function(room) {
return room.name;
});
return this.roomList;
Expand Down
4 changes: 2 additions & 2 deletions nap/lib/app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var AppConfig = require('../../config/AppConfig'),
Rooms = require('../../lib/app/Rooms.js'),
Utils = require('../../lib/utils/Utils'),
Bonfires = require('./Bonfires'),
RoomData = require('../../data/RoomData.js');
RoomData = require('../../data/RoomData');

var GitterHelper = require('../../lib/gitter/GitterHelper');

Expand All @@ -27,7 +27,7 @@ var Router = {
query.org = AppConfig.getOrg();

if(query.dm === 'y') {
query.room = query.room || AppConfig.botname;
query.room = query.room || AppConfig.getBotName();
}

if (query.room) {
Expand Down
10 changes: 8 additions & 2 deletions nap/lib/bot/BotCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,21 @@ var BotCommands = {
return "botVersion: " + AppConfig.botVersion;
},

test: function (input, bot) {
botstatus: function (input, bot) {
if (input.params) {
return null; // dont response if they type test something as its probly just chat
}
var msg = "All bot systems are go! \n";
msg += this.version();
msg += this.version() + "\n";
msg += this.botenv();
return msg;
},

botenv: function(input, bot) {
var str = "env: " + AppConfig.serverEnv;
return str;
},

// bonfire features
hint: function(input, bot) {
var str;
Expand Down
50 changes: 25 additions & 25 deletions nap/lib/bot/GBot.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,29 @@ var GBot = {

announce: function(opts) {
clog("announce", opts);
this.scanRooms();
Utils.clog("announce -->", opts);
this.joinRoom(opts, true);
Utils.clog("announce <ok", opts);
// this.scanRooms();
// Utils.clog("announce -->", opts);
// this.joinRoom(opts, true);
// Utils.clog("announce <ok", opts);
},

joinRoom: function(opts) {
var roomUrl = opts.roomObj.name;
debugger;
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);
GBot.listenToRoom(room);
var text = GBot.getAnnounceMessage(opts);
GBot.say(text, room);
clog("joined> ", room.uri);
return room;
});
return false;
},
// joinRoom: function(opts) {
// var roomUrl = opts.roomObj.name;
// debugger;
// 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);
// GBot.listenToRoom(room);
// var text = GBot.getAnnounceMessage(opts);
// GBot.say(text, room);
// clog("joined> ", room.uri);
// return room;
// });
// return false;
// },

// checks if joined already, otherwise adds
addToRoomList: function(room) {
Expand Down Expand Up @@ -138,7 +138,6 @@ var GBot = {
return false;
},


getAnnounceMessage: function(opts) {
var text = "----\n";
if (opts.who && opts.topic) {
Expand Down Expand Up @@ -197,9 +196,10 @@ var GBot = {
// ie a set of bot specific discussion rooms
joinKnownRooms: function() {
var that = this;
RoomData.map(function(oneRoomData) {
clog("botname on rooms", AppConfig.getBotName() );
RoomData.rooms().map(function(oneRoomData) {
var roomUrl = oneRoomData.name;
// console.log("oneRoomData", oneRoomData);
clog("oneRoomData", oneRoomData);
// clog("gitter.rooms", that.gitter.rooms);
that.gitter.rooms.join(roomUrl, function(err, room) {
if (err) {
Expand All @@ -216,7 +216,7 @@ var GBot = {
joinBonfireRooms: function() {
var that = this;
Bonfires.allDashedNames().map(function(name) {
var roomUrl = AppConfig.currentBot() + "/" + name;
var roomUrl = AppConfig.getBotName() + "/" + name;
// Utils.clog("bf room", roomUrl);
that.gitter.rooms.join(roomUrl, function(err, room) {
if (err) {
Expand Down
4 changes: 2 additions & 2 deletions nap/lib/utils/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ var Utils = {

switch (where) {
case 'gitter':
host = AppConfig.gitterHost + AppConfig.botname;
host = AppConfig.gitterHost + AppConfig.getBotName();
break;
case 'wiki':
host = AppConfig.wikiHost;
break;
default:
host = AppConfig.wikiHost + AppConfig.botname;
host = AppConfig.wikiHost + AppConfig.getBotName();
}

uri = host + str;
Expand Down
2 changes: 1 addition & 1 deletion nap/test/GBotSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("GBot", function () {
GBot.init();
msg = Utils.makeMessageFromString("wiki css");
res = GBot.findAnyReply(msg);
expect(res).to.contain('## [css]');
expect(res).to.contain('## :pencil: [css]');
});

it("should have a test response", function () {
Expand Down

0 comments on commit ec89985

Please sign in to comment.