김민욱

merge Master and KMU develop

...@@ -16,7 +16,7 @@ MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) { ...@@ -16,7 +16,7 @@ MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
16 MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) { 16 MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
17 if (err) throw err; 17 if (err) throw err;
18 var dbo = db.db("jokeapi"); 18 var dbo = db.db("jokeapi");
19 - dbo.createCollection("joke", function(err, res) { 19 + dbo.createCollection("jokes", function(err, res) {
20 if (err) throw err; 20 if (err) throw err;
21 console.log("Collection created!"); 21 console.log("Collection created!");
22 db.close(); 22 db.close();
......
...@@ -16,7 +16,7 @@ MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) { ...@@ -16,7 +16,7 @@ MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
16 MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) { 16 MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
17 if (err) throw err; 17 if (err) throw err;
18 var dbo = db.db("FunnyStoryapi"); 18 var dbo = db.db("FunnyStoryapi");
19 - dbo.createCollection("FunnyStories", function(err, res) { 19 + dbo.createCollection("FunnyStory", function(err, res) {
20 if (err) throw err; 20 if (err) throw err;
21 console.log("Collection created!"); 21 console.log("Collection created!");
22 db.close(); 22 db.close();
......
...@@ -15,7 +15,7 @@ MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) { ...@@ -15,7 +15,7 @@ MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
15 //Create collection 15 //Create collection
16 MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) { 16 MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
17 if (err) throw err; 17 if (err) throw err;
18 - var dbo = db.db("redditjoke"); 18 + var dbo = db.db("reddit");
19 dbo.createCollection("redditjokes", function(err, res) { 19 dbo.createCollection("redditjokes", function(err, res) {
20 if (err) throw err; 20 if (err) throw err;
21 console.log("Collection created!"); 21 console.log("Collection created!");
......
1 +const MongoClient = require('mongodb').MongoClient;
2 +const jokedoc = require('../joke_data/user.json');
3 +const dbname = 'userdb';
4 +const collec = 'user';
5 +const dboperation = require('./operations.js');
6 +var url = "mongodb://localhost:27017/userdb";
7 +
8 +//Create database
9 +MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
10 + if (err) throw err;
11 + console.log("Database created!");
12 + db.close();
13 +});
14 +
15 +//Create collection
16 +MongoClient.connect(url, { useNewUrlParser: true }, function(err, db) {
17 + if (err) throw err;
18 + var dbo = db.db("userdb");
19 + dbo.createCollection("user", function(err, res) {
20 + if (err) throw err;
21 + console.log("Collection created!");
22 + db.close();
23 + });
24 + });
25 +
26 +
27 +//Storing data jokes.json data into mongodb
28 +MongoClient.connect(url,{ useNewUrlParser: true }).then((client) => {
29 +
30 + console.log('Connected correctly to server');
31 +
32 +
33 + const db = client.db(dbname);
34 +
35 + dboperation.insertDocument(db, jokedoc, collec)
36 + .then((result) => {
37 + console.log("Inserted Document:\n", result.ops);
38 +
39 + return dboperation.findDocuments(db, collec);
40 + })
41 + .catch((err) => console.log(err));
42 +
43 +})
44 +.catch((err) => console.log(err));
45 +
46 +
47 +
48 +
49 +
50 +
51 +
52 +
...@@ -3,8 +3,9 @@ const SlackBot = require('slackbots'); //link : https://github.com/mishk0/slack- ...@@ -3,8 +3,9 @@ const SlackBot = require('slackbots'); //link : https://github.com/mishk0/slack-
3 const dbname = 'jokeapi'; 3 const dbname = 'jokeapi';
4 const emoji = require('../slack_emoji'); 4 const emoji = require('../slack_emoji');
5 const url = 'mongodb://localhost:27017/'; 5 const url = 'mongodb://localhost:27017/';
6 -const fs=require('fs'); 6 +var url2 = 'mongodb://localhost:27017/userjoke'
7 -message_recieved = 0; 7 +const fs = require('fs');
8 +//const userjoke = require('./joke_data/user.json');
8 9
9 exports.startbot = ()=>{ 10 exports.startbot = ()=>{
10 // Get authorization to use the slackbot 11 // Get authorization to use the slackbot
...@@ -110,7 +111,7 @@ function handleMessage(message, current_channel){ ...@@ -110,7 +111,7 @@ function handleMessage(message, current_channel){
110 UserMakeJoke(message,current_channel); 111 UserMakeJoke(message,current_channel);
111 } 112 }
112 else if(message.includes(' me')){ 113 else if(message.includes(' me')){
113 - 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]"; 114 + 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]";
114 bot.postMessageToChannel(current_channel, "Tell you what??? :no_mouth:", emoji.emojis('no_mouth')); 115 bot.postMessageToChannel(current_channel, "Tell you what??? :no_mouth:", emoji.emojis('no_mouth'));
115 bot.postMessageToChannel(current_channel, comment, emoji.emojis('flushed')); 116 bot.postMessageToChannel(current_channel, comment, emoji.emojis('flushed'));
116 } 117 }
...@@ -154,6 +155,18 @@ function MakeJoke(message,user_channel){ ...@@ -154,6 +155,18 @@ function MakeJoke(message,user_channel){
154 obj=JSON.parse(data); 155 obj=JSON.parse(data);
155 var length=obj.table.length; 156 var length=obj.table.length;
156 obj.table.push({id : length+1, type : 'userjoke', setup : msg[0], punchline : msg[1]}); 157 obj.table.push({id : length+1, type : 'userjoke', setup : msg[0], punchline : msg[1]});
158 + var myobj = {id : length+1, type : 'userjoke', setup : msg[0], punchline : msg[1]};
159 + MongoClient.connect(url2,function(err,db){
160 + if(err) throw err;
161 + var dbo = db.db("userdb");
162 + dbo.collection("user").insertOne(myobj, function(err,res){
163 + if(err) throw err;
164 + console.log("1 insert!!");
165 + db.close;
166 + })
167 +
168 + })
169 +
157 var json=JSON.stringify(obj); 170 var json=JSON.stringify(obj);
158 fs.writeFile(path,json,'utf8',function(err){ 171 fs.writeFile(path,json,'utf8',function(err){
159 if(err){ 172 if(err){
...@@ -169,6 +182,34 @@ function MakeJoke(message,user_channel){ ...@@ -169,6 +182,34 @@ function MakeJoke(message,user_channel){
169 else{ 182 else{
170 console.log("file not exists"); 183 console.log("file not exists");
171 obj.table.push({id : 1, type : 'userjoke', setup : msg[0], punchline : msg[1]}); 184 obj.table.push({id : 1, type : 'userjoke', setup : msg[0], punchline : msg[1]});
185 + var myobj = {id : 1, type : 'userjoke', setup : msg[0], punchline : msg[1]};
186 + //Create database
187 + MongoClient.connect(url2, { useNewUrlParser: true }, function(err, db) {
188 + if (err) throw err;
189 + console.log("Database created!");
190 + db.close();
191 + });
192 +
193 + //Create collection
194 + MongoClient.connect(url2, { useNewUrlParser: true }, function(err, db) {
195 + if (err) throw err;
196 + var dbo = db.db("userdb");
197 + dbo.createCollection("user", function(err, res) {
198 + if (err) throw err;
199 + console.log("Collection created!");
200 + db.close();
201 + });
202 + });
203 + MongoClient.connect(url2,{ useNewUrlParser: true },function(err,db){
204 + if(err) throw err;
205 + var dbo = db.db("userdb");
206 + dbo.collection("user").insertOne(myobj, function(err,res){
207 + if(err) throw err;
208 + console.log("1 insert!!");
209 + db.close;
210 + })
211 +
212 + });
172 var json=JSON.stringify(obj); 213 var json=JSON.stringify(obj);
173 fs.writeFile(path,json,'utf8',function(err){ 214 fs.writeFile(path,json,'utf8',function(err){
174 if(err){ 215 if(err){
......
1 +{"table":[{"id":1,"type":"userjoke","setup":" hello","punchline":" ok"}]}
...\ No newline at end of file ...\ No newline at end of file
...@@ -44,12 +44,12 @@ ...@@ -44,12 +44,12 @@
44 "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ==" 44 "integrity": "sha512-ReZxvNHIOv88FlT7rxcXIIC0fPt4KZqZbOlivyWtXLt8ESx84zd3kMC6iK5jVeS2qt+g7ftS7ye4fi06X5rtRQ=="
45 }, 45 },
46 "axios": { 46 "axios": {
47 - "version": "0.18.0", 47 + "version": "0.18.1",
48 - "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.0.tgz", 48 + "resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz",
49 - "integrity": "sha1-MtU+SFHv3AoRmTts0AB4nXDAUQI=", 49 + "integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==",
50 "requires": { 50 "requires": {
51 - "follow-redirects": "^1.3.0", 51 + "follow-redirects": "1.5.10",
52 - "is-buffer": "^1.1.5" 52 + "is-buffer": "^2.0.2"
53 } 53 }
54 }, 54 },
55 "bcrypt-pbkdf": { 55 "bcrypt-pbkdf": {
...@@ -71,9 +71,9 @@ ...@@ -71,9 +71,9 @@
71 "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" 71 "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw="
72 }, 72 },
73 "combined-stream": { 73 "combined-stream": {
74 - "version": "1.0.7", 74 + "version": "1.0.8",
75 - "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.7.tgz", 75 + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
76 - "integrity": "sha512-brWl9y6vOB1xYPZcpZde3N9zDByXTosAeMDo4p1wzo6UMOX4vumB+TP1RZ76sfE6Md68Q0NJSrE/gbezd4Ul+w==", 76 + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
77 "requires": { 77 "requires": {
78 "delayed-stream": "~1.0.0" 78 "delayed-stream": "~1.0.0"
79 } 79 }
...@@ -92,11 +92,11 @@ ...@@ -92,11 +92,11 @@
92 } 92 }
93 }, 93 },
94 "debug": { 94 "debug": {
95 - "version": "3.2.6", 95 + "version": "3.1.0",
96 - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz", 96 + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
97 - "integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==", 97 + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
98 "requires": { 98 "requires": {
99 - "ms": "^2.1.1" 99 + "ms": "2.0.0"
100 } 100 }
101 }, 101 },
102 "delayed-stream": { 102 "delayed-stream": {
...@@ -134,11 +134,11 @@ ...@@ -134,11 +134,11 @@
134 "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" 134 "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I="
135 }, 135 },
136 "follow-redirects": { 136 "follow-redirects": {
137 - "version": "1.7.0", 137 + "version": "1.5.10",
138 - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.7.0.tgz", 138 + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
139 - "integrity": "sha512-m/pZQy4Gj287eNy94nivy5wchN3Kp+Q5WgUPNy5lJSZ3sgkVKSYV/ZChMAQVIgx1SqfZ2zBZtPA2YlXIWxxJOQ==", 139 + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
140 "requires": { 140 "requires": {
141 - "debug": "^3.2.6" 141 + "debug": "=3.1.0"
142 } 142 }
143 }, 143 },
144 "forever-agent": { 144 "forever-agent": {
...@@ -156,6 +156,11 @@ ...@@ -156,6 +156,11 @@
156 "mime-types": "^2.1.12" 156 "mime-types": "^2.1.12"
157 } 157 }
158 }, 158 },
159 + "fs": {
160 + "version": "0.0.1-security",
161 + "resolved": "https://registry.npmjs.org/fs/-/fs-0.0.1-security.tgz",
162 + "integrity": "sha1-invTcYa23d84E/I4WLV+yq9eQdQ="
163 + },
159 "getpass": { 164 "getpass": {
160 "version": "0.1.7", 165 "version": "0.1.7",
161 "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", 166 "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz",
...@@ -189,9 +194,9 @@ ...@@ -189,9 +194,9 @@
189 } 194 }
190 }, 195 },
191 "is-buffer": { 196 "is-buffer": {
192 - "version": "1.1.6", 197 + "version": "2.0.3",
193 - "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", 198 + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
194 - "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==" 199 + "integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
195 }, 200 },
196 "is-typedarray": { 201 "is-typedarray": {
197 "version": "1.0.0", 202 "version": "1.0.0",
...@@ -246,16 +251,16 @@ ...@@ -246,16 +251,16 @@
246 "optional": true 251 "optional": true
247 }, 252 },
248 "mime-db": { 253 "mime-db": {
249 - "version": "1.38.0", 254 + "version": "1.40.0",
250 - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.38.0.tgz", 255 + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.40.0.tgz",
251 - "integrity": "sha512-bqVioMFFzc2awcdJZIzR3HjZFX20QhilVS7hytkKrv7xFAn8bM1gzc/FOX2awLISvWe0PV8ptFKcon+wZ5qYkg==" 256 + "integrity": "sha512-jYdeOMPy9vnxEqFRRo6ZvTZ8d9oPb+k18PKoYNYUe2stVEBPPwsln/qWzdbmaIvnhZ9v2P+CuecK+fpUfsV2mA=="
252 }, 257 },
253 "mime-types": { 258 "mime-types": {
254 - "version": "2.1.22", 259 + "version": "2.1.24",
255 - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.22.tgz", 260 + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.24.tgz",
256 - "integrity": "sha512-aGl6TZGnhm/li6F7yx82bJiBZwgiEa4Hf6CNr8YO+r5UHr53tSTYZb102zyU50DOWWKeOv0uQLRL0/9EiKWCog==", 261 + "integrity": "sha512-WaFHS3MCl5fapm3oLxU4eYDw77IQM2ACcxQ9RIxfaC3ooc6PFuBMGZZsYpvoXS5D5QTWPieo1jjLdAm3TBP3cQ==",
257 "requires": { 262 "requires": {
258 - "mime-db": "~1.38.0" 263 + "mime-db": "1.40.0"
259 } 264 }
260 }, 265 },
261 "mongodb": { 266 "mongodb": {
...@@ -279,9 +284,9 @@ ...@@ -279,9 +284,9 @@
279 } 284 }
280 }, 285 },
281 "ms": { 286 "ms": {
282 - "version": "2.1.1", 287 + "version": "2.0.0",
283 - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", 288 + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
284 - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==" 289 + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
285 }, 290 },
286 "oauth-sign": { 291 "oauth-sign": {
287 "version": "0.9.0", 292 "version": "0.9.0",
...@@ -299,9 +304,9 @@ ...@@ -299,9 +304,9 @@
299 "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=" 304 "integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
300 }, 305 },
301 "psl": { 306 "psl": {
302 - "version": "1.1.31", 307 + "version": "1.1.32",
303 - "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.31.tgz", 308 + "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.32.tgz",
304 - "integrity": "sha512-/6pt4+C+T+wZUieKR620OpzN/LlnNKuWjy1iFLQ/UG35JqHlR/89MP1d96dUfkf6Dne3TuLQzOYEYshJ+Hx8mw==" 309 + "integrity": "sha512-MHACAkHpihU/REGGPLj4sEfc/XKW2bheigvHO1dUqjaKigMp1C8+WLQYRGgeKFMsw5PMfegZcaN8IDXK/cD0+g=="
305 }, 310 },
306 "punycode": { 311 "punycode": {
307 "version": "2.1.1", 312 "version": "2.1.1",
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
9 "author": "Yeonjun Kim", 9 "author": "Yeonjun Kim",
10 "license": "MIT", 10 "license": "MIT",
11 "dependencies": { 11 "dependencies": {
12 - "axios": "^0.18.0", 12 + "axios": "^0.18.1",
13 + "fs": "0.0.1-security",
13 "mongodb": "^3.2.6", 14 "mongodb": "^3.2.6",
14 "slackbots": "^1.2.0" 15 "slackbots": "^1.2.0"
15 } 16 }
......