Showing
1 changed file
with
90 additions
and
7 deletions
... | @@ -28,10 +28,34 @@ function onMessage(message, replyToken) { | ... | @@ -28,10 +28,34 @@ function onMessage(message, replyToken) { |
28 | if(message.type != 'text') | 28 | if(message.type != 'text') |
29 | return; | 29 | return; |
30 | 30 | ||
31 | - if(message.text.indexOf('아이템') >= 0) | 31 | + if(message.text.indexOf('아이템') >= 0) { |
32 | recommendItem(message.text.split(' ')[0], replyToken); | 32 | recommendItem(message.text.split(' ')[0], replyToken); |
33 | + return; | ||
34 | + } | ||
33 | 35 | ||
34 | - | 36 | + let keywords = [ |
37 | + '추천덱', | ||
38 | + '추천메타', | ||
39 | + '덱추천', | ||
40 | + '메타추천', | ||
41 | + '메타덱', | ||
42 | + '추천시너지', | ||
43 | + '메타시너지', | ||
44 | + '시너지추천' | ||
45 | + ]; | ||
46 | + | ||
47 | + let isMeta = false; | ||
48 | + let textOnly = message.text.replace(' ', ''); | ||
49 | + for(let k of keywords) { | ||
50 | + if(textOnly.indexOf(k) >= 0) | ||
51 | + isMeta = true; | ||
52 | + } | ||
53 | + if(isMeta) { | ||
54 | + recommendMeta(replyToken); | ||
55 | + return; | ||
56 | + } | ||
57 | + | ||
58 | + replyMessage(replyToken, [{type: 'text', text: '수행할 수 없는 명령입니다.'}]); | ||
35 | } | 59 | } |
36 | 60 | ||
37 | function recommendItem(charAlias, replyToken) { | 61 | function recommendItem(charAlias, replyToken) { |
... | @@ -43,12 +67,71 @@ function recommendItem(charAlias, replyToken) { | ... | @@ -43,12 +67,71 @@ function recommendItem(charAlias, replyToken) { |
43 | else | 67 | else |
44 | reply = `${results[0].alias}의 추천 아이템은 ${results.map(e => e.name).join(', ')} 입니다.`; | 68 | reply = `${results[0].alias}의 추천 아이템은 ${results.map(e => e.name).join(', ')} 입니다.`; |
45 | 69 | ||
46 | - axios.post('https://api.line.me/v2/bot/message/reply', { | 70 | + replyMessage(replyToken, [{type: 'text', text: reply}]); |
47 | - replyToken: replyToken, | 71 | + }); |
48 | - messages: [{type: 'text', text: reply}] | 72 | +} |
49 | - }, { | 73 | + |
50 | - headers: {'Authorization': channelToken} | 74 | +async function recommendMeta(replyToken) { |
75 | + let sql = 'SELECT * FROM decks ORDER BY `count` DESC LIMIT 0,3'; | ||
76 | + let [results] = await pool.query(sql); | ||
77 | + let messages = []; | ||
78 | + | ||
79 | + for(let row of results) { | ||
80 | + let chars = []; | ||
81 | + sql = 'SELECT `alias` FROM character_aliases WHERE character_id=? AND is_name=1'; | ||
82 | + for(let i = 1; i <= 8; i++) { | ||
83 | + [results] = await pool.query(sql, [row[`character_${i}`]]); | ||
84 | + chars.push(results[0].alias); | ||
85 | + } | ||
86 | + | ||
87 | + let traitCnt = new Map(); | ||
88 | + traitCnt.set(row.chosen, 1); | ||
89 | + | ||
90 | + let checked = new Set(); | ||
91 | + | ||
92 | + sql = 'SELECT trait FROM character_traits WHERE character_id=?'; | ||
93 | + for(let i = 0; i <= 8; i++) { | ||
94 | + if(checked.has(row[`character_${i}`])) | ||
95 | + continue; | ||
96 | + | ||
97 | + [results] = await pool.query(sql, [row[`character_${i}`]]); | ||
98 | + | ||
99 | + for(let t of results) { | ||
100 | + if(traitCnt.has(t.trait)) | ||
101 | + traitCnt.set(t.trait, traitCnt.get(t.trait) + 1); | ||
102 | + else | ||
103 | + traitCnt.set(t.trait, 1); | ||
104 | + } | ||
105 | + | ||
106 | + checked.add(row[`character_${i}`]); | ||
107 | + } | ||
108 | + | ||
109 | + let traits = []; | ||
110 | + sql = 'SELECT t.name, l.count FROM traits t JOIN trait_levels l ON t.id=l.trait_id WHERE t.id=? AND l.count <= ? ORDER BY l.count DESC LIMIT 1'; | ||
111 | + for(let [key, value] of traitCnt.entries()) { | ||
112 | + [results] = await pool.query(sql, [key, value]); | ||
113 | + if(results.length == 0) | ||
114 | + continue; | ||
115 | + | ||
116 | + traits.push(`${results[0].count}${results[0].name}`); | ||
117 | + }; | ||
118 | + | ||
119 | + [results] = await pool.query('SELECT `name` FROM traits WHERE `id`=?', [row.chosen]); | ||
120 | + messages.push({ | ||
121 | + type: 'text', | ||
122 | + text: traits.join(', ') + '\n' + chars.join(', ') + '\n' + '선택받은 자: ' + results[0].name | ||
51 | }); | 123 | }); |
124 | + } | ||
125 | + | ||
126 | + replyMessage(replyToken, messages); | ||
127 | +} | ||
128 | + | ||
129 | +function replyMessage(replyToken, messages) { | ||
130 | + axios.post('https://api.line.me/v2/bot/message/reply', { | ||
131 | + replyToken: replyToken, | ||
132 | + messages: messages | ||
133 | + }, { | ||
134 | + headers: {'Authorization': channelToken} | ||
52 | }); | 135 | }); |
53 | } | 136 | } |
54 | 137 | ... | ... |
-
Please register or login to post a comment