박권수

add README.md in line and drop unecessary module and code

......@@ -50,6 +50,7 @@ app.listen(SERVER_PORT, () => {
console.log("Server is running on port", process.env.SERVER_PORT);
});
//for Line Channel
try {
const option = {
ca: fs.readFileSync('/etc/letsencrypt/live/' + DOMAIN +'/fullchain.pem'),
......
const Router = require("koa-router");
const auth = new Router();
const authCtrl = require("./auth.ctrl");
const kakaoAuth = require("./kakaoAuth");
auth.post("/login", authCtrl.login);
auth.post("/logout", authCtrl.logout);
auth.post("/register", authCtrl.register);
auth.get("/check", authCtrl.check);
auth.post("/kakaotoken", kakaoAuth.kakaotoken);
module.exports = auth;
......
const request = require('request');
const querystring = require('querystring');
exports.kakaotoken = async (ctx) => {
const token = ctx.request.body;
'http://kapi.kakao.com/v2/api/talk/memo/default/send'
console.log(ctx);
console.log("token setted", token);
let template_objectObj = {
object_type: "text",
text: "hi", link: {
web_url: "https://developers.kakao.com",
}
};
let template_objectStr = JSON.stringify(template_objectObj);
console.log(template_objectStr);
let options = {
url: "http://kapi.kakao.com/v2/api/talk/memo/default/send",
method: "POST",
headers: {
"Authorization": "Bearer ".concat(token),
"Content-Type": "application/x-www-form-urlencoded"
}, form: {
template_object: template_objectStr
}
};
request.post(options, (err, res, body) => {
if (err != null) {
console.log(err);
}
});
};
\ No newline at end of file
......@@ -8,8 +8,17 @@ const Profile = require("../../models/profile");
const problem_set = require("../../data/problem_set");
const compareBJ = require("../../util/compareBJ");
/*
username : default = ""
*/
let username = "";
/*
POST api/line/hook
{
for line reply : recommend and set
}
*/
exports.linestart = async(ctx) => {
var eventObj = ctx.request.body.events[0];
......@@ -20,6 +29,7 @@ exports.linestart = async(ctx) => {
console.log('[request message]', eventObj.message);
console.log('[username]', username);
//first . set User
if(username == "") {
username = eventObj.message.text;
......@@ -38,7 +48,7 @@ exports.linestart = async(ctx) => {
"messages":[
{
"type":"text",
"text": "작심삼일 혹은 백준 사이트의 ID값이 올바르지 않습니다. 다시 입력해주세요."
"text": "작심삼일 사이트의 ID값이 올바르지 않습니다. 다시 입력해주세요."
}
]
}
......@@ -67,7 +77,7 @@ exports.linestart = async(ctx) => {
}
};
//second. can reset username
if(eventObj.message.text == "reset ID") {
username = "";
request.post(
......@@ -81,7 +91,7 @@ exports.linestart = async(ctx) => {
"messages":[
{
"type":"text",
"text": "작심삼일 혹은 백준 사이트의 ID가 초기화 되었습니다."
"text": "작심삼일 사이트의 ID가 초기화 되었습니다."
}
]
}
......@@ -90,7 +100,7 @@ exports.linestart = async(ctx) => {
});
}
//main : recommend Problem
if(eventObj.message.text == "문제") {
console.log("문제를 추천합니다.");
let recommendData = await lineRecommend(username);
......@@ -101,6 +111,7 @@ exports.linestart = async(ctx) => {
}
//for recommend message
function recommendBJ(replyToken, recommendData) {
var recommendProblem = "오늘의 추천문제는 " + recommendData.problem_title + "입니다.";
var problemURL = "https://www.boj.kr/" + recommendData.problem_number;
......
const Router = require("koa-router");
const profile = new Router();
const profileCtrl = require("./profile.ctrl");
profile.post("/solved:id");
profile.get("/solvednum:id");
profile.post("/recommend", profileCtrl.recommend);
profile.patch("/syncBJ", profileCtrl.syncBJ);
profile.post("/setprofile", profileCtrl.setProfile);
profile.post("/getprofile", profileCtrl.getProfile);
module.exports = profile;
......