엄성진

Completed Development About Settings, Modify Help

1 -// 아래 주석을 참고해 플레이리스트 or 노래의 배열을 직접 만드시면 됩니다.
2 -// 배열을 만들 때, 활용하실 id값이 플레이리스트의 id인지, 특정 노래의 id인지 구별해서 배열을 만드셔야 합니다.
3 -// '플레이리스트'의 id라면 인덱스 500 이하로,
4 -// '특정 노래'의 id라면 인덱스 500 이상으로 넣어주세요!
5 -// 아래 예시를 보고 이해 안되시면, 편하게 카톡으로 말씀해주세요
6 -
7 -
8 -// index < 500 = 플레이리스트
9 -// index > 500 = 개별 곡
10 -
11 // index 100번대 = 장르 플레이리스트 1 // index 100번대 = 장르 플레이리스트
12 // index 200번대 = 무드 플레이리스트 2 // index 200번대 = 무드 플레이리스트
13 // index 300번대 = 가수 플레이리스트 3 // index 300번대 = 가수 플레이리스트
14 -// index 500번대 = 특정 플레이리스트의 노래 10곡
15 4
16 // index 101 = 장르 - 힙합 5 // index 101 = 장르 - 힙합
17 // index 102 = 장르 - 피아노 6 // index 102 = 장르 - 피아노
...@@ -25,8 +14,6 @@ ...@@ -25,8 +14,6 @@
25 // index 303 = 가수 - 레드벨벳 14 // index 303 = 가수 - 레드벨벳
26 // index 304 = 가수 - 트와이스 15 // index 304 = 가수 - 트와이스
27 16
28 -// index 501 = 슬픈노래 10곡
29 -
30 exports.all_ids = []; 17 exports.all_ids = [];
31 18
32 exports.all_ids[101] = 'PLfVO1GXBPp3s03voaFAWN7AkzEnpsGF1U' 19 exports.all_ids[101] = 'PLfVO1GXBPp3s03voaFAWN7AkzEnpsGF1U'
...@@ -39,7 +26,4 @@ exports.all_ids[202] = 'PLfVO1GXBPp3vrR3ZcQFlCEC6oNdo_MQ_R' ...@@ -39,7 +26,4 @@ exports.all_ids[202] = 'PLfVO1GXBPp3vrR3ZcQFlCEC6oNdo_MQ_R'
39 exports.all_ids[301] = 'PLfVO1GXBPp3tgrwk3GDJi3v-E_Hnq3lDO' 26 exports.all_ids[301] = 'PLfVO1GXBPp3tgrwk3GDJi3v-E_Hnq3lDO'
40 exports.all_ids[302] = 'PLfVO1GXBPp3ubihJVPi6HSltRIuvSqSI1' 27 exports.all_ids[302] = 'PLfVO1GXBPp3ubihJVPi6HSltRIuvSqSI1'
41 exports.all_ids[303] = 'PLfVO1GXBPp3u0ckIfYZkADGlSQ6LQoAIQ' 28 exports.all_ids[303] = 'PLfVO1GXBPp3u0ckIfYZkADGlSQ6LQoAIQ'
42 -exports.all_ids[304] = 'PLfVO1GXBPp3vo3sivJPfFzREBECRFepVK'
43 -
44 -//exports.all_ids[501] = ['p5iu1V30myk', 'i-SBnhaZSSU', 'Etfgb6A7hSI', 'IN2mml9xs_s',
45 -// 'tp1uoFAfgHE', 'Qx22TnVVIfU', '3y1QIqR115A', 'VXBI1wt8XII', 'aWMBn2--E0Q', 'HyTbgBlnLCo'];
...\ No newline at end of file ...\ No newline at end of file
29 +exports.all_ids[304] = 'PLfVO1GXBPp3vo3sivJPfFzREBECRFepVK'
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -5,18 +5,15 @@ const fs = require('fs'); ...@@ -5,18 +5,15 @@ const fs = require('fs');
5 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' 5 const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
6 var { google } = require('googleapis'); 6 var { google } = require('googleapis');
7 var service = google.youtube('v3'); 7 var service = google.youtube('v3');
8 -// var app = express();
9 -// app.use(bodyParser.json());
10 8
11 //세팅,설정값 9 //세팅,설정값
12 var setting_userId = []; //유저아이디보관 10 var setting_userId = []; //유저아이디보관
13 var setting_Thumbnail = []; // 1:썸네일 출력(기본값) / 0:미출력 11 var setting_Thumbnail = []; // 1:썸네일 출력(기본값) / 0:미출력
14 -var setting_SendAmount = []; // 보낼 양 (1이상, 10이하의 정수) (기본값:1) 12 +var setting_SendAmount = []; // 보낼 양 (1이상, 4이하의 정수) (기본값:1)
15 var setting_SendAddress = []; // 1:유튜브 주소 출력(기본값) / 0:미출력 13 var setting_SendAddress = []; // 1:유튜브 주소 출력(기본값) / 0:미출력
16 14
17 function SEND(replyToken,title,url2,thumbnail,SendAmount,sendaddress) //검색해서 나온 내용 전송하는 함수 15 function SEND(replyToken,title,url2,thumbnail,SendAmount,sendaddress) //검색해서 나온 내용 전송하는 함수
18 { 16 {
19 - //sendMessage = JSON.stringify(response.data.items[0].snippet.title);
20 17
21 sendMessage = ""; 18 sendMessage = "";
22 var temp_title = [], temp_url = [], temp_url2 = [], temp_thumpnail = []; 19 var temp_title = [], temp_url = [], temp_url2 = [], temp_thumpnail = [];
...@@ -608,17 +605,164 @@ exports.unablethumbnail = function(replyToken,userId) ...@@ -608,17 +605,164 @@ exports.unablethumbnail = function(replyToken,userId)
608 exports.amount_settings = function (replyToken, userId) 605 exports.amount_settings = function (replyToken, userId)
609 { 606 {
610 console.log('출력량 설정'); 607 console.log('출력량 설정');
611 - // 여기서 노래 몇개를 출력할지 물어보고나서, 웹훅의 응답을 받아 그 응답에 따라서 608 + request.post(
612 - // setting_SendAmount[setting_userId.indexOf(userId)] 의 값를 수정합니다. 609 + {
613 - // 이거는 단순하게 숫자를 입력받으면 될 것 같습니다. 다만 1,2,3,4,5,6,7,8,9,10 의 응답만 받도록 해주셔야 합니다. (예외처리 필수) 610 + url: TARGET_URL,
611 + headers:
612 + {
613 + 'Authorization': `Bearer ${Info.TOKEN}`
614 + },
615 + json:
616 + {
617 + "replyToken": replyToken,
618 + "messages":
619 + [
620 + {
621 + "type": "template",
622 + "altText": "설정메뉴입니다.",
623 + "template": {
624 + "type": "buttons",
625 + "title": "추천 음악 개수 조정",
626 + "text": "원하는 추천 개수를 골라주세요.",
627 + "actions": [
628 + {
629 + "type": "postback",
630 + "label": "1개",
631 + "data": "amount1"
632 + },
633 + {
634 + "type": "postback",
635 + "label": "2개",
636 + "data": "amount2"
637 + },
638 + {
639 + "type": "postback",
640 + "label": "3개",
641 + "data": "amount3"
642 + },
643 + {
644 + "type": "postback",
645 + "label": "4개",
646 + "data": "amount4"
647 + }
648 + ]
649 + }
650 + }
651 + ]
652 + }
653 + }
654 +
655 + );
656 +}
657 +
658 +exports.amount1 = function(replyToken,userId)
659 +{
660 + console.log('한 번에 1개씩');
661 + setting_SendAmount[setting_userId.indexOf(userId)]=1;
662 + request.post(
663 + {
664 + url: TARGET_URL,
665 + headers:
666 + {
667 + 'Authorization': `Bearer ${Info.TOKEN}`
668 + },
669 + json:
670 + {
671 + "replyToken": replyToken,
672 + "messages":
673 + [
674 + {
675 + "type": "text",
676 + "text": "이제 한 번에 한 개씩 추천합니다!"
677 + }
678 + ]
679 + }
680 + }
681 + );
682 +}
683 +
684 +exports.amount2 = function(replyToken,userId)
685 +{
686 + console.log('한 번에 2개씩');
687 + setting_SendAmount[setting_userId.indexOf(userId)]=2;
688 + request.post(
689 + {
690 + url: TARGET_URL,
691 + headers:
692 + {
693 + 'Authorization': `Bearer ${Info.TOKEN}`
694 + },
695 + json:
696 + {
697 + "replyToken": replyToken,
698 + "messages":
699 + [
700 + {
701 + "type": "text",
702 + "text": "이제 한 번에 두 개씩 추천합니다!"
703 + }
704 + ]
705 + }
706 + }
707 + );
614 } 708 }
615 709
710 +exports.amount3 = function(replyToken,userId)
711 +{
712 + console.log('한 번에 3개씩');
713 + setting_SendAmount[setting_userId.indexOf(userId)]=3;
714 + request.post(
715 + {
716 + url: TARGET_URL,
717 + headers:
718 + {
719 + 'Authorization': `Bearer ${Info.TOKEN}`
720 + },
721 + json:
722 + {
723 + "replyToken": replyToken,
724 + "messages":
725 + [
726 + {
727 + "type": "text",
728 + "text": "이제 한 번에 세 개씩 추천합니다!"
729 + }
730 + ]
731 + }
732 + }
733 + );
734 +}
616 735
736 +exports.amount4 = function(replyToken,userId)
737 +{
738 + console.log('한 번에 4개씩');
739 + setting_SendAmount[setting_userId.indexOf(userId)]=4;
740 + request.post(
741 + {
742 + url: TARGET_URL,
743 + headers:
744 + {
745 + 'Authorization': `Bearer ${Info.TOKEN}`
746 + },
747 + json:
748 + {
749 + "replyToken": replyToken,
750 + "messages":
751 + [
752 + {
753 + "type": "text",
754 + "text": "이제 한 번에 네 개씩 추천합니다!"
755 + }
756 + ]
757 + }
758 + }
759 + );
760 +}
617 761
618 762
619 763
620 764
621 -exports.address_settings = function (replyToken,) 765 +exports.address_settings = function (replyToken)
622 { 766 {
623 console.log('유튜브 주소 전송 설정'); 767 console.log('유튜브 주소 전송 설정');
624 request.post( 768 request.post(
...@@ -722,167 +866,53 @@ exports.check = function (message, replyToken, userId) { ...@@ -722,167 +866,53 @@ exports.check = function (message, replyToken, userId) {
722 console.log("알림: 새로운 사용자가 발견됨"); 866 console.log("알림: 새로운 사용자가 발견됨");
723 } 867 }
724 868
725 - //const rand_0to9 = Math.floor(Math.random() * 10); // 0~9까지 난수생성
726 var choice; 869 var choice;
727 var choose; 870 var choose;
728 871
729 switch (message) { 872 switch (message) {
730 -
731 - case "힙합 플레이리스트":
732 - choose = 101;
733 - choice = ids.all_ids[choose]
734 - break;
735 - case "피아노 플레이리스트":
736 - choose = 102;
737 - choice = ids.all_ids[choose]
738 - break;
739 - case "팝 플레이리스트":
740 - choose = 103;
741 - choice = ids.all_ids[choose]
742 - break;
743 - case "신나는 플레이리스트":
744 - choose = 201;
745 - choice = ids.all_ids[choose]
746 - break;
747 - case "슬픈 플레이리스트":
748 - choose = 202;
749 - choice = ids.all_ids[choose]
750 - break;
751 - case "블랙핑크 플레이리스트":
752 - choose = 301;
753 - choice = ids.all_ids[choose]
754 - break;
755 - case "아이유 플레이리스트":
756 - choose = 302;
757 - choice = ids.all_ids[choose]
758 - break;
759 - case "레드벨벳 플레이리스트":
760 - choose = 303;
761 - choice = ids.all_ids[choose]
762 - break;
763 - case "트와이스 플레이리스트":
764 - choose = 304;
765 - choice = ids.all_ids[choose]
766 - break;
767 case "플레이리스트": 873 case "플레이리스트":
768 - choose = 100; 874 + PLAYLIST(replyToken);
769 - choice = 0;
770 break; 875 break;
771 case "도움말": 876 case "도움말":
772 - choose = 001; 877 + sendMessage = "- 기본적으로 찾고 싶은 음악을 입력하여 보내면 적절한 음악 영상을 찾아 추천해드립니다."
773 - choice = 0; 878 + +"\n"+"예시) 소녀시대 노래"
879 + +"\n"+"- '플레이리스트'를 입력하면 분류에 따라 엄선한 음악을 추천드립니다!"
880 + +"\n"+"- '설정'을 입력하면 썸네일 출력 여부, 추천 음악 개수(1~4), 유튜브 주소 전송 여부를 설정하실 수 있습니다."
881 + +"\n"+"- 이 도움말을 다시 보고 싶으시다면 '도움말'을 입력하시면 됩니다! 음악과 함께 좋은 하루 보내세요.";
882 + HELP(replyToken,sendMessage);
774 break; 883 break;
775 case "설정": 884 case "설정":
776 - choose = 002; 885 + SETTINGS(replyToken);
777 - choice = 0;
778 break; 886 break;
779 - // 아래는 case 추가를 위한 템플릿 887 + default: //일반 검색
780 - // case "": 888 + var optionParams={
781 - // choose = ; 889 + q:message,
782 - // choice = ids.all_ids[choose] 890 + part:"snippet",
783 - 891 + key:Info.YoutubeKey,
784 - default: 892 + maxResults:10
785 - choose = 500; 893 + };
786 - choice = 0; 894 + optionParams.q=encodeURI(optionParams.q);
787 - } 895 + var url="https://www.googleapis.com/youtube/v3/search?";
788 - 896 + for(var option in optionParams){
789 - if (choose == 500) { //일반 검색 897 + url+=option+"="+optionParams[option]+"&";
790 -
791 - var optionParams={
792 - q:message,
793 - part:"snippet",
794 - key:Info.YoutubeKey,
795 - maxResults:10
796 - };
797 - optionParams.q=encodeURI(optionParams.q);
798 - var url="https://www.googleapis.com/youtube/v3/search?";
799 - for(var option in optionParams){
800 - url+=option+"="+optionParams[option]+"&";
801 - }
802 -
803 - //url의마지막에 붙어있는 & 정리
804 - url=url.substr(0, url.length-1);
805 -
806 - request(url, function(err, res, body){
807 - var title=[]
808 - var url2=[]
809 - var data=JSON.parse(body).items;
810 - for(var content in data)
811 - {
812 - title.push(data[content].snippet.title);
813 - url2.push(data[content].id.videoId);
814 } 898 }
815 - if (title.length==0) 899 +
816 - console.log('검색된 동영상이 없습니다.'); 900 + //url의마지막에 붙어있는 & 정리
817 - else 901 + url=url.substr(0, url.length-1);
818 - SEND(replyToken,title,url2,setting_Thumbnail[setting_userId.indexOf(userId)],setting_SendAmount[setting_userId.indexOf(userId)],setting_SendAddress[setting_userId.indexOf(userId)]); 902 +
819 - }); 903 + request(url, function(err, res, body){
820 - 904 + var title=[]
821 - 905 + var url2=[]
822 - /* 906 + var data=JSON.parse(body).items;
823 - service.videos.list 907 + for(var content in data)
824 - (
825 { 908 {
826 - key: 'AIzaSyBInggOtXxPFYIRee0Xs3vb5iZ9YE9_518', 909 + title.push(data[content].snippet.title);
827 - part: 'snippet', 910 + url2.push(data[content].id.videoId);
828 - id: choice,
829 - fields: 'items(snippet(title))'
830 - },
831 - function (err, response) {
832 - if (err) {
833 - console.log('The API returned an error: ', err);
834 - return;
835 - }
836 -
837 - var video = response.data.items;
838 -
839 - if (video.length == 0) {
840 - console.log('검색된 동영상이 없습니다.');
841 - }
842 - else {
843 - SEND(replyToken,response,choice,1,1,1);
844 - }
845 } 911 }
846 - 912 + if (title.length==0)
847 - )
848 - */
849 - }
850 -
851 - else if (choose == 001){ // 도움말
852 - sendMessage = "- 기본적으로 찾고 싶은 음악을 입력하여 보내면 적절한 음악 영상을 찾아 추천해드립니다."
853 - +"\n"+"예시) 소녀시대 노래"
854 - +"\n"+"- '플레이리스트'를 입력하면 분류에 따라 엄선한 음악을 추천드립니다!"
855 - +"\n"+"- '설정'을 입력하면 썸네일 출력 여부, 추천 음악 개수(1~10), 유튜브 주소 전송 여부를 설정하실 수 있습니다."
856 - +"\n"+"- 이 도움말을 다시 보고 싶으시다면 '도움말'을 입력하시면 됩니다! 음악과 함께 좋은 하루 보내세요.";
857 - HELP(replyToken,sendMessage);
858 - }
859 - else if (choose == 002) { // 설정
860 - SETTINGS(replyToken);
861 - }
862 -
863 - else { //플레이리스트
864 -
865 - PLAYLIST(replyToken);
866 - /*
867 - service.playlistItems.list(
868 - {
869 - key: Info.YoutubeKey,
870 - part: 'snippet',
871 - fields: 'items(snippet(title,resourceId,thumbnails(high(url))))', //제목, VideoId, Thumbnail 이미지 정보.
872 - maxResults: 10,
873 - playlistId: choice
874 - }, function (err, response){
875 - if (err) {
876 - console.log('The API returned an error: ', err);
877 - return;
878 - }
879 - var video = response.data.items;
880 - if (video.length == 0)
881 console.log('검색된 동영상이 없습니다.'); 913 console.log('검색된 동영상이 없습니다.');
882 else 914 else
883 - SEND_LIST(replyToken,response,choice,setting_Thumbnail[setting_userId.indexOf(userId)],setting_SendAmount[setting_userId.indexOf(userId)],setting_SendAddress[setting_userId.indexOf(userId)]); 915 + SEND(replyToken,title,url2,setting_Thumbnail[setting_userId.indexOf(userId)],setting_SendAmount[setting_userId.indexOf(userId)],setting_SendAddress[setting_userId.indexOf(userId)]);
884 - } 916 + });
885 - )
886 - */
887 } 917 }
888 } 918 }
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -10,8 +10,6 @@ const TARGET_URL = 'https://api.line.me/v2/bot/message/reply' ...@@ -10,8 +10,6 @@ const TARGET_URL = 'https://api.line.me/v2/bot/message/reply'
10 var app = express(); 10 var app = express();
11 app.use(bodyParser.json()); 11 app.use(bodyParser.json());
12 var songs = require('./check'); 12 var songs = require('./check');
13 -var thumbnail = 1;// 썸네일 출력 여부 (1:출력/0:미출력/기본값:1)
14 -var thumbnail_yes;
15 app.post('/hook', function (req, res) { 13 app.post('/hook', function (req, res) {
16 14
17 var eventObj = req.body.events[0]; 15 var eventObj = req.body.events[0];
...@@ -37,15 +35,21 @@ app.post('/hook', function (req, res) { ...@@ -37,15 +35,21 @@ app.post('/hook', function (req, res) {
37 songs.unablethumbnail(eventObj.replyToken,eventObj.source.userId); 35 songs.unablethumbnail(eventObj.replyToken,eventObj.source.userId);
38 break; 36 break;
39 37
40 - 38 + case "개수": //설정에서 전송 개수 설정버튼을 눌렀을때
41 -
42 -
43 - case "개수": //설정에서 출력 개수 설정버튼을 눌렀을때
44 songs.amount_settings(eventObj.replyToken,eventObj.source.userId); 39 songs.amount_settings(eventObj.replyToken,eventObj.source.userId);
45 break; 40 break;
46 - 41 + case "amount1": //설정 -> 전송 개수 -> 1
47 - 42 + songs.amount1(eventObj.replyToken,eventObj.source.userId);
48 - 43 + break;
44 + case "amount2": //설정 -> 전송 개수 -> 2
45 + songs.amount2(eventObj.replyToken,eventObj.source.userId);
46 + break;
47 + case "amount3": //설정 -> 전송 개수 -> 3
48 + songs.amount3(eventObj.replyToken,eventObj.source.userId);
49 + break;
50 + case "amount4": //설정 -> 전송 개수 -> 4
51 + songs.amount4(eventObj.replyToken,eventObj.source.userId);
52 + break;
49 53
50 case "주소": //설정에서 유튜브 주소 설정버튼을 눌렀을때 54 case "주소": //설정에서 유튜브 주소 설정버튼을 눌렀을때
51 songs.address_settings(eventObj.replyToken); 55 songs.address_settings(eventObj.replyToken);
...@@ -99,9 +103,6 @@ app.post('/hook', function (req, res) { ...@@ -99,9 +103,6 @@ app.post('/hook', function (req, res) {
99 case "twice": // 플레이리스트 -> 가수 -> 트와이스 103 case "twice": // 플레이리스트 -> 가수 -> 트와이스
100 songs.twice(eventObj.replyToken,eventObj.source.userId); 104 songs.twice(eventObj.replyToken,eventObj.source.userId);
101 break; 105 break;
102 -
103 -
104 - //case (출력 개수 설정 버튼을 누르고 거기서 응답이 들어왔을때)
105 } 106 }
106 res.sendStatus(200); 107 res.sendStatus(200);
107 } 108 }
......