유재형
Committed by Ma Suhyeon

edit recommend item

Showing 1 changed file with 10 additions and 3 deletions
......@@ -28,13 +28,20 @@ function onMessage(message, replyToken) {
if(message.type != 'text')
return;
let sql = 'SELECT i.`name` FROM `character_items` c JOIN `items` i ON c.`item`=i.`id` WHERE c.`character_id`=? ORDER BY c.`count` DESC LIMIT 0,5';
pool.query(sql, [message.text]).then(function([results]) {
if(message.text.indexOf('아이템') >= 0)
recommendItem(message.text.split(' ')[0], replyToken);
}
function recommendItem(charAlias, replyToken) {
let sql = 'SELECT n.`alias`, i.`name` FROM `character_aliases` a JOIN `character_items` c ON a.`character_id`=c.`character_id` JOIN `character_aliases` n ON c.`character_id`=n.`character_id` JOIN `items` i ON c.`item`=i.`id` WHERE a.`alias`=? AND n.`is_name`=1 ORDER BY c.`count` DESC LIMIT 0,5';
pool.query(sql, [charAlias]).then(function([results]) {
let reply;
if(results.length == 0)
reply = '데이터가 없습니다.';
else
reply = `${message.text}의 추천 아이템은 ${results.map(e => e.name).join(', ')} 입니다.`;
reply = `${results[0].alias}의 추천 아이템은 ${results.map(e => e.name).join(', ')} 입니다.`;
axios.post('https://api.line.me/v2/bot/message/reply', {
replyToken: replyToken,
......