김연준

remote mongodb access in ec2

npm-debug.log
\ No newline at end of file
......@@ -3,25 +3,25 @@ const jokedoc = require('../joke_data/jokes.json');
const dbname = 'jokeapi';
const collec = 'jokes';
const dboperation = require('./operations.js');
var url = "mongodb://localhost:27017/jokeapi";
//Create database
MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
if (err) throw err;
console.log("Database created!");
db.close();
});
//Create collection
MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
if (err) throw err;
var dbo = db.db("jokeapi");
dbo.createCollection("jokes", function(err, res) {
if (err) throw err;
console.log("Collection created!");
db.close();
});
});
var url = "mongodb://13.124.65.242:27017/jokeapi";
// //Create database
// MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
// if (err) throw err;
// console.log("Database created!");
// db.close();
// });
// //Create collection
// MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
// if (err) throw err;
// var dbo = db.db("jokeapi");
// dbo.createCollection("jokes", function(err, res) {
// if (err) throw err;
// console.log("Collection created!");
// db.close();
// });
// });
//Storing data jokes.json data into mongodb
......
......@@ -3,7 +3,7 @@ const jokedoc = require('../joke_data/Funny_story.json');
const dbname = 'FunnyStoryapi';
const collec = 'FunnyStory';
const dboperation = require('./operations.js');
var url = "mongodb://localhost:27017/FunnyStoryapi";
var url = "mongodb://13.124.65.242:27017/FunnyStoryapi";
//Create database
MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
......@@ -16,7 +16,7 @@ MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
if (err) throw err;
var dbo = db.db("FunnyStoryapi");
dbo.createCollection("FunnyStory", function(err, res) {
dbo.createCollection("FunnyStories", function(err, res) {
if (err) throw err;
console.log("Collection created!");
db.close();
......
......@@ -3,7 +3,7 @@ const jokedoc = require('../joke_data/reddit_joke.json');
const dbname = 'redditjoke';
const collec = 'reddit';
const dboperation = require('./operations.js');
var url = "mongodb://localhost:27017/redditjoke";
var url = "mongodb://13.124.65.242:27017/redditjoke";
//Create database
MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
......@@ -15,7 +15,7 @@ MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
//Create collection
MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
if (err) throw err;
var dbo = db.db("reddit");
var dbo = db.db("redditjoke");
dbo.createCollection("redditjokes", function(err, res) {
if (err) throw err;
console.log("Collection created!");
......
......@@ -3,7 +3,7 @@ const jokedoc = require('../joke_data/user.json');
const dbname = 'userdb';
const collec = 'user';
const dboperation = require('./operations.js');
var url = "mongodb://localhost:27017/userdb";
var url = "mongodb://13.124.65.242:27017/userdb";
//Create database
MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
......
......@@ -2,16 +2,16 @@ const MongoClient = require('mongodb').MongoClient;
const SlackBot = require('slackbots'); //link : https://github.com/mishk0/slack-bot-api
const dbname = 'jokeapi';
const emoji = require('../slack_emoji');
const url = 'mongodb://localhost:27017/';
var url2 = 'mongodb://localhost:27017/userjoke'
const fs = require('fs');
//const userjoke = require('./joke_data/user.json');
const url = 'mongodb://13.124.65.242:27017/';
const url2 = 'mongodb://13.124.65.242:27017/userdb';
const fs=require('fs');
message_recieved = 0;
exports.startbot = ()=>{
// Get authorization to use the slackbot
const bot = new SlackBot({
token : "xoxb-651692943605-645515979745-VInZkUepi88jyzhpps44uRyM",
name : "jokebot"
token : "xoxb-582582124755-587875604934-gdWsVhzGXCze3mECWXpTsAP6",
name : "joker"
});
// Start the slackbot
......@@ -111,7 +111,7 @@ function handleMessage(message, current_channel){
UserMakeJoke(message,current_channel);
}
else if(message.includes(' me')){
comment = "Please use @joker [-help] to know what I can do!:smile::smile::smile:\n You can write type of joke[knock-knock, general, programming, funny story, reddit]";
comment = "Please use @joker --help to know what I can do!:smile::smile::smile:\n You can write type of joke[knock-knock, general, programming, funny story, reddit]";
bot.postMessageToChannel(current_channel, "Tell you what??? :no_mouth:", emoji.emojis('no_mouth'));
bot.postMessageToChannel(current_channel, comment, emoji.emojis('flushed'));
}
......@@ -156,7 +156,7 @@ function MakeJoke(message,user_channel){
var length=obj.table.length;
obj.table.push({id : length+1, type : user, setup : msg[0], punchline : msg[1]});
var myobj = {id : length+1, type : user, setup : msg[0], punchline : msg[1]};
MongoClient.connect(url2,function(err,db){
MongoClient.connect(url,function(err,db){
if(err) throw err;
var dbo = db.db("userdb");
dbo.collection("user").insertOne(myobj, function(err,res){
......@@ -164,7 +164,6 @@ function MakeJoke(message,user_channel){
console.log("1 insert!!");
db.close;
})
})
var json=JSON.stringify(obj);
......@@ -183,24 +182,8 @@ function MakeJoke(message,user_channel){
console.log("file not exists");
obj.table.push({id : 1, type : user, setup : msg[0], punchline : msg[1]});
var myobj = {id : 1, type : user, setup : msg[0], punchline : msg[1]};
//Create database
MongoClient.connect(url2, { useNewUrlParser: true }, function(err, db) {
if (err) throw err;
console.log("Database created!");
db.close();
});
//Create collection
MongoClient.connect(url2, { useNewUrlParser: true }, function(err, db) {
if (err) throw err;
var dbo = db.db("userdb");
dbo.createCollection("user", function(err, res) {
if (err) throw err;
console.log("Collection created!");
db.close();
});
});
MongoClient.connect(url2,{ useNewUrlParser: true },function(err,db){
MongoClient.connect(url,{ useNewUrlParser: true },function(err,db){
if(err) throw err;
var dbo = db.db("userdb");
dbo.collection("user").insertOne(myobj, function(err,res){
......@@ -208,7 +191,6 @@ function MakeJoke(message,user_channel){
console.log("1 insert!!");
db.close;
})
});
var json=JSON.stringify(obj);
fs.writeFile(path,json,'utf8',function(err){
......@@ -235,7 +217,7 @@ function getRandomInt(start,end) {
//Function for giving out random joke
randomJoke= (user_channel)=>{
//Connect to mongodb client
MongoClient.connect('mongodb://localhost:27017', function (err, client){
MongoClient.connect('mongodb://13.124.65.242:27017/', function (err, client){
if (err) throw err;
//go into database name jokeapi
var db = client.db('jokeapi');
......@@ -272,27 +254,42 @@ UserMakeJoke= (message,user_channel)=>{
var temp=message.split(' ');
var user=temp[0].substring(2,temp[0].length-1);
console.log('유저 => '+user);
MongoClient.connect('mongodb://13.124.65.242:27017', function (err, client){
if (err) throw err;
//go into database name jokeapi
var db = client.db('userdb');
result = db.collection('user').findOne({type: user});
console.log(result);
user = result;
//After finding one joke, use promise to run codes synchronously
user.then(function(total){
question = total.setup;
bot.postMessageToChannel(user_channel, question, emoji.emojis('laughing'));
console.log("질문 불려짐");
return total;
})
.then((all)=>{
joke=all.punchline;
//Use setTimeout function to delay the code execution, making sure the user reads the question first and then see the final funny joke
setTimeout(function secondFunction(){
bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing'));
console.log("허무개그 전송~~~~~~!");
},3000);
})
//close mongodb
client.close();
})
var path='./joke_data/'+user+'.json';
var data=fs.readFileSync(path);
var jsondata=JSON.parse(data);
random=getRandomInt(1,jsondata.table.length+1);
console.log(random);
for(var i=0;i<jsondata.table.length;i++){
if(jsondata.table[i].id==random){
user=jsondata.table[i];
question=user.setup;
bot.postMessageToChannel(user_channel,question, emoji.emojis('laughing'));
joke=user.punchline;
setTimeout(function secondfunction(){
bot.postMessageToChannel(user_channel,joke, emoji.emojis('laughing'));
},3000);
console.log("User joke~~~");
break;
}
}
}
//Function for giving out random joke after filtering only general type jokes
......@@ -366,7 +363,7 @@ Funnystory= (user_channel)=>{
cate = total.category;
story = total.body;
category_story=cate+'\n'+story+':stuck_out_tongue_winking_eye::laughing:';
bot.postMessageToChannel(user_channel, category_story, emoji.emojis('smiliey'));
bot.postMessageToChannel(user_channel, category_story, emoji.emojis('smiley'));
console.log("Funny story~~~");
})
client.close();
......@@ -387,7 +384,7 @@ redditJoke= (user_channel)=>{
user.then(function(total){
title = total.title;
bot.postMessageToChannel(user_channel, title, emoji.emojis('smiliey'));
console.log("quiz~");
console.log("질문 불려짐");
return total;
})
.then((all)=>{
......@@ -395,7 +392,7 @@ redditJoke= (user_channel)=>{
//Use setTimeout function to delay the code execution, making sure the user reads the question first and then see the final funny joke
setTimeout(function secondFunction(){
bot.postMessageToChannel(user_channel,`${joke}:stuck_out_tongue_winking_eye::laughing:`,emoji.emojis('laughing'));
console.log("reddit joke~~~");
console.log("허무개그 전송~~~~~~!");
},3000);
})
client.close();
......
{"table":[{"id":1,"type":"UJZF5UTMX","setup":" ok","punchline":" okkk"},{"id":2,"type":"UJZF5UTMX","setup":" man","punchline":" woman"},{"id":3,"type":"UJZF5UTMX","setup":" kim ","punchline":" minuk"}]}
\ No newline at end of file
{"table":[{"id":1,"type":"UJZF5UTMX","setup":" ok","punchline":" okkk"},{"id":2,"type":"UJZF5UTMX","setup":" man","punchline":" woman"},{"id":3,"type":"UJZF5UTMX","setup":" kim ","punchline":" minuk"},{"id":4,"type":"UH9RRHSTG","setup":" 팔에 비빔면 뭍으면 빨리 닦아야됨 왜?","punchline":" 팔도비빔면됨"},{"id":5,"type":"UH9RRHSTG","setup":" 팔에 비빔소스 묻으면 빨리 닦아야함","punchline":" 팔도비빔면되서"},{"id":6,"type":"UH9RRHSTG","setup":" check","punchline":" working"}]}
\ No newline at end of file
......
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'start' ]
2 info using npm@3.5.2
3 info using node@v8.10.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle joker@1.0.0~prestart: joker@1.0.0
6 silly lifecycle joker@1.0.0~prestart: no script for prestart, continuing
7 info lifecycle joker@1.0.0~start: joker@1.0.0
8 verbose lifecycle joker@1.0.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle joker@1.0.0~start: PATH: /usr/share/npm/bin/node-gyp-bin:/home/kyjyeon/Desktop/khuhub/TeamProject/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
10 verbose lifecycle joker@1.0.0~start: CWD: /home/kyjyeon/Desktop/khuhub/TeamProject
11 silly lifecycle joker@1.0.0~start: Args: [ '-c', 'node index.js' ]
12 silly lifecycle joker@1.0.0~start: Returned: code: 1 signal: null
13 info lifecycle joker@1.0.0~start: Failed to exec start script
14 verbose stack Error: joker@1.0.0 start: `node index.js`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (/usr/share/npm/lib/utils/lifecycle.js:232:16)
14 verbose stack at emitTwo (events.js:126:13)
14 verbose stack at EventEmitter.emit (events.js:214:7)
14 verbose stack at ChildProcess.<anonymous> (/usr/share/npm/lib/utils/spawn.js:24:14)
14 verbose stack at emitTwo (events.js:126:13)
14 verbose stack at ChildProcess.emit (events.js:214:7)
14 verbose stack at maybeClose (internal/child_process.js:925:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
15 verbose pkgid joker@1.0.0
16 verbose cwd /home/kyjyeon/Desktop/khuhub/TeamProject
17 error Linux 4.18.0-15-generic
18 error argv "/usr/bin/node" "/usr/bin/npm" "start"
19 error node v8.10.0
20 error npm v3.5.2
21 error code ELIFECYCLE
22 error joker@1.0.0 start: `node index.js`
22 error Exit status 1
23 error Failed at the joker@1.0.0 start script 'node index.js'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the joker package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error node index.js
23 error You can get information on how to open an issue for this project with:
23 error npm bugs joker
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls joker
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]