Showing
4 changed files
with
114 additions
and
9 deletions
This diff is collapsed. Click to expand it.
... | @@ -6,11 +6,13 @@ const friend = require("./friend"); | ... | @@ -6,11 +6,13 @@ const friend = require("./friend"); |
6 | const notify = require("./notify"); | 6 | const notify = require("./notify"); |
7 | const user = require("./user"); | 7 | const user = require("./user"); |
8 | const profile = require("./profile"); | 8 | const profile = require("./profile"); |
9 | +const line = require("./line") | ||
9 | 10 | ||
10 | api.use("/auth", auth.routes()); | 11 | api.use("/auth", auth.routes()); |
11 | api.use("/friend", friend.routes()); | 12 | api.use("/friend", friend.routes()); |
12 | api.use("/notify", notify.routes()); | 13 | api.use("/notify", notify.routes()); |
13 | api.use("/user", user.routes()); | 14 | api.use("/user", user.routes()); |
14 | api.use("/profile", profile.routes()); | 15 | api.use("/profile", profile.routes()); |
16 | +api.use("/line", line.routes()); | ||
15 | 17 | ||
16 | -module.exports = api; | 18 | +module.exports = api; |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
... | @@ -3,11 +3,11 @@ const lineCtrl = require("./line.ctrl"); | ... | @@ -3,11 +3,11 @@ const lineCtrl = require("./line.ctrl"); |
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 = 'tdN03DyXDAcKGZsuiPndaU7UC2GzuEQYUhPCkDnGWXGGdiPmV15QYbFU1U5JP5EpiETIKLqOmci/RxFZTfD7FRMED0OpT+3qgEYBNf8T9/jRzHRm7rblBLtzFBVOeXeYRcluOsz4koE4JaAJaUtMtwdB04t89/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.osstest17.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'); | ... | ... |
1 | +var Koa = require('koa'); | ||
2 | +const request = require('request'); | ||
3 | +const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | ||
4 | +const TOKEN = 'iaoVQEV5adLHh7MbW8bZvHKoULoKZUD6B0bXD2l0srO+yXyXKRe4HBLvWQwrkKQx2fwdsz1O/qVpVh9eucUf9GxRb8w2dSaaWCXd9FTqDLP5Yu9xovneGprYlU/0VKSAVw1iphi9BfJWfjIjwWY2pAdB04t89/1O/w1cDnyilFU='; | ||
5 | +const fs = require('fs'); | ||
6 | +const path = require('path'); | ||
7 | +const HTTPS = require('https'); | ||
8 | +const domain = "www.ossjaksimsamil.ml" | ||
9 | +const sslport = 23023; | ||
10 | + | ||
11 | +const bodyParser = require('body-parser'); | ||
12 | + | ||
1 | const Profile = require("../../models/profile"); | 13 | const Profile = require("../../models/profile"); |
2 | const problem_set = require("../../data/problem_set"); | 14 | const problem_set = require("../../data/problem_set"); |
3 | const compareBJ = require("../../util/compareBJ"); | 15 | const compareBJ = require("../../util/compareBJ"); |
4 | 16 | ||
17 | + | ||
18 | +exports.linestart = function(req,res) { | ||
19 | + var eventObj = req.body.events[0]; | ||
20 | + //var source = eventObj.source; | ||
21 | + //var message = eventObj.message; | ||
22 | + | ||
23 | + // request log | ||
24 | + console.log('======================', new Date() ,'======================'); | ||
25 | + console.log('[request]', req.body); | ||
26 | + console.log('[request source] ', eventObj.source); | ||
27 | + 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 | + | ||
57 | + recommendBJ(eventObj.replyToken, eventObj.message.text); | ||
58 | + } | ||
59 | + res.sendStatus(200); | ||
60 | +} | ||
61 | + | ||
62 | +function recommendBJ(replyToken, message) { | ||
63 | + var recommendProblem = "오늘의 추천문제는 " + message.problem_title + "입니다."; | ||
64 | + var problemURL = "https://www.boj.kr/" + recommendData.problem_number; | ||
65 | + request.post( | ||
66 | + { | ||
67 | + url: TARGET_URL, | ||
68 | + headers: { | ||
69 | + 'Authorization': `Bearer ${TOKEN}` | ||
70 | + }, | ||
71 | + json: { | ||
72 | + "replyToken":replyToken, | ||
73 | + "messages":[ | ||
74 | + { | ||
75 | + "type":"text", | ||
76 | + "text": recommendProblem | ||
77 | + }, | ||
78 | + { | ||
79 | + "type":"text", | ||
80 | + "text": problemURL | ||
81 | + } | ||
82 | + ] | ||
83 | + } | ||
84 | + },(body) => { | ||
85 | + console.log(body) | ||
86 | + }); | ||
87 | + | ||
88 | + | ||
89 | + res.sendStatus(200); | ||
90 | +} | ||
91 | + | ||
92 | +try { | ||
93 | + const option = { | ||
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(), | ||
96 | + cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain +'/cert.pem'), 'utf8').toString(), | ||
97 | + }; | ||
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 | +} | ||
106 | + | ||
107 | + | ||
5 | /* | 108 | /* |
6 | POST api/notify/slack/recommend | 109 | POST api/notify/slack/recommend |
7 | { | 110 | { |
8 | username: "username" | 111 | username: "username" |
9 | } | 112 | } |
10 | */ | 113 | */ |
11 | -exports.lineRecommend = (username) => { | 114 | +function lineRecommend(username) { |
12 | 115 | ||
13 | const profile = await Profile.findByUsername(username); | 116 | const profile = await Profile.findByUsername(username); |
14 | if (!profile) { | 117 | if (!profile) { |
... | @@ -24,13 +127,13 @@ exports.lineRecommend = (username) => { | ... | @@ -24,13 +127,13 @@ exports.lineRecommend = (username) => { |
24 | if (!recommendData) { | 127 | if (!recommendData) { |
25 | console.log("402"); | 128 | console.log("402"); |
26 | return; | 129 | return; |
27 | - } else { | 130 | + } |
28 | - return recommendData; | 131 | + |
29 | - } | 132 | + return recommendData; |
133 | + | ||
30 | }; | 134 | }; |
31 | 135 | ||
32 | -exports.isExist = (id) => | 136 | +function isExist(username) { |
33 | -{ | ||
34 | const profile = await Profile.findByUsername(username); | 137 | const profile = await Profile.findByUsername(username); |
35 | if (!profile) { | 138 | if (!profile) { |
36 | return false; | 139 | return false; | ... | ... |
-
Please register or login to post a comment