Permalink
Browse files
feat(app): Move config to main directory
- Loading branch information...
Showing
with
50 additions
and
35 deletions.
-
+1
−0
.gitignore
-
+3
−0
config/default.json
-
+2
−1
package.json
-
+11
−0
src/config.js
-
+5
−31
src/index.js
-
+28
−3
src/models/manager.js
|
|
@@ -1 +1,2 @@ |
|
|
node_modules/
|
|
|
+config/production.json
|
|
|
@@ -0,0 +1,3 @@ |
|
|
+{
|
|
|
+ "port": 3000
|
|
|
+}
|
|
|
@@ -5,7 +5,8 @@ |
|
|
"main": "src/index.js",
|
|
|
"dependencies": {
|
|
|
"botkit": "^0.0.4",
|
|
|
- "lodash": "^3.10.1"
|
|
|
+ "lodash": "^3.10.1",
|
|
|
+ "nconf": "^0.8.2"
|
|
|
},
|
|
|
"devDependencies": {},
|
|
|
"scripts": {
|
|
|
|
|
|
@@ -0,0 +1,11 @@ |
|
|
+var nconf = require('nconf'),
|
|
|
+ NODE_ENV = process.env.NODE_ENV || 'production';
|
|
|
+
|
|
|
+
|
|
|
+nconf.argv()
|
|
|
+ .env()
|
|
|
+ .file({ file: 'config/default.json' })
|
|
|
+ .file('env', { file: 'config/' + NODE_ENV + '.json' });
|
|
|
+
|
|
|
+
|
|
|
+module.exports = nconf;
|
|
|
@@ -1,44 +1,18 @@ |
|
|
'use strict';
|
|
|
|
|
|
-const config = {
|
|
|
- port: 3000,
|
|
|
- token: 'xoxb-17065016470-hFTAT0RNh0NkRSLBRStDZ7Nn'
|
|
|
-};
|
|
|
+const config = require('./config');
|
|
|
|
|
|
const Botkit = require('botkit/lib/Botkit.js');
|
|
|
-
|
|
|
const controller = Botkit.slackbot({
|
|
|
debug: false
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
const ManagerModel = require('./models/manager');
|
|
|
-const manager = new ManagerModel();
|
|
|
-
|
|
|
-
|
|
|
-controller
|
|
|
- .hears(['start meeting'], 'ambient', (bot, message) => {
|
|
|
- let channelId = message.channel;
|
|
|
-
|
|
|
- if (manager.meetingExist(channelId))
|
|
|
- return bot.say(message,
|
|
|
- 'Sorry, there is an existing meeting in this channel');
|
|
|
-
|
|
|
- let meeting = manager.create(channelId);
|
|
|
-
|
|
|
- meeting
|
|
|
- .start(bot, message)
|
|
|
- .then(() => {
|
|
|
- console.log('Conversation ended. Destroying...');
|
|
|
-
|
|
|
- meeting.destroy(channelId);
|
|
|
- });
|
|
|
+const manager = new ManagerModel(controller);
|
|
|
+const managerProcess = controller.spawn({
|
|
|
+ token: config.get('token')
|
|
|
});
|
|
|
|
|
|
-
|
|
|
-const managerProcess = controller.spawn({
|
|
|
- token: config.token
|
|
|
- })
|
|
|
+managerProcess
|
|
|
.startRTM((err, bot, payload) => {
|
|
|
if (err) return console.error('Error: ', err);
|
|
|
});
|
|
|
@@ -6,12 +6,14 @@ const _ = require('lodash'); |
|
|
|
|
|
|
|
|
class manager {
|
|
|
- constructor() {
|
|
|
+ constructor(controller) {
|
|
|
this.meetings = {};
|
|
|
+ this.controller = controller;
|
|
|
+ this.bindEvents_();
|
|
|
}
|
|
|
|
|
|
- meetingExist(id) {
|
|
|
- return !this.meetings && this.meetings[id];
|
|
|
+ meetingExist(channelId) {
|
|
|
+ return !this.meetings[channelId];
|
|
|
}
|
|
|
|
|
|
create(channelId) {
|
|
|
@@ -23,6 +25,29 @@ class manager { |
|
|
destroy(channelId) {
|
|
|
this.meetings[channelId] = null;
|
|
|
}
|
|
|
+
|
|
|
+ bindEvents_() {
|
|
|
+ let that = this;
|
|
|
+
|
|
|
+ this.controller
|
|
|
+ .hears(['start meeting'], 'ambient', (bot, message) => {
|
|
|
+ let channelId = message.channel;
|
|
|
+
|
|
|
+ if (that.meetingExist(channelId))
|
|
|
+ return bot.say(message,
|
|
|
+ 'Sorry, there is an existing meeting in this channel');
|
|
|
+
|
|
|
+ let meeting = that.create(channelId);
|
|
|
+
|
|
|
+ meeting
|
|
|
+ .start(bot, message)
|
|
|
+ .then(() => {
|
|
|
+ console.log('Conversation ended. Destroying...');
|
|
|
+ bot.say('Thanks. See you tomorrow at 10:00 AM');
|
|
|
+ meeting.destroy(channelId);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
module.exports = manager;
|
0 comments on commit
e9505eb