신원형

main.js temparatory edit

const express = require('express');
const request = require('request');
const talk = require('./talk')
const fs = require('fs');
const path = require('path');
const HTTPS = require('https');
const bodyParser = require('body-parser');
var latitude = 37.2429832;
var longitude = 127.0749535;
var locationAdd = "경기 용인시 기흥구 서그내로49번길 13"
var location_name = "카페 서천"
const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
const tokens = JSON.parse(fs.readFileSync("setting.json"))
const sslport = 23023;
......@@ -21,6 +14,11 @@ const TOKEN = tokens.channel
const id = tokens.id
const pw = tokens.pw
const canvas = require('./khcanvas')
const selector = require('./schedule_selector')
const weather = require('./weather')
function sendText(replyToken, messages) {
request.post(
{
......@@ -46,7 +44,7 @@ function sendText(replyToken, messages) {
// OR
// https://developers.line.biz/en/reference/messaging-api/#location-message
function sendImage(replyToken, imageUrl) {
function sendLocation(replyToken, latitude, longitude, locationAdd, locationName) {
request.post(
{
url: TARGET_URL,
......@@ -70,9 +68,28 @@ function sendImage(replyToken, imageUrl) {
});
}
function filter_date(date, id, pw) {
const schedule = canvas.get_schedule(id, pw, date)
const first_todo = selector.is_possible_schedule(date, schedule)
if (first_todo) {
return `제출되지 않은 과제가 있습니다. ${first_todo}`
}
return null
}
/*
1. 사용자가 아무 메세지나 입력?
2. 이캠퍼스 일정 찾기
3. 날씨 적절한지 판단
4. 카테고리 물어보기
5. 랜덤 위치를 알려주는 메세지 반환
*/
var app = express();
app.use(bodyParser.json());
app.post('/hook', function (req, res) {
app.post('/hook', async function (req, res) {
var eventObj = req.body.events[0];
// var source = eventObj.source;
......@@ -84,20 +101,30 @@ app.post('/hook', function (req, res) {
console.log('[request source] ', eventObj.source);
console.log('[request message]', eventObj.message);
sendText(eventObj.replyToken, talk.start(id, pw)) // Test only
//sendImage(eventObj.replyToken)
const today = new Date()
const filter_result = filter_date(today, id, pw)
if (filter_result) {
sendText(eventObj.replyToken, filter_result)
}
(await weather.get_weather_current()).then(it => {
})
res.sendStatus(200);
});
try {
const option = {
ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'),
key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(),
cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(),
};
// const option = {
// ca: fs.readFileSync('/etc/letsencrypt/live/' + domain + '/fullchain.pem'),
// key: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/privkey.pem'), 'utf8').toString(),
// cert: fs.readFileSync(path.resolve(process.cwd(), '/etc/letsencrypt/live/' + domain + '/cert.pem'), 'utf8').toString(),
// };
HTTPS.createServer(option, app).listen(sslport, () => {
HTTPS.createServer(app).listen(sslport, () => {
console.log(`[HTTPS] Server is started on port ${sslport}`);
});
} catch (error) {
......
const canvas = require('./khcanvas')
const selector = require('./schedule_selector')
function start(id, pw) {
const today = new Date()
const filter_result = filter_date(today, id, pw)
if(filter_result) {
return filter_result
}
}
function filter_date(date, id, pw) {
const schedule = canvas.get_schedule(id, pw, date)
const first_todo = selector.is_possible_schedule(date, schedule)
if(first_todo) {
return `제출되지 않은 과제가 있습니다. ${first_todo}`
}
return null
}
module.exports.start = start
\ No newline at end of file