Toggle navigation
Toggle navigation
This project
Loading...
Sign in
최재은
/
밀당강의봇
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
김예미
2019-06-05 16:41:03 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
d83890df890b5fcfae0f5288cc9dab6cfdae198d
d83890df
1 parent
76e68c21
Final Commit!
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
48 deletions
controller.js
template.js
controller.js
View file @
d83890d
...
...
@@ -9,16 +9,17 @@ exports.handleMessage=function(sender_psid, received_message) {
template
.
greetingTemplate
(
function
(
result
,
res
){
if
(
result
==
true
){
response
=
res
;
callSendAPI
(
sender_psid
,
response
)
}
});
callSendAPI
(
sender_psid
,
response
);
}
else
{
template
.
choiceLectProfTemplate
(
text
,
function
(
result
,
res
){
if
(
result
==
true
){
response
=
res
;
console
.
log
(
"text2:"
,
response
)
callSendAPI
(
sender_psid
,
response
);
}
});
callSendAPI
(
sender_psid
,
response
);
}
}
...
...
@@ -50,9 +51,9 @@ exports.handlePostback =function(sender_psid, received_postback) {
if
(
result
==
true
){
console
.
log
(
res
);
response
=
res
;
callSendAPI
(
sender_psid
,
response
);
}
});
callSendAPI
(
sender_psid
,
response
);
}
}
...
...
@@ -66,6 +67,7 @@ const handlePostback_choiceByProf = function(sender_psid, received){
if
(
result
==
true
){
console
.
log
(
res
);
response
=
res
;
callSendAPI
(
sender_psid
,
response
);
}
});
}
else
if
(
stat
===
'stat_2'
){
...
...
@@ -73,6 +75,7 @@ const handlePostback_choiceByProf = function(sender_psid, received){
if
(
result
==
true
){
console
.
log
(
res
);
response
=
res
;
callSendAPI
(
sender_psid
,
response
);
}
});
}
else
if
(
stat
===
'stat_3'
){
...
...
@@ -80,10 +83,10 @@ const handlePostback_choiceByProf = function(sender_psid, received){
if
(
result
==
true
){
console
.
log
(
res
);
response
=
res
;
callSendAPI
(
sender_psid
,
response
);
}
});
}
callSendAPI
(
sender_psid
,
response
);
}
const
handlePostback_choiceByLect
=
function
(
sender_psid
,
received
){
...
...
@@ -96,6 +99,7 @@ const handlePostback_choiceByLect = function(sender_psid, received){
if
(
result
==
true
){
console
.
log
(
res
);
response
=
res
;
callSendAPI
(
sender_psid
,
response
);
}
});
}
else
if
(
stat
===
'stat_2'
){
...
...
@@ -103,6 +107,7 @@ const handlePostback_choiceByLect = function(sender_psid, received){
if
(
result
==
true
){
console
.
log
(
res
);
response
=
res
;
callSendAPI
(
sender_psid
,
response
);
}
});
}
else
if
(
stat
===
'stat_3'
){
...
...
@@ -110,10 +115,10 @@ const handlePostback_choiceByLect = function(sender_psid, received){
if
(
result
==
true
){
console
.
log
(
res
);
response
=
res
;
callSendAPI
(
sender_psid
,
response
);
}
});
}
callSendAPI
(
sender_psid
,
response
);
}
const
handlePostback_help
=
function
(
sender_psid
,
received
)
{
...
...
@@ -126,10 +131,10 @@ const handlePostback_help = function(sender_psid, received) {
if
(
result
==
true
){
console
.
log
(
res
);
response
=
res
;
callSendAPI
(
sender_psid
,
response
);
}
});
}
callSendAPI
(
sender_psid
,
response
);
}
// Sends response messages via the Send API
...
...
@@ -146,7 +151,8 @@ const callSendAPI = (sender_psid, response, cb=null) => {
}
},
(
err
,
res
,
body
)
=>
{
if
(
!
err
)
{
console
.
log
(
'message sent!'
)
console
.
log
(
'message sent!'
);
console
.
log
(
'res: '
,
response
);
}
else
{
console
.
error
(
"Unable to send message:"
+
err
);
}
...
...
template.js
View file @
d83890d
...
...
@@ -76,35 +76,45 @@ exports.getLectNameTemplate = function(cb){
}
exports
.
choiceLectProfTemplate
=
function
(
message
,
cb
)
{
var
sqlquery
=
'SELECT * FROM reviews WHERE lecturename
= ? OR proname =
?'
;
var
par
=
[
'%'
+
message
+
'%'
,
'%'
+
message
+
'%'
];
var
sqlquery
=
'SELECT * FROM reviews WHERE lecturename
Like ? OR proname Like
?'
;
var
par
=
[
"%"
+
message
+
"%"
,
"%"
+
message
+
"%"
];
db
.
query
(
sqlquery
,
par
,
function
(
error
,
results
){
console
.
log
(
"!~~!~!~!~!~!~!~!~!"
);
console
.
log
(
"!~~!~!~!~!~!~!~~!~!"
);
console
.
log
(
results
);
console
.
log
(
"메세지: "
,
message
);
if
(
error
){
res
.
render
(
'error'
);
}
if
(
results
.
length
==
0
){
cb
(
true
,
{
text
:
"검색 결과가 없습니다. 검색어를 다시 입력해주세요."
});
}
else
if
(
results
.
length
<=
2
){
LectProfList
(
results
,
0
,
results
.
length
,
false
,
'0'
,
message
,
function
(
result
,
text
){
if
(
result
==
true
){
cb
(
true
,
text
);
}
});
}
else
if
(
results
.
length
>
2
){
LectProfList
(
results
,
0
,
2
,
true
,
'1'
,
message
,
function
(
result
,
text
){
if
(
result
==
true
){
cb
(
true
,
text
);
}
});
}
else
{
if
(
results
.
length
==
0
){
console
.
log
(
"0개로 들어 왔어용"
);
cb
(
true
,
{
text
:
"검색 결과가 없습니다. 검색어를 다시 입력해주세요."
});
}
else
if
(
results
.
length
<=
2
){
console
.
log
(
"2개로 들어 왔어용"
);
LectProfList
(
results
,
0
,
results
.
length
,
false
,
'0'
,
message
,
function
(
result
,
text
){
if
(
result
==
true
){
console
.
log
(
text
);
cb
(
true
,
text
);
}
});
}
else
if
(
results
.
length
>
2
){
console
.
log
(
"3개로 들어 왔어용"
);
LectProfList
(
results
,
0
,
2
,
true
,
'1'
,
message
,
function
(
result
,
text
){
if
(
result
==
true
){
console
.
log
(
"text1: "
,
text
);
cb
(
true
,
text
);
}
});
}
}
});
}
const
LectProfList
=
function
(
results
,
start
,
length
,
ismore
,
morecount
,
message
,
cb
){
function
LectProfList
(
results
,
start
,
length
,
ismore
,
morecount
,
message
,
cb
){
console
.
log
(
"LectProfList 함수에 들어옴"
);
if
(
length
==
1
){
var
title
=
results
[
start
].
lecturename
+
results
[
start
].
proname
;
console
.
log
(
"첫 버튼 하나짜리 처리하는데 들어옴"
);
var
title
=
results
[
start
].
lecturename
+
"\n["
+
results
[
start
].
proname
+
"]"
;
var
payload
=
'CHOICE_BY_PROFstat_3'
+
results
[
start
].
idreviews
;
var
text
=
{
"attachment"
:{
...
...
@@ -124,7 +134,8 @@ const LectProfList = function(results,start,length,ismore,morecount,message,cb){
};
cb
(
true
,
text
);
}
else
if
((
length
==
2
)
&&
(
!
ismore
)){
var
title
=
[
results
[
start
].
lecturename
+
results
[
start
].
proname
,
results
[
start
+
1
].
lecturename
+
results
[
start
+
1
].
proname
];
console
.
log
(
"2개짜리 처리하는데 들어옴"
);
var
title
=
[
results
[
start
].
lecturename
+
"\n["
+
results
[
start
].
proname
+
"]"
,
results
[
start
+
1
].
lecturename
+
"\n["
+
results
[
start
+
1
].
proname
+
"]"
];
var
payload
=
[
'CHOICE_BY_PROFstat_3'
+
results
[
start
].
idreviews
,
'CHOICE_BY_PROFstat_3'
+
results
[
start
+
1
].
idreviews
];
var
text
=
{
"attachment"
:{
...
...
@@ -149,7 +160,8 @@ const LectProfList = function(results,start,length,ismore,morecount,message,cb){
};
cb
(
true
,
text
);
}
else
if
((
length
==
2
)
&&
(
ismore
)){
var
title
=
[
results
[
start
].
lecturename
+
results
[
start
].
proname
,
results
[
start
+
1
].
lecturename
+
results
[
start
+
1
].
proname
];
console
.
log
(
"버튼 2개, 더보기까지 처리하는데 들어옴"
);
var
title
=
[
results
[
start
].
lecturename
+
"\n["
+
results
[
start
].
proname
+
"]"
,
results
[
start
+
1
].
lecturename
+
"\n["
+
results
[
start
+
1
].
proname
+
"]"
];
var
payload
=
[
'CHOICE_BY_PROFstat_3'
+
results
[
start
].
idreviews
,
'CHOICE_BY_PROFstat_3'
+
results
[
start
+
1
].
idreviews
,
'CHOICE_BY_PROFstat_2'
+
message
+
'/'
+
morecount
];
var
text
=
{
"attachment"
:{
...
...
@@ -184,10 +196,12 @@ const LectProfList = function(results,start,length,ismore,morecount,message,cb){
//stat_2
exports
.
moreProfTemplate
=
function
(
payload
,
cb
){
var
ms
=
payload
.
substr
(
20
).
split
(
'/'
);
var
more
=
1
*
(
ms
[
0
]);
//to Number
var
message
=
ms
[
1
];
var
message
=
ms
[
0
];
//to Number
console
.
log
(
"ms1: "
,
ms
[
1
])
var
more
=
parseInt
(
ms
[
1
]);
console
.
log
(
"more: "
,
more
)
var
sqlquery
=
'SELECT * FROM reviews WHERE lecturename
= ? OR proname =
?'
;
var
sqlquery
=
'SELECT * FROM reviews WHERE lecturename
Like ? OR proname Like
?'
;
var
par
=
[
'%'
+
message
+
'%'
,
'%'
+
message
+
'%'
];
db
.
query
(
sqlquery
,
par
,
function
(
error
,
results
){
if
(
error
){
...
...
@@ -195,13 +209,13 @@ exports.moreProfTemplate = function(payload,cb){
res
.
render
(
'error'
);
}
if
((
results
.
length
-
2
*
(
more
+
1
))
<=
0
){
LectProfList
(
results
,
2
*
more
,
results
.
length
-
2
*
n
,
false
,
'0'
,
message
,
function
(
result
,
text
){
LectProfList
(
results
,
2
*
more
,
results
.
length
-
2
*
more
,
false
,
'0'
,
message
,
function
(
result
,
text
){
if
(
result
==
true
){
cb
(
true
,
text
);
}
});
}
else
{
LectProfList
(
results
,
2
*
more
,
2
,
true
,
""
+
(
more
+
1
),
message
,
function
(
result
,
text
){
LectProfList
(
results
,
2
*
more
,
2
,
true
,
(
more
+
1
).
toString
(
),
message
,
function
(
result
,
text
){
if
(
result
==
true
){
cb
(
true
,
text
);
}
...
...
@@ -215,8 +229,8 @@ exports.moreLectTemplate= function(payload,cb){
var
more
=
1
*
(
ms
[
0
]);
var
message
=
ms
[
1
];
var
sqlquery
=
'SELECT * FROM reviews WHERE lecturename
= ? OR proname =
?'
;
var
par
=
[
message
,
message
];
var
sqlquery
=
'SELECT * FROM reviews WHERE lecturename
Like ? OR proname Like
?'
;
var
par
=
[
'%'
+
message
+
'%'
,
'%'
+
message
+
'%'
];
db
.
query
(
sqlquery
,
par
,
function
(
error
,
results
){
if
(
error
){
console
.
log
(
error
);
...
...
@@ -251,8 +265,8 @@ exports.rateTemplate= function(payload,cb){
}
var
proname
=
results
[
0
].
proname
;
var
lecname
=
results
[
0
].
lecname
;
var
reviews
=
results
[
0
].
review
.
split
(
'
,
'
);
var
lecname
=
results
[
0
].
lec
ture
name
;
var
reviews
=
results
[
0
].
review
.
split
(
'
.
'
);
var
review
=
reviews
[
0
];
var
rate
=
results
[
0
].
avg_rate
;
var
botsay
=
[];
...
...
@@ -271,18 +285,18 @@ exports.rateTemplate= function(payload,cb){
botsay
=
[
"무조건 들어요!"
,
"갓갓 교수님의 갓갓 수업"
,
"안 들으면 후회해요ㅠㅠ"
,
"수강신청 1순위!"
];
}
var
payload
=
'MoreRate'
+
id
;
var
payload
1
=
'MoreRate'
+
id
;
var
text
=
{
"attachment"
:{
"type"
:
"template"
,
"payload"
:{
"template_type"
:
"button"
,
"text"
:
proname
+
" 교수님의 강의 ["
+
lecname
+
"]의 강의평입니다.\n **평균 평점: "
+
rate
+
"\n **봇의 한줄평: "
+
botsay
[
randNum
]
+
"\n **학우의 한줄평: "
+
re
iv
ew
,
"text"
:
proname
+
" 교수님의 강의 ["
+
lecname
+
"]의 강의평입니다.\n **평균 평점: "
+
rate
+
"\n **봇의 한줄평: "
+
botsay
[
randNum
]
+
"\n **학우의 한줄평: "
+
re
vi
ew
,
"buttons"
:[
{
"type"
:
"postback"
,
"title"
:
"자세한 강의평 보기"
,
"payload"
:
payload
"payload"
:
payload
1
}
]
}
...
...
@@ -294,7 +308,6 @@ exports.rateTemplate= function(payload,cb){
exports
.
moreRateTemplate
=
function
(
payload
,
cb
){
var
id
=
payload
.
substr
(
8
);
var
total_review
=
""
;
var
sqlquery
=
'SELECT * FROM reviews WHERE idreviews = ?'
;
var
par
=
[
id
];
...
...
@@ -304,12 +317,9 @@ exports.moreRateTemplate = function(payload,cb){
res
.
render
(
'error'
);
}
var
reviews
=
results
[
0
].
review
.
split
(
','
);
for
(
var
review
in
reviews
){
total_review
+=
review
+
"\n"
;
}
cb
(
true
,{
text
:
total_review
});
var
reviews
=
results
[
0
].
review
;
console
.
log
(
"전체리뷰:"
,
reviews
)
cb
(
true
,{
text
:
reviews
});
});
}
...
...
Please
register
or
login
to post a comment