김연준

Making randomJoke function operate correctly

node_modules
\ No newline at end of file
mongodb
\ No newline at end of file
......
......@@ -7,7 +7,7 @@ const url = 'mongodb://localhost:27017/';
exports.startbot = ()=>{
// Get authorization to use the slackbot
const bot = new SlackBot({
token : "xoxb-582582124755-587875604934-86ISu22wmEaDhGWtQmpvumbR",
token : "",
name : "Joker"
});
......@@ -70,21 +70,18 @@ randomJoke= ()=>{
user = result;
user.then(function(total){
question = total.setup;
joke = total.punchline;
const face = {
icon_emoji: ':laughing:'
};
function firstFunction(channel){
bot.postMessageToChannel(channel, joke, face);
console.log("허무개그 전송~~~~!");
}
function secondFunction(channel, callback){
function firstFunction(channel){
bot.postMessageToChannel(channel, question, face);
console.log("질문 불려짐")
firstFunction(channel);
}
secondFunction('everyone',firstFunction);
firstFunction('everyone');
console.log('질문 불려짐');
return total;
// bot.postMessageToChannel('everyone', question, face);
// bot.postMessageToChannel('full-stack-web', question, joke, face);
// bot.postMessageToChannel('bot_test', question, face);
......@@ -92,6 +89,17 @@ randomJoke= ()=>{
// bot.postMessageToChannel('full-stack-web', joke, face);
// bot.postMessageToChannel('bot_test', joke, face);
})
.then((all)=>{
joke = all.punchline;
const face = {
icon_emoji: ':laughing:'
};
function secondFunction(channel){
bot.postMessageToChannel(channel, joke, face);
console.log( "허무개그 전송~~~~!")
}
secondFunction('everyone');
})
client.close();
})
}
......@@ -178,9 +186,8 @@ programmingJoke= ()=>{
function secondFunction(channel, callback){
bot.postMessageToChannel(channel, question, face);
console.log("프로그래밍 질문 불려짐")
firstFunction(channel);
}
secondFunction('everyone',firstFunction);
secondFunction('everyone').then(firstFunction('everyone'));
// bot.postMessageToChannel('everyone', question, face);
// bot.postMessageToChannel('full-stack-web', question, joke, face);
// bot.postMessageToChannel('bot_test', question, face);
......
const MongoClient = require('mongodb').MongoClient;
const jokedoc = require('./jokes/jokes.json');
const jokedoc = require('./joke_data/jokes.json');
const dbname = 'jokeapi';
const collec = 'jokes';
var url = "mongodb://localhost:27017/jokeapi";
// Create database
// MongoClient.connect(url, function(err, db) {
// if (err) throw err;
// console.log("Database created!");
// db.close();
// });
//Create database
MongoClient.connect(url, function(err, db) {
if (err) throw err;
console.log("Database created!");
db.close();
});
// MongoClient.connect(url, function(err, db) {
// if (err) throw err;
// var dbo = db.db("jokeapi");
// dbo.createCollection("joke", function(err, res) {
// if (err) throw err;
// console.log("Collection created!");
// db.close();
// });
// });
//Create collection
MongoClient.connect(url, function(err, db) {
if (err) throw err;
var dbo = db.db("jokeapi");
dbo.createCollection("joke", function(err, res) {
if (err) throw err;
console.log("Collection created!");
db.close();
});
});
// Storing data jokes.json data into mongodb
// MongoClient.connect(url).then((client) => {
//Storing data jokes.json data into mongodb
MongoClient.connect(url).then((client) => {
// console.log('Connected correctly to server');
console.log('Connected correctly to server');
// const db = client.db(dbname);
const db = client.db(dbname);
// dboperation.insertDocument(db, jokedoc, collec)
// .then((result) => {
// console.log("Inserted Document:\n", result.ops);
dboperation.insertDocument(db, jokedoc, collec)
.then((result) => {
console.log("Inserted Document:\n", result.ops);
// return dboperation.findDocuments(db, collec);
// })
// .catch((err) => console.log(err));
return dboperation.findDocuments(db, collec);
})
.catch((err) => console.log(err));
// })
// .catch((err) => console.log(err));
})
.catch((err) => console.log(err));
......