tobby48 3 years ago
parent
commit
c7b1edf22b

+ 3
- 1
src/main/java/kr/co/swh/lecture/opensource/project/discode/JavaCordBot.java View File

@@ -4,10 +4,12 @@ import javax.security.auth.login.LoginException;
4 4
 
5 5
 import org.javacord.api.DiscordApi;
6 6
 import org.javacord.api.DiscordApiBuilder;
7
+import org.javacord.api.entity.emoji.CustomEmojiBuilder;
7 8
 import org.javacord.api.entity.message.Message;
8 9
 import org.javacord.api.entity.message.MessageBuilder;
9 10
 import org.javacord.api.entity.message.component.ActionRow;
10 11
 import org.javacord.api.entity.message.component.Button;
12
+import org.javacord.api.entity.message.component.ButtonStyle;
11 13
 import org.javacord.api.interaction.MessageComponentInteraction;
12 14
 
13 15
 
@@ -21,12 +23,12 @@ public class JavaCordBot {
21 23
         // Add a listener which answers with "Pong!" if someone writes "!ping"
22 24
         api.addMessageCreateListener(event -> {
23 25
             if (event.getMessageContent().equalsIgnoreCase("!ping")) {
24
-                
25 26
                 new MessageBuilder()
26 27
                 .setContent("Click on one of these Buttons!")
27 28
                 .addComponents(
28 29
                     ActionRow.of(Button.success("success", "Send a message"),
29 30
                         Button.danger("danger", "Delete this message"),
31
+//                        Button.create("hi", ButtonStyle.DANGER, "custom", "1F606"),
30 32
                         Button.secondary("secondary", "Remind me after 5 minutes")))
31 33
                 .send(event.getChannel());
32 34
             }

+ 12
- 5
src/main/java/kr/co/swh/lecture/opensource/project/discode/music/Youtube.java View File

@@ -52,7 +52,7 @@ public class Youtube {
52 52
 		return response.toString();
53 53
 	}
54 54
 	
55
-	public ArrayList<String> audio(String audio) {
55
+	public ArrayList<YoutubeInfo> audio(String audio) {
56 56
 		
57 57
 		Gson gsonObj = new Gson();
58 58
 		Map<String, String> inputMap = new HashMap<String, String>();
@@ -60,7 +60,7 @@ public class Youtube {
60 60
 		inputMap.put("blog", "https://web-inf.tistory.com");
61 61
 		
62 62
 		Youtube y = new Youtube();
63
-		ArrayList<String> alist = new ArrayList<String>();
63
+		ArrayList<YoutubeInfo> alist = new ArrayList<YoutubeInfo>();
64 64
 		try {
65 65
 			String s = y.search(""+ audio +"");
66 66
 			Map map = gsonObj.fromJson(s, Map.class);	
@@ -81,13 +81,20 @@ public class Youtube {
81 81
 				//System.out.println(title.get("title"));
82 82
 				String popo;
83 83
 				HashMap<String,String> disc = new HashMap<String,String>();
84
-				//disc.put("number",String.valueOf(a+1));
85
-				//disc.put("title",(String) title.get("title")); //값 추가
84
+				disc.put("number",String.valueOf(a+1));
85
+				disc.put("title",(String) title.get("title")); //값 추가
86 86
 				disc.put("address","https://www.youtube.com/watch?v="+((String) videoId.get("videoId")));
87
+				
88
+				YoutubeInfo you = new YoutubeInfo();
89
+				you.setTitle((String) title.get("title"));
90
+				you.setNumber(String.valueOf(a+1));
91
+				you.setAddress("https://www.youtube.com/watch?v="+((String) videoId.get("videoId")));
92
+				
93
+				
87 94
 				System.out.println(disc);
88 95
 				popo = "https://www.youtube.com/watch?v="+((String) videoId.get("videoId"));
89 96
 				
90
-				alist.add(popo);	
97
+				alist.add(you);	
91 98
 					if(a > 10)   
92 99
 					{
93 100
 						break;

+ 41
- 0
src/main/java/kr/co/swh/lecture/opensource/project/discode/music/YoutubeInfo.java View File

@@ -0,0 +1,41 @@
1
+package kr.co.swh.lecture.opensource.project.discode.music; 
2
+
3
+import org.apache.log4j.Logger;
4
+
5
+/**
6
+ * <pre>
7
+ * kr.co.swh.lecture.opensource.project.discode.music 
8
+ * YoutubeInfo.java
9
+ *
10
+ * 설명 :
11
+ * </pre>
12
+ * 
13
+ * @since : 2021. 7. 11.
14
+ * @author : tobby48
15
+ * @version : v1.0
16
+ */
17
+public class YoutubeInfo {
18
+
19
+	private String number;
20
+	private String title;
21
+	private String address;
22
+	public String getNumber() {
23
+		return number;
24
+	}
25
+	public void setNumber(String number) {
26
+		this.number = number;
27
+	}
28
+	public String getTitle() {
29
+		return title;
30
+	}
31
+	public void setTitle(String title) {
32
+		this.title = title;
33
+	}
34
+	public String getAddress() {
35
+		return address;
36
+	}
37
+	public void setAddress(String address) {
38
+		this.address = address;
39
+	}
40
+	
41
+}

+ 3
- 4
src/main/java/kr/co/swh/lecture/opensource/project/discode/music/YoutubeMusicListener.java View File

@@ -2,7 +2,6 @@ package kr.co.swh.lecture.opensource.project.discode.music;
2 2
 
3 3
 import java.util.ArrayList;
4 4
 
5
-import kr.co.swh.lecture.opensource.project.youtube.Youtube;
6 5
 import net.dv8tion.jda.api.EmbedBuilder;
7 6
 import net.dv8tion.jda.api.Permission;
8 7
 import net.dv8tion.jda.api.entities.Message;
@@ -93,10 +92,10 @@ public class YoutubeMusicListener extends ListenerAdapter{
93 92
 			String title = message.substring(3);
94 93
 			
95 94
 			Youtube y = new Youtube();
96
-			ArrayList<String> arr = y.audio(title);
95
+			ArrayList<YoutubeInfo> arr = y.audio(title);
97 96
 			
98 97
 			MessageEmbed embed = new EmbedBuilder()
99
-                    .setDescription(arr.get(0))
98
+                    .setDescription(arr.get(0).getTitle())
100 99
                     .setTitle(title)
101 100
                     .setFooter("swhacademy", null).build();
102 101
         	
@@ -105,7 +104,7 @@ public class YoutubeMusicListener extends ListenerAdapter{
105 104
 			});;
106 105
 			
107 106
 			PlayerManager Playermanager = PlayerManager.getINSTANCE();
108
-			Playermanager.loadAndPlay(tc, arr.get(0));
107
+			Playermanager.loadAndPlay(tc, arr.get(0).getTitle());
109 108
 			Playermanager.getGuildMusicManager(tc.getGuild()).player.setVolume(10);
110 109
 			
111 110