김민욱

modify database code

......@@ -10,7 +10,7 @@ message_recieved = 0;
exports.startbot = ()=>{
// Get authorization to use the slackbot
const bot = new SlackBot({
token : "xoxb-651692943605-645515979745-sqycGNiTIOZNxnly4k1BV1HO",
token : "xoxb-651692943605-645515979745-VInZkUepi88jyzhpps44uRyM",
name : "jokebot"
});
......@@ -142,7 +142,7 @@ function MakeJoke(message,user_channel){
var user=temp[0].substring(2,temp[0].length-1);
console.log('유저 => '+user);
var path='./joke_data/'+user+'.json';
var path='./joke_data/user.json';
console.log(path);
fs.exists(path,function(exists){
if(exists){
......@@ -154,8 +154,8 @@ function MakeJoke(message,user_channel){
else{
obj=JSON.parse(data);
var length=obj.table.length;
obj.table.push({id : length+1, type : 'userjoke', setup : msg[0], punchline : msg[1]});
var myobj = {id : length+1, type : 'userjoke', setup : msg[0], punchline : msg[1]};
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){
if(err) throw err;
var dbo = db.db("userdb");
......@@ -181,8 +181,8 @@ function MakeJoke(message,user_channel){
}
else{
console.log("file not exists");
obj.table.push({id : 1, type : 'userjoke', setup : msg[0], punchline : msg[1]});
var myobj = {id : 1, type : 'userjoke', setup : msg[0], punchline : msg[1]};
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;
......@@ -387,7 +387,7 @@ redditJoke= (user_channel)=>{
user.then(function(total){
title = total.title;
bot.postMessageToChannel(user_channel, title, emoji.emojis('smiliey'));
console.log("질문 불려짐");
console.log("quiz~");
return total;
})
.then((all)=>{
......@@ -395,7 +395,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("허무개그 전송~~~~~~!");
console.log("reddit joke~~~");
},3000);
})
client.close();
......
{"table":[{"id":1,"type":"userjoke","setup":" one plus one equals?","punchline":" window!!"}]}
\ No newline at end of file
{"table":[{"id":1,"type":"userjoke","setup":" hello","punchline":" ok"}]}
\ 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"}]}
\ No newline at end of file
......
......@@ -264,18 +264,18 @@
}
},
"mongodb": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.2.6.tgz",
"integrity": "sha512-qnHc4tjEkHKemuzBq9R7ycYnhFE0Dlpt6+n6suoZp2DcDdqviQ+teloJU24fsOw/PLmr75yGk4mRx/YabjDQEQ==",
"version": "3.2.7",
"resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.2.7.tgz",
"integrity": "sha512-2YdWrdf1PJgxcCrT1tWoL6nHuk6hCxhddAAaEh8QJL231ci4+P9FLyqopbTm2Z2sAU6mhCri+wd9r1hOcHdoMw==",
"requires": {
"mongodb-core": "3.2.6",
"mongodb-core": "3.2.7",
"safe-buffer": "^5.1.2"
}
},
"mongodb-core": {
"version": "3.2.6",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.2.6.tgz",
"integrity": "sha512-i+XRVjur9D0ywGF7cFebOUnALnbvMHajdNhhl3TQuopW6QDE655G8CpPeERbqSqfa3rOKEUo08lENDIiBIuAvQ==",
"version": "3.2.7",
"resolved": "https://registry.npmjs.org/mongodb-core/-/mongodb-core-3.2.7.tgz",
"integrity": "sha512-WypKdLxFNPOH/Jy6i9z47IjG2wIldA54iDZBmHMINcgKOUcWJh8og+Wix76oGd7EyYkHJKssQ2FAOw5Su/n4XQ==",
"requires": {
"bson": "^1.1.1",
"require_optional": "^1.0.1",
......
......@@ -11,7 +11,7 @@
"dependencies": {
"axios": "^0.18.1",
"fs": "0.0.1-security",
"mongodb": "^3.2.6",
"mongodb": "^3.2.7",
"slackbots": "^1.2.0"
}
}
......