EC2 Default User

Distinguish id being played

Showing 1 changed file with 83 additions and 14 deletions
......@@ -21,6 +21,7 @@ app.use(bodyParser.json());
app.post('/hook', function (req, res) {
var eventObj = req.body.events[0];
console.log(eventObj);
var source = eventObj.source;
var message = eventObj.message;
......@@ -30,17 +31,91 @@ app.post('/hook', function (req, res) {
console.log('[request source] ', source);
console.log('[request message]', message);
wordchain(eventObj.replyToken, message.text);
wordchain(eventObj.replyToken, message.text, source.userId);
res.sendStatus(200);
});
function wordchain(replyToken, message) {
var playingId = [];
function isCommand(message)
{
return message == '/시작' || message == '/종료' ? true : false;
}
let letter = message.slice(-1);
function wordchain(replyToken, message, userId) {
if (isCommand(message)){
request.post(
if(message == '/시작') {
playingId.push(userId);
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":replyToken,
"messages":[
{
"type":"text",
"text": "게임이 시작되었습니다.\n단어를 제시해주세요"
}
]
}
},(error, response, body) => {
console.log(body);
});
} else {
var num = playingId.indexOf(userId);
playingId.splice(num, 1);
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":replyToken,
"messages":[
{
"type":"text",
"text": "게임이 종료되었습니다."
}
]
}
},(error, response, body) => {
console.log(body);
});
};
} else {
if(!playingId.includes(userId)) {
request.post(
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
},
json: {
"replyToken":replyToken,
"messages":[
{
"type":"text",
"text": "안녕하세요. 끝말잇기봇입니다.\n-표준어 내의 명사만 가능\n\t(표준국어대사전에 근거)\n-한 글자 단어 금지\n-중복 단어 금지\n시작: '/시작', 종료: '/종료' 입력"
}
]
}
},(error, response, body) => {
console.log(body);
});
} else {
var word = message;
let letter = word.slice(-1);
console.log(letter);
request.post(
{
url: STDICT_URL,
headers: {
......@@ -56,11 +131,8 @@ function wordchain(replyToken, message) {
var nextword = parsedData.channel.item[0].word;
var word_definition = parsedData.channel.item[0].sense.definition;
request.post(
{
{
url: TARGET_URL,
headers: {
'Authorization': `Bearer ${TOKEN}`
......@@ -70,11 +142,7 @@ function wordchain(replyToken, message) {
"messages":[
{
"type":"text",
"text":nextword
},
{
"type":"text",
"text":': ' + word_definition
"text":nextword + ': ' + word_definition
}
]
}
......@@ -83,7 +151,8 @@ function wordchain(replyToken, message) {
});
}
});
}
}
}
//SSL
......