Showing
3 changed files
with
48 additions
and
41 deletions
... | @@ -7,7 +7,7 @@ const url = 'mongodb://localhost:27017/'; | ... | @@ -7,7 +7,7 @@ const url = 'mongodb://localhost:27017/'; |
7 | exports.startbot = ()=>{ | 7 | exports.startbot = ()=>{ |
8 | // Get authorization to use the slackbot | 8 | // Get authorization to use the slackbot |
9 | const bot = new SlackBot({ | 9 | const bot = new SlackBot({ |
10 | - token : "xoxb-582582124755-587875604934-86ISu22wmEaDhGWtQmpvumbR", | 10 | + token : "", |
11 | name : "Joker" | 11 | name : "Joker" |
12 | }); | 12 | }); |
13 | 13 | ||
... | @@ -70,21 +70,18 @@ randomJoke= ()=>{ | ... | @@ -70,21 +70,18 @@ randomJoke= ()=>{ |
70 | user = result; | 70 | user = result; |
71 | user.then(function(total){ | 71 | user.then(function(total){ |
72 | question = total.setup; | 72 | question = total.setup; |
73 | - joke = total.punchline; | ||
74 | const face = { | 73 | const face = { |
75 | icon_emoji: ':laughing:' | 74 | icon_emoji: ':laughing:' |
76 | }; | 75 | }; |
77 | - function firstFunction(channel){ | ||
78 | - bot.postMessageToChannel(channel, joke, face); | ||
79 | - console.log("허무개그 전송~~~~!"); | ||
80 | - } | ||
81 | 76 | ||
82 | - function secondFunction(channel, callback){ | 77 | + function firstFunction(channel){ |
83 | bot.postMessageToChannel(channel, question, face); | 78 | bot.postMessageToChannel(channel, question, face); |
84 | - console.log("질문 불려짐") | ||
85 | - firstFunction(channel); | ||
86 | } | 79 | } |
87 | - secondFunction('everyone',firstFunction); | 80 | + firstFunction('everyone'); |
81 | + console.log('질문 불려짐'); | ||
82 | + return total; | ||
83 | + | ||
84 | + | ||
88 | // bot.postMessageToChannel('everyone', question, face); | 85 | // bot.postMessageToChannel('everyone', question, face); |
89 | // bot.postMessageToChannel('full-stack-web', question, joke, face); | 86 | // bot.postMessageToChannel('full-stack-web', question, joke, face); |
90 | // bot.postMessageToChannel('bot_test', question, face); | 87 | // bot.postMessageToChannel('bot_test', question, face); |
... | @@ -92,6 +89,17 @@ randomJoke= ()=>{ | ... | @@ -92,6 +89,17 @@ randomJoke= ()=>{ |
92 | // bot.postMessageToChannel('full-stack-web', joke, face); | 89 | // bot.postMessageToChannel('full-stack-web', joke, face); |
93 | // bot.postMessageToChannel('bot_test', joke, face); | 90 | // bot.postMessageToChannel('bot_test', joke, face); |
94 | }) | 91 | }) |
92 | + .then((all)=>{ | ||
93 | + joke = all.punchline; | ||
94 | + const face = { | ||
95 | + icon_emoji: ':laughing:' | ||
96 | + }; | ||
97 | + function secondFunction(channel){ | ||
98 | + bot.postMessageToChannel(channel, joke, face); | ||
99 | + console.log( "허무개그 전송~~~~!") | ||
100 | + } | ||
101 | + secondFunction('everyone'); | ||
102 | + }) | ||
95 | client.close(); | 103 | client.close(); |
96 | }) | 104 | }) |
97 | } | 105 | } |
... | @@ -178,9 +186,8 @@ programmingJoke= ()=>{ | ... | @@ -178,9 +186,8 @@ programmingJoke= ()=>{ |
178 | function secondFunction(channel, callback){ | 186 | function secondFunction(channel, callback){ |
179 | bot.postMessageToChannel(channel, question, face); | 187 | bot.postMessageToChannel(channel, question, face); |
180 | console.log("프로그래밍 질문 불려짐") | 188 | console.log("프로그래밍 질문 불려짐") |
181 | - firstFunction(channel); | ||
182 | } | 189 | } |
183 | - secondFunction('everyone',firstFunction); | 190 | + secondFunction('everyone').then(firstFunction('everyone')); |
184 | // bot.postMessageToChannel('everyone', question, face); | 191 | // bot.postMessageToChannel('everyone', question, face); |
185 | // bot.postMessageToChannel('full-stack-web', question, joke, face); | 192 | // bot.postMessageToChannel('full-stack-web', question, joke, face); |
186 | // bot.postMessageToChannel('bot_test', question, face); | 193 | // bot.postMessageToChannel('bot_test', question, face); | ... | ... |
1 | const MongoClient = require('mongodb').MongoClient; | 1 | const MongoClient = require('mongodb').MongoClient; |
2 | -const jokedoc = require('./jokes/jokes.json'); | 2 | +const jokedoc = require('./joke_data/jokes.json'); |
3 | const dbname = 'jokeapi'; | 3 | const dbname = 'jokeapi'; |
4 | const collec = 'jokes'; | 4 | const collec = 'jokes'; |
5 | 5 | ||
6 | var url = "mongodb://localhost:27017/jokeapi"; | 6 | var url = "mongodb://localhost:27017/jokeapi"; |
7 | 7 | ||
8 | -// Create database | 8 | +//Create database |
9 | -// MongoClient.connect(url, function(err, db) { | 9 | +MongoClient.connect(url, function(err, db) { |
10 | -// if (err) throw err; | 10 | + if (err) throw err; |
11 | -// console.log("Database created!"); | 11 | + console.log("Database created!"); |
12 | -// db.close(); | 12 | + db.close(); |
13 | -// }); | 13 | +}); |
14 | 14 | ||
15 | -// MongoClient.connect(url, function(err, db) { | 15 | +//Create collection |
16 | -// if (err) throw err; | 16 | +MongoClient.connect(url, function(err, db) { |
17 | -// var dbo = db.db("jokeapi"); | 17 | + if (err) throw err; |
18 | -// dbo.createCollection("joke", function(err, res) { | 18 | + var dbo = db.db("jokeapi"); |
19 | -// if (err) throw err; | 19 | + dbo.createCollection("joke", function(err, res) { |
20 | -// console.log("Collection created!"); | 20 | + if (err) throw err; |
21 | -// db.close(); | 21 | + console.log("Collection created!"); |
22 | -// }); | 22 | + db.close(); |
23 | -// }); | 23 | + }); |
24 | + }); | ||
24 | 25 | ||
25 | 26 | ||
26 | -// Storing data jokes.json data into mongodb | 27 | +//Storing data jokes.json data into mongodb |
27 | -// MongoClient.connect(url).then((client) => { | 28 | +MongoClient.connect(url).then((client) => { |
28 | 29 | ||
29 | -// console.log('Connected correctly to server'); | 30 | + console.log('Connected correctly to server'); |
30 | 31 | ||
31 | 32 | ||
32 | -// const db = client.db(dbname); | 33 | + const db = client.db(dbname); |
33 | 34 | ||
34 | -// dboperation.insertDocument(db, jokedoc, collec) | 35 | + dboperation.insertDocument(db, jokedoc, collec) |
35 | -// .then((result) => { | 36 | + .then((result) => { |
36 | -// console.log("Inserted Document:\n", result.ops); | 37 | + console.log("Inserted Document:\n", result.ops); |
37 | 38 | ||
38 | -// return dboperation.findDocuments(db, collec); | 39 | + return dboperation.findDocuments(db, collec); |
39 | -// }) | 40 | + }) |
40 | -// .catch((err) => console.log(err)); | 41 | + .catch((err) => console.log(err)); |
41 | 42 | ||
42 | -// }) | 43 | +}) |
43 | -// .catch((err) => console.log(err)); | 44 | +.catch((err) => console.log(err)); |
44 | 45 | ||
45 | 46 | ||
46 | 47 | ... | ... |
-
Please register or login to post a comment