Toggle navigation
Toggle navigation
This project
Loading...
Sign in
신지원
/
LineMusicChatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
엄성진
2021-06-09 03:36:27 +0900
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
1d796018d1a99147a26710f7e0a95e6608ca5036
1d796018
2 parents
d8b8bfa2
d3e25725
Merge remote-tracking branch 'origin/dev'
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
111 deletions
.gitignore
all_ids.js
check.js
index.js
video_sad.js
.gitignore
View file @
1d79601
all_ids.js
View file @
1d79601
// 아래 주석을 참고해 플레이리스트 or 노래의 배열을 직접 만드시면 됩니다.
// 배열을 만들 때, 활용하실 id값이 플레이리스트의 id인지, 특정 노래의 id인지 구별해서 배열을 만드셔야 합니다.
// '플레이리스트'의 id라면 인덱스 500 이하로,
// '특정 노래'의 id라면 인덱스 500 이상으로 넣어주세요!
// 아래 예시를 보고 이해 안되시면, 편하게 카톡으로 말씀해주세요
// index < 500 = 플레이리스트
// index > 500 = 개별 곡
// index 100번대 = 장르 플레이리스트
// index 200번대 = 무드 플레이리스트
// index 300번대 = 가수 플레이리스트
// index 500번대 = 특정 플레이리스트의 노래 10곡
// index 101 = 장르 - 힙합
// index 102 = 장르 - 피아노
...
...
@@ -25,8 +14,6 @@
// index 303 = 가수 - 레드벨벳
// index 304 = 가수 - 트와이스
// index 501 = 슬픈노래 10곡
exports
.
all_ids
=
[];
exports
.
all_ids
[
101
]
=
'PLfVO1GXBPp3s03voaFAWN7AkzEnpsGF1U'
...
...
@@ -40,6 +27,3 @@ exports.all_ids[301] = 'PLfVO1GXBPp3tgrwk3GDJi3v-E_Hnq3lDO'
exports
.
all_ids
[
302
]
=
'PLfVO1GXBPp3ubihJVPi6HSltRIuvSqSI1'
exports
.
all_ids
[
303
]
=
'PLfVO1GXBPp3u0ckIfYZkADGlSQ6LQoAIQ'
exports
.
all_ids
[
304
]
=
'PLfVO1GXBPp3vo3sivJPfFzREBECRFepVK'
\ No newline at end of file
exports
.
all_ids
[
501
]
=
[
'p5iu1V30myk'
,
'i-SBnhaZSSU'
,
'Etfgb6A7hSI'
,
'IN2mml9xs_s'
,
'tp1uoFAfgHE'
,
'Qx22TnVVIfU'
,
'3y1QIqR115A'
,
'VXBI1wt8XII'
,
'aWMBn2--E0Q'
,
'HyTbgBlnLCo'
];
\ No newline at end of file
...
...
check.js
View file @
1d79601
This diff is collapsed. Click to expand it.
index.js
View file @
1d79601
var
express
=
require
(
'express'
);
var
Info
=
require
(
'./Info'
);
const
request
=
require
(
'request'
);
const
fs
=
require
(
'fs'
);
const
path
=
require
(
'path'
);
const
HTTPS
=
require
(
'https'
);
const
domain
=
"2020105631.oss2021.tk"
const
sslport
=
23023
;
const
bodyParser
=
require
(
'body-parser'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
;
// var Info = require('./Info');
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
var
app
=
express
();
app
.
use
(
bodyParser
.
json
());
<<<<<<<
HEAD
var
sad
=
require
(
'./video_sad'
);
=======
var
songs
=
require
(
'./check'
);
>>>>>>>
feature
/
YouTube_API
app
.
post
(
'/hook'
,
function
(
req
,
res
)
{
var
eventObj
=
req
.
body
.
events
[
0
];
...
...
@@ -26,10 +17,97 @@ app.post('/hook', function (req, res) {
// request log
console
.
log
(
'======================'
,
new
Date
(),
'======================'
);
send
(
eventObj
.
replyToken
,
message
.
text
);
if
(
eventObj
.
type
==
"message"
)
// 일반 메시지일때
{
react
(
eventObj
.
replyToken
,
message
.
text
,
eventObj
.
source
.
userId
);
}
else
switch
(
eventObj
.
postback
.
data
)
{
case
"썸네일"
:
//설정에서 썸네일 설정버튼을 눌렀을때
songs
.
thumbnail_settings
(
eventObj
.
replyToken
);
break
;
case
"enablethumbnail"
:
//설정 -> 썸네일 설정 -> 활성화
songs
.
enablethumbnail
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"unablethumbnail"
:
//설정 -> 썸네일 설정 -> 비활성화
songs
.
unablethumbnail
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"개수"
:
//설정에서 전송 개수 설정버튼을 눌렀을때
songs
.
amount_settings
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"amount1"
:
//설정 -> 전송 개수 -> 1
songs
.
amount1
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"amount2"
:
//설정 -> 전송 개수 -> 2
songs
.
amount2
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"amount3"
:
//설정 -> 전송 개수 -> 3
songs
.
amount3
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"amount4"
:
//설정 -> 전송 개수 -> 4
songs
.
amount4
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"주소"
:
//설정에서 유튜브 주소 설정버튼을 눌렀을때
songs
.
address_settings
(
eventObj
.
replyToken
);
break
;
case
"enableaddress"
:
//설정 -> 주소 설정 -> 활성화
songs
.
enableaddress
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"unableaddress"
:
//설정 -> 주소 설정 -> 비활성화
songs
.
unableaddress
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"genre"
:
// 플레이리스트 -> 장르
songs
.
genre
(
eventObj
.
replyToken
);
break
;
case
"hiphop"
:
// 플레이리스트 -> 장르 -> 힙합
songs
.
hiphop
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"piano"
:
// 플레이리스트 -> 장르 -> 피아노
songs
.
piano
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"pop"
:
// 플레이리스트 -> 장르 -> 팝
songs
.
pop
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"mood"
:
// 플레이리스트 -> 무드
songs
.
mood
(
eventObj
.
replyToken
);
break
;
case
"exciting"
:
// 플레이리스트 -> 무드 -> 신남
songs
.
exciting
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"sad"
:
// 플레이리스트 -> 무드 -> 슬픔
songs
.
sad
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"singer"
:
// 플레이리스트 -> 가수
songs
.
singer
(
eventObj
.
replyToken
);
break
;
case
"blackpink"
:
// 플레이리스트 -> 가수 -> 블랙핑크
songs
.
blackpink
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"iu"
:
// 플레이리스트 -> 가수 -> 아이유
songs
.
iu
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"redvelvet"
:
// 플레이리스트 -> 가수 -> 레드벨벳
songs
.
redvelvet
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
case
"twice"
:
// 플레이리스트 -> 가수 -> 트와이스
songs
.
twice
(
eventObj
.
replyToken
,
eventObj
.
source
.
userId
);
break
;
}
res
.
sendStatus
(
200
);
});
function
send
(
replyToken
,
message
)
{
}
);
function
react
(
replyToken
,
message
,
userId
)
{
request
.
post
(
{
...
...
@@ -37,16 +115,15 @@ function send(replyToken, message) {
},
function
()
{
songs
.
check
(
message
,
replyToken
);
songs
.
check
(
message
,
replyToken
,
userId
);
}
);
}
try
{
const
option
=
{
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
domain
+
'/fullchain.pem'
),
key
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
domain
+
'/privkey.pem'
),
'utf8'
).
toString
(),
cert
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
domain
+
'/cert.pem'
),
'utf8'
).
toString
(),
ca
:
fs
.
readFileSync
(
'/etc/letsencrypt/live/'
+
Info
.
domain
+
'/fullchain.pem'
),
key
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
Info
.
domain
+
'/privkey.pem'
),
'utf8'
).
toString
(),
cert
:
fs
.
readFileSync
(
path
.
resolve
(
process
.
cwd
(),
'/etc/letsencrypt/live/'
+
Info
.
domain
+
'/cert.pem'
),
'utf8'
).
toString
(),
};
HTTPS
.
createServer
(
option
,
app
).
listen
(
sslport
,
()
=>
{
...
...
video_sad.js
deleted
100644 → 0
View file @
d8b8bfa
var
Info
=
require
(
'./Info'
);
exports
.
check
=
function
(
message
,
replyToken
){
const
rand_0to9
=
Math
.
floor
(
Math
.
random
()
*
10
);
// 0~9까지 난수생성
var
ids
=
[
'p5iu1V30myk'
,
'i-SBnhaZSSU'
,
'Etfgb6A7hSI'
,
'IN2mml9xs_s'
,
// 모든 동영상 id를 관리하는 배열
'tp1uoFAfgHE'
,
'Qx22TnVVIfU'
,
'3y1QIqR115A'
,
'VXBI1wt8XII'
,
'aWMBn2--E0Q'
,
'HyTbgBlnLCo'
];
const
request
=
require
(
'request'
);
const
fs
=
require
(
'fs'
);
const
TARGET_URL
=
'https://api.line.me/v2/bot/message/reply'
var
{
google
}
=
require
(
'googleapis'
);
var
service
=
google
.
youtube
(
'v3'
);
service
.
videos
.
list
(
{
key
:
'AIzaSyBInggOtXxPFYIRee0Xs3vb5iZ9YE9_518'
,
part
:
'snippet'
,
id
:
ids
[
rand_0to9
],
// 동영상 Id random input
fields
:
'items(snippet(title))'
},
function
(
err
,
response
)
{
if
(
err
)
{
console
.
log
(
'The API returned an error: '
,
err
);
return
;
}
var
video
=
response
.
data
.
items
;
if
(
video
.
length
==
0
)
{
console
.
log
(
'검색된 동영상이 없습니다.'
);
}
else
{
sendMessage
=
JSON
.
stringify
(
response
.
data
.
items
[
0
].
snippet
.
title
);
console
.
log
(
sendMessage
);
request
.
post
(
{
url
:
TARGET_URL
,
headers
:
{
'Authorization'
:
`Bearer
${
Info
.
TOKEN
}
`
},
json
:
{
"replyToken"
:
replyToken
,
"messages"
:
[
{
"type"
:
"image"
,
"originalContentUrl"
:
"https://img.youtube.com/vi/"
+
ids
[
rand_0to9
]
+
"/hqdefault.jpg"
,
"previewImageUrl"
:
"https://img.youtube.com/vi/"
+
ids
[
rand_0to9
]
+
"/hqdefault.jpg"
},
{
"type"
:
"text"
,
"text"
:
sendMessage
}
]
}
}
);
}
}
)
}
Please
register
or
login
to post a comment