Toggle navigation
Toggle navigation
This project
Loading...
Sign in
마수현
/
tft-chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
마수현
2020-12-07 14:01:21 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
Ma Suhyeon
2020-12-07 14:01:21 +0900
Commit
3b5cbcf36b0a24a6a2a3b82f9aeaf00eab2f052d
3b5cbcf3
1 parent
f98ac277
Implement recommend meta
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
3 deletions
app.js
app.js
View file @
3b5cbcf
...
...
@@ -28,10 +28,34 @@ function onMessage(message, replyToken) {
if
(
message
.
type
!=
'text'
)
return
;
if
(
message
.
text
.
indexOf
(
'아이템'
)
>=
0
)
if
(
message
.
text
.
indexOf
(
'아이템'
)
>=
0
)
{
recommendItem
(
message
.
text
.
split
(
' '
)[
0
],
replyToken
);
return
;
}
let
keywords
=
[
'추천덱'
,
'추천메타'
,
'덱추천'
,
'메타추천'
,
'메타덱'
,
'추천시너지'
,
'메타시너지'
,
'시너지추천'
];
let
isMeta
=
false
;
let
textOnly
=
message
.
text
.
replace
(
' '
,
''
);
for
(
let
k
of
keywords
)
{
if
(
textOnly
.
indexOf
(
k
)
>=
0
)
isMeta
=
true
;
}
if
(
isMeta
)
{
recommendMeta
(
replyToken
);
return
;
}
replyMessage
(
replyToken
,
[{
type
:
'text'
,
text
:
'수행할 수 없는 명령입니다.'
}]);
}
function
recommendItem
(
charAlias
,
replyToken
)
{
...
...
@@ -43,13 +67,72 @@ function recommendItem(charAlias, replyToken) {
else
reply
=
`
${
results
[
0
].
alias
}
의 추천 아이템은
${
results
.
map
(
e
=>
e
.
name
).
join
(
', '
)}
입니다.`
;
replyMessage
(
replyToken
,
[{
type
:
'text'
,
text
:
reply
}]);
});
}
async
function
recommendMeta
(
replyToken
)
{
let
sql
=
'SELECT * FROM decks ORDER BY `count` DESC LIMIT 0,3'
;
let
[
results
]
=
await
pool
.
query
(
sql
);
let
messages
=
[];
for
(
let
row
of
results
)
{
let
chars
=
[];
sql
=
'SELECT `alias` FROM character_aliases WHERE character_id=? AND is_name=1'
;
for
(
let
i
=
1
;
i
<=
8
;
i
++
)
{
[
results
]
=
await
pool
.
query
(
sql
,
[
row
[
`character_
${
i
}
`
]]);
chars
.
push
(
results
[
0
].
alias
);
}
let
traitCnt
=
new
Map
();
traitCnt
.
set
(
row
.
chosen
,
1
);
let
checked
=
new
Set
();
sql
=
'SELECT trait FROM character_traits WHERE character_id=?'
;
for
(
let
i
=
0
;
i
<=
8
;
i
++
)
{
if
(
checked
.
has
(
row
[
`character_
${
i
}
`
]))
continue
;
[
results
]
=
await
pool
.
query
(
sql
,
[
row
[
`character_
${
i
}
`
]]);
for
(
let
t
of
results
)
{
if
(
traitCnt
.
has
(
t
.
trait
))
traitCnt
.
set
(
t
.
trait
,
traitCnt
.
get
(
t
.
trait
)
+
1
);
else
traitCnt
.
set
(
t
.
trait
,
1
);
}
checked
.
add
(
row
[
`character_
${
i
}
`
]);
}
let
traits
=
[];
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'
;
for
(
let
[
key
,
value
]
of
traitCnt
.
entries
())
{
[
results
]
=
await
pool
.
query
(
sql
,
[
key
,
value
]);
if
(
results
.
length
==
0
)
continue
;
traits
.
push
(
`
${
results
[
0
].
count
}${
results
[
0
].
name
}
`
);
};
[
results
]
=
await
pool
.
query
(
'SELECT `name` FROM traits WHERE `id`=?'
,
[
row
.
chosen
]);
messages
.
push
({
type
:
'text'
,
text
:
traits
.
join
(
', '
)
+
'\n'
+
chars
.
join
(
', '
)
+
'\n'
+
'선택받은 자: '
+
results
[
0
].
name
});
}
replyMessage
(
replyToken
,
messages
);
}
function
replyMessage
(
replyToken
,
messages
)
{
axios
.
post
(
'https://api.line.me/v2/bot/message/reply'
,
{
replyToken
:
replyToken
,
messages
:
[{
type
:
'text'
,
text
:
reply
}]
messages
:
messages
},
{
headers
:
{
'Authorization'
:
channelToken
}
});
});
}
app
.
listen
(
3000
,
()
=>
console
.
log
(
'TFT Chatbot started'
));
\ No newline at end of file
...
...
Please
register
or
login
to post a comment