Showing
2 changed files
with
160 additions
and
127 deletions
1 | -const lineCtrl = require("./line.ctrl"); | 1 | +// const lineCtrl = require("./line.ctrl"); |
2 | 2 | ||
3 | -var Koa = require('koa'); | 3 | +// var Koa = require('koa'); |
4 | -const request = require('request'); | 4 | +// const request = require('request'); |
5 | -const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 5 | +// const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
6 | -const TOKEN = 'iaoVQEV5adLHh7MbW8bZvHKoULoKZUD6B0bXD2l0srO+yXyXKRe4HBLvWQwrkKQx2fwdsz1O/qVpVh9eucUf9GxRb8w2dSaaWCXd9FTqDLP5Yu9xovneGprYlU/0VKSAVw1iphi9BfJWfjIjwWY2pAdB04t89/1O/w1cDnyilFU='; | 6 | +// const TOKEN = 'iaoVQEV5adLHh7MbW8bZvHKoULoKZUD6B0bXD2l0srO+yXyXKRe4HBLvWQwrkKQx2fwdsz1O/qVpVh9eucUf9GxRb8w2dSaaWCXd9FTqDLP5Yu9xovneGprYlU/0VKSAVw1iphi9BfJWfjIjwWY2pAdB04t89/1O/w1cDnyilFU='; |
7 | -const fs = require('fs'); | 7 | +// const fs = require('fs'); |
8 | -const path = require('path'); | 8 | +// const path = require('path'); |
9 | -const HTTPS = require('https'); | 9 | +// const HTTPS = require('https'); |
10 | -const domain = "www.ossjaksimsamil.ml" | 10 | +// const domain = "www.ossjaksimsamil.ml" |
11 | -const sslport = 23023; | 11 | +// const sslport = 23023; |
12 | 12 | ||
13 | -const bodyParser = require('body-parser'); | 13 | +// const bodyParser = require('body-parser'); |
14 | -var app = new Koa(); | 14 | +// var app = new Koa(); |
15 | -app.use(bodyParser.json()); | 15 | +// app.use(bodyParser.json()); |
16 | -let username; //username 저장 | 16 | +// let username; //username 저장 |
17 | -app.post('/hook', function (req, res) { | 17 | +// app.post('/hook', function (req, res) { |
18 | 18 | ||
19 | - var eventObj = req.body.events[0]; | 19 | +// var eventObj = req.body.events[0]; |
20 | - //var source = eventObj.source; | 20 | +// //var source = eventObj.source; |
21 | - //var message = eventObj.message; | 21 | +// //var message = eventObj.message; |
22 | 22 | ||
23 | - // request log | 23 | +// // request log |
24 | - console.log('======================', new Date() ,'======================'); | 24 | +// console.log('======================', new Date() ,'======================'); |
25 | - console.log('[request]', req.body); | 25 | +// console.log('[request]', req.body); |
26 | - console.log('[request source] ', eventObj.source); | 26 | +// console.log('[request source] ', eventObj.source); |
27 | - console.log('[request message]', eventObj.message); | 27 | +// console.log('[request message]', eventObj.message); |
28 | - if((eventObj.message.text == '문제추천')&&(username != undefined)){ | 28 | +// if((eventObj.message.text == '문제추천')&&(username != undefined)){ |
29 | - console.log("문제를 추천합니다."); | 29 | +// console.log("문제를 추천합니다."); |
30 | - recommendData = lineCtrl.lineRecommend(username); | 30 | +// recommendData = lineCtrl.lineRecommend(username); |
31 | - recommendBJ(eventObj.replyToken, recommendData); | 31 | +// recommendBJ(eventObj.replyToken, recommendData); |
32 | - } else { | 32 | +// } else { |
33 | - let isExist = lineCtrl.findID(eventObj.message.text); | 33 | +// let isExist = lineCtrl.findID(eventObj.message.text); |
34 | - if (isExist == true) | 34 | +// if (isExist == true) |
35 | - username = eventObj.message.text; | 35 | +// username = eventObj.message.text; |
36 | - else{ | 36 | +// else{ |
37 | - request.post( | 37 | +// request.post( |
38 | - { | 38 | +// { |
39 | - url: TARGET_URL, | 39 | +// url: TARGET_URL, |
40 | - headers: { | 40 | +// headers: { |
41 | - 'Authorization': `Bearer ${TOKEN}` | 41 | +// 'Authorization': `Bearer ${TOKEN}` |
42 | - }, | 42 | +// }, |
43 | - json: { | 43 | +// json: { |
44 | - "replyToken":replyToken, | 44 | +// "replyToken":replyToken, |
45 | - "messages":[ | 45 | +// "messages":[ |
46 | - { | 46 | +// { |
47 | - "type":"text", | 47 | +// "type":"text", |
48 | - "text": "작심삼일 혹은 백준 사이트의 ID값이 올바르지 않습니다. 다시 입력해주세요." | 48 | +// "text": "작심삼일 혹은 백준 사이트의 ID값이 올바르지 않습니다. 다시 입력해주세요." |
49 | - } | 49 | +// } |
50 | - ] | 50 | +// ] |
51 | - } | 51 | +// } |
52 | - },(body) => { | 52 | +// },(body) => { |
53 | - console.log(body) | 53 | +// console.log(body) |
54 | - }); | 54 | +// }); |
55 | - } | 55 | +// } |
56 | 56 | ||
57 | - recommendBJ(eventObj.replyToken, eventObj.message.text); | 57 | +// recommendBJ(eventObj.replyToken, eventObj.message.text); |
58 | - } | 58 | +// } |
59 | - res.sendStatus(200); | 59 | +// res.sendStatus(200); |
60 | -}, | 60 | +// }, |
61 | 61 | ||
62 | -function recommendBJ(replyToken, message) { | 62 | +// function recommendBJ(replyToken, message) { |
63 | - var recommendProblem = "오늘의 추천문제는 " + message.problem_title + "입니다."; | 63 | +// var recommendProblem = "오늘의 추천문제는 " + message.problem_title + "입니다."; |
64 | - var problemURL = "https://www.boj.kr/" + recommendData.problem_number; | 64 | +// var problemURL = "https://www.boj.kr/" + recommendData.problem_number; |
65 | - request.post( | 65 | +// request.post( |
66 | - { | 66 | +// { |
67 | - url: TARGET_URL, | 67 | +// url: TARGET_URL, |
68 | - headers: { | 68 | +// headers: { |
69 | - 'Authorization': `Bearer ${TOKEN}` | 69 | +// 'Authorization': `Bearer ${TOKEN}` |
70 | - }, | 70 | +// }, |
71 | - json: { | 71 | +// json: { |
72 | - "replyToken":replyToken, | 72 | +// "replyToken":replyToken, |
73 | - "messages":[ | 73 | +// "messages":[ |
74 | - { | 74 | +// { |
75 | - "type":"text", | 75 | +// "type":"text", |
76 | - "text": recommendProblem | 76 | +// "text": recommendProblem |
77 | - }, | 77 | +// }, |
78 | - { | 78 | +// { |
79 | - "type":"text", | 79 | +// "type":"text", |
80 | - "text": problemURL | 80 | +// "text": problemURL |
81 | - } | 81 | +// } |
82 | - ] | 82 | +// ] |
83 | - } | 83 | +// } |
84 | - },(body) => { | 84 | +// },(body) => { |
85 | - console.log(body) | 85 | +// console.log(body) |
86 | - }); | 86 | +// }); |
87 | 87 | ||
88 | 88 | ||
89 | - res.sendStatus(200); | 89 | +// res.sendStatus(200); |
90 | -}); | 90 | +// }); |
91 | 91 | ||
92 | -try { | 92 | +// try { |
93 | - const option = { | 93 | +// const option = { |
94 | - ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), | 94 | +// ca: fs.readFileSync('/etc/letsencrypt/live/' + domain +'/fullchain.pem'), |
95 | - key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), | 95 | +// key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/privkey.pem'), 'utf8').toString(), |
96 | - cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), | 96 | +// cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), |
97 | - }; | 97 | +// }; |
98 | 98 | ||
99 | - HTTPS.createServer(option, app).listen(sslport, () => { | ||
100 | - console.log(`[HTTPS] Server is started on port ${sslport}`); | ||
101 | - }); | ||
102 | - } catch (error) { | ||
103 | - console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | ||
104 | - console.log(error); | ||
105 | - } | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
99 | +// HTTPS.createServer(option, app).listen(sslport, () => { | ||
100 | +// console.log(`[HTTPS] Server is started on port ${sslport}`); | ||
101 | +// }); | ||
102 | +// } catch (error) { | ||
103 | +// console.log('[HTTPS] HTTPS 오류가 발생하였습니다. HTTPS 서버는 실행되지 않습니다.'); | ||
104 | +// console.log(error); | ||
105 | +// } | ||
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | -var Koa = require('koa'); | ||
2 | const request = require('request'); | 1 | const request = require('request'); |
3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 2 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
4 | const TOKEN = 'iaoVQEV5adLHh7MbW8bZvHKoULoKZUD6B0bXD2l0srO+yXyXKRe4HBLvWQwrkKQx2fwdsz1O/qVpVh9eucUf9GxRb8w2dSaaWCXd9FTqDLP5Yu9xovneGprYlU/0VKSAVw1iphi9BfJWfjIjwWY2pAdB04t89/1O/w1cDnyilFU='; | 3 | const TOKEN = 'iaoVQEV5adLHh7MbW8bZvHKoULoKZUD6B0bXD2l0srO+yXyXKRe4HBLvWQwrkKQx2fwdsz1O/qVpVh9eucUf9GxRb8w2dSaaWCXd9FTqDLP5Yu9xovneGprYlU/0VKSAVw1iphi9BfJWfjIjwWY2pAdB04t89/1O/w1cDnyilFU='; |
... | @@ -8,12 +7,12 @@ const HTTPS = require('https'); | ... | @@ -8,12 +7,12 @@ const HTTPS = require('https'); |
8 | const domain = "www.ossjaksimsamil.ml" | 7 | const domain = "www.ossjaksimsamil.ml" |
9 | const sslport = 23023; | 8 | const sslport = 23023; |
10 | 9 | ||
11 | -const bodyParser = require('body-parser'); | ||
12 | - | ||
13 | const Profile = require("../../models/profile"); | 10 | const Profile = require("../../models/profile"); |
14 | const problem_set = require("../../data/problem_set"); | 11 | const problem_set = require("../../data/problem_set"); |
15 | const compareBJ = require("../../util/compareBJ"); | 12 | const compareBJ = require("../../util/compareBJ"); |
13 | +const user = require('../user'); | ||
16 | 14 | ||
15 | +let username = ""; | ||
17 | 16 | ||
18 | exports.linestart = function(req,res) { | 17 | exports.linestart = function(req,res) { |
19 | var eventObj = req.body.events[0]; | 18 | var eventObj = req.body.events[0]; |
... | @@ -25,37 +24,71 @@ exports.linestart = function(req,res) { | ... | @@ -25,37 +24,71 @@ exports.linestart = function(req,res) { |
25 | console.log('[request]', req.body); | 24 | console.log('[request]', req.body); |
26 | console.log('[request source] ', eventObj.source); | 25 | console.log('[request source] ', eventObj.source); |
27 | console.log('[request message]', eventObj.message); | 26 | console.log('[request message]', eventObj.message); |
28 | - if((eventObj.message.text == '문제추천')&&(username != undefined)){ | ||
29 | - console.log("문제를 추천합니다."); | ||
30 | - recommendData = lineCtrl.lineRecommend(username); | ||
31 | - recommendBJ(eventObj.replyToken, recommendData); | ||
32 | - } else { | ||
33 | - let isExist = lineCtrl.findID(eventObj.message.text); | ||
34 | - if (isExist == true) | ||
35 | - username = eventObj.message.text; | ||
36 | - else{ | ||
37 | - request.post( | ||
38 | - { | ||
39 | - url: TARGET_URL, | ||
40 | - headers: { | ||
41 | - 'Authorization': `Bearer ${TOKEN}` | ||
42 | - }, | ||
43 | - json: { | ||
44 | - "replyToken":replyToken, | ||
45 | - "messages":[ | ||
46 | - { | ||
47 | - "type":"text", | ||
48 | - "text": "작심삼일 혹은 백준 사이트의 ID값이 올바르지 않습니다. 다시 입력해주세요." | ||
49 | - } | ||
50 | - ] | ||
51 | - } | ||
52 | - },(body) => { | ||
53 | - console.log(body) | ||
54 | - }); | ||
55 | - } | ||
56 | 27 | ||
57 | - recommendBJ(eventObj.replyToken, eventObj.message.text); | 28 | + if(username == "") { |
29 | + username = eventObj.message.text; | ||
30 | + } | ||
31 | + | ||
32 | + if (!isExist(username)) { | ||
33 | + username = ""; | ||
34 | + | ||
35 | + request.post( | ||
36 | + { | ||
37 | + url: TARGET_URL, | ||
38 | + headers: { | ||
39 | + 'Authorization': `Bearer ${TOKEN}` | ||
40 | + }, | ||
41 | + json: { | ||
42 | + "replyToken":replyToken, | ||
43 | + "messages":[ | ||
44 | + { | ||
45 | + "type":"text", | ||
46 | + "text": "작심삼일 혹은 백준 사이트의 ID값이 올바르지 않습니다. 다시 입력해주세요." | ||
47 | + } | ||
48 | + ] | ||
49 | + } | ||
50 | + },(body) => { | ||
51 | + console.log(body) | ||
52 | + }); | ||
53 | + } | ||
54 | + | ||
55 | + if(eventObj.message.text == "문제") { | ||
56 | + console.log("문제를 추천합니다."); | ||
57 | + recommendData = lineRecommend(username); | ||
58 | + recommendBJ(eventObj.replyToken, recommendData); | ||
58 | } | 59 | } |
60 | + | ||
61 | + // if((eventObj.message.text == '문제추천')&&(username != undefined)){ | ||
62 | + // console.log("문제를 추천합니다."); | ||
63 | + // recommendData = lineRecommend(username); | ||
64 | + // recommendBJ(eventObj.replyToken, recommendData); | ||
65 | + // } else { | ||
66 | + // let isExist = lineCtrl.findID(eventObj.message.text); | ||
67 | + // if (isExist == true) | ||
68 | + // username = eventObj.message.text; | ||
69 | + // else{ | ||
70 | + // request.post( | ||
71 | + // { | ||
72 | + // url: TARGET_URL, | ||
73 | + // headers: { | ||
74 | + // 'Authorization': `Bearer ${TOKEN}` | ||
75 | + // }, | ||
76 | + // json: { | ||
77 | + // "replyToken":replyToken, | ||
78 | + // "messages":[ | ||
79 | + // { | ||
80 | + // "type":"text", | ||
81 | + // "text": "작심삼일 혹은 백준 사이트의 ID값이 올바르지 않습니다. 다시 입력해주세요." | ||
82 | + // } | ||
83 | + // ] | ||
84 | + // } | ||
85 | + // },(body) => { | ||
86 | + // console.log(body) | ||
87 | + // }); | ||
88 | + // } | ||
89 | + | ||
90 | + // recommendBJ(eventObj.replyToken, eventObj.message.text); | ||
91 | + // } | ||
59 | res.sendStatus(200); | 92 | res.sendStatus(200); |
60 | } | 93 | } |
61 | 94 | ... | ... |
-
Please register or login to post a comment