Showing
1 changed file
with
2 additions
and
18 deletions
1 | var express = require('express'); | 1 | var express = require('express'); |
2 | const request = require('request'); | 2 | const request = require('request'); |
3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' | 3 | const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' |
4 | -const TOKEN = '' | 4 | +const TOKEN = 'zVAczqoJ+L9oykqhEj7HoP7f6Nyb+R3T1TntHXQhYihI+KIxH4SZDGpKu0jKsMXMHKBVXpmbybA+oaV8u/dfLppKe3NHXU9AdBVypy9NgfWiFPLlcwm3GdkVPAZGoS4nvOCXWDKUb+ixPKWjlbnChAdB04t89/1O/w1cDnyilFU=' |
5 | const fs = require('fs'); | 5 | const fs = require('fs'); |
6 | const path = require('path'); | 6 | const path = require('path'); |
7 | const HTTPS = require('https'); | 7 | const HTTPS = require('https'); |
8 | const domain = "2019102226.osschatbot2022.ml" | 8 | const domain = "2019102226.osschatbot2022.ml" |
9 | const sslport = 23023; | 9 | const sslport = 23023; |
10 | - | ||
11 | - | ||
12 | - | ||
13 | const bodyParser = require('body-parser'); | 10 | const bodyParser = require('body-parser'); |
14 | var app = express(); | 11 | var app = express(); |
15 | app.use(bodyParser.json()); | 12 | app.use(bodyParser.json()); |
16 | app.post('/hook', function (req, res) { | 13 | app.post('/hook', function (req, res) { |
17 | - | ||
18 | var eventObj = req.body.events[0]; | 14 | var eventObj = req.body.events[0]; |
19 | var message = eventObj.message; | 15 | var message = eventObj.message; |
20 | - | ||
21 | function output_message(results, list) { | 16 | function output_message(results, list) { |
22 | var num = list[Math.floor(Math.random() * list.length)]; | 17 | var num = list[Math.floor(Math.random() * list.length)]; |
23 | request.post( | 18 | request.post( |
... | @@ -47,7 +42,6 @@ app.post('/hook', function (req, res) { | ... | @@ -47,7 +42,6 @@ app.post('/hook', function (req, res) { |
47 | console.log(body) | 42 | console.log(body) |
48 | }); | 43 | }); |
49 | } | 44 | } |
50 | - | ||
51 | // request log | 45 | // request log |
52 | console.log('======================', new Date(), '======================'); | 46 | console.log('======================', new Date(), '======================'); |
53 | // mwsql | 47 | // mwsql |
... | @@ -55,16 +49,13 @@ app.post('/hook', function (req, res) { | ... | @@ -55,16 +49,13 @@ app.post('/hook', function (req, res) { |
55 | var db = mysql.createConnection({ | 49 | var db = mysql.createConnection({ |
56 | host: 'chatbot.c7fzgftc3yrm.us-east-1.rds.amazonaws.com', | 50 | host: 'chatbot.c7fzgftc3yrm.us-east-1.rds.amazonaws.com', |
57 | user: 'chatbot', | 51 | user: 'chatbot', |
58 | - password: '', | 52 | + password: '11111111', |
59 | database: 'chatbot', | 53 | database: 'chatbot', |
60 | port: '3306' | 54 | port: '3306' |
61 | }); | 55 | }); |
62 | - | ||
63 | db.connect(); | 56 | db.connect(); |
64 | - | ||
65 | var max = 0; | 57 | var max = 0; |
66 | var arr2; | 58 | var arr2; |
67 | - | ||
68 | db.query('SELECT * FROM recipe', function (error, results, fields) { | 59 | db.query('SELECT * FROM recipe', function (error, results, fields) { |
69 | if (error) { | 60 | if (error) { |
70 | console.log(error); | 61 | console.log(error); |
... | @@ -86,11 +77,9 @@ app.post('/hook', function (req, res) { | ... | @@ -86,11 +77,9 @@ app.post('/hook', function (req, res) { |
86 | arr2.push(i); | 77 | arr2.push(i); |
87 | } | 78 | } |
88 | } | 79 | } |
89 | - | ||
90 | if (arr1.length != 0) { | 80 | if (arr1.length != 0) { |
91 | output_message(results, arr1); | 81 | output_message(results, arr1); |
92 | } | 82 | } |
93 | - | ||
94 | else if (arr2 != undefined) { | 83 | else if (arr2 != undefined) { |
95 | output_message(results, arr2); | 84 | output_message(results, arr2); |
96 | } | 85 | } |
... | @@ -123,21 +112,16 @@ app.post('/hook', function (req, res) { | ... | @@ -123,21 +112,16 @@ app.post('/hook', function (req, res) { |
123 | console.log(body) | 112 | console.log(body) |
124 | }); | 113 | }); |
125 | } | 114 | } |
126 | - | ||
127 | }); | 115 | }); |
128 | - | ||
129 | db.end(); | 116 | db.end(); |
130 | - | ||
131 | res.sendStatus(200); | 117 | res.sendStatus(200); |
132 | }); | 118 | }); |
133 | - | ||
134 | try { | 119 | try { |
135 | const option = { | 120 | const option = { |
136 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'), | 121 | ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'), |
137 | key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(), | 122 | key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(), |
138 | cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(), | 123 | cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(), |
139 | }; | 124 | }; |
140 | - | ||
141 | HTTPS.createServer(option, app).listen(sslport, () => { | 125 | HTTPS.createServer(option, app).listen(sslport, () => { |
142 | console.log(`[HTTPS] Server is started on port ${sslport}`); | 126 | console.log(`[HTTPS] Server is started on port ${sslport}`); |
143 | }); | 127 | }); | ... | ... |
-
Please register or login to post a comment