|
@@ -1,15 +1,80 @@
|
1
|
1
|
package kr.co.swh.lecture.opensource.project.discode.music;
|
2
|
2
|
|
3
|
3
|
import java.awt.Color;
|
|
4
|
+import java.nio.ByteBuffer;
|
|
5
|
+import java.util.ArrayList;
|
4
|
6
|
|
|
7
|
+import kr.co.swh.lecture.opensource.project.youtube.Youtube;
|
5
|
8
|
import net.dv8tion.jda.api.EmbedBuilder;
|
|
9
|
+import net.dv8tion.jda.api.Permission;
|
6
|
10
|
import net.dv8tion.jda.api.entities.Message;
|
7
|
11
|
import net.dv8tion.jda.api.entities.TextChannel;
|
8
|
12
|
import net.dv8tion.jda.api.entities.User;
|
|
13
|
+import net.dv8tion.jda.api.entities.VoiceChannel;
|
9
|
14
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
|
15
|
+import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
10
|
16
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
|
17
|
+import net.dv8tion.jda.api.managers.AudioManager;
|
11
|
18
|
|
12
|
19
|
public class LayoutListener extends ListenerAdapter{
|
|
20
|
+
|
|
21
|
+ @Override
|
|
22
|
+ public void onGuildMessageReceived(GuildMessageReceivedEvent event) {
|
|
23
|
+ // TODO Auto-generated method stub
|
|
24
|
+ // super.onGuildMessageReceived(event);
|
|
25
|
+ // Good practise to ignore bots.
|
|
26
|
+ if(event.getAuthor().isBot()) {
|
|
27
|
+ return;
|
|
28
|
+ }
|
|
29
|
+ // Gets the raw message content and binds it to a local variable.
|
|
30
|
+ String message = event.getMessage().getContentRaw().toLowerCase();
|
|
31
|
+ // So we don't have to access event.getChannel() every time.
|
|
32
|
+ TextChannel channel = event.getChannel();
|
|
33
|
+ // Checks if the command is !join.
|
|
34
|
+ if(message.equals("!join")) {
|
|
35
|
+ // Checks if the bot has permissions.
|
|
36
|
+ if(!event.getGuild().getSelfMember().hasPermission(channel, Permission.VOICE_CONNECT)) {
|
|
37
|
+ // The bot does not have permission to join any voice channel. Don't forget the .queue()!
|
|
38
|
+ channel.sendMessage("I do not have permissions to join a voice channel!").queue();
|
|
39
|
+ return;
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+// net.dv8tion.jda.api.entities.Member m = event.getMember();
|
|
43
|
+ // Creates a variable equal to the channel that the user is in.
|
|
44
|
+ VoiceChannel connectedChannel = event.getMember().getVoiceState().getChannel();
|
|
45
|
+ // Checks if they are in a channel -- not being in a channel means that the variable = null.
|
|
46
|
+ if(connectedChannel == null) {
|
|
47
|
+ // Don't forget to .queue()!
|
|
48
|
+ channel.sendMessage("You are not connected to a voice channel!").queue();
|
|
49
|
+ return;
|
|
50
|
+ }
|
|
51
|
+ // Gets the audio manager.
|
|
52
|
+ AudioManager audioManager = event.getGuild().getAudioManager();
|
|
53
|
+ // When somebody really needs to chill.
|
|
54
|
+ if(audioManager.isAttemptingToConnect()) {
|
|
55
|
+ channel.sendMessage("The bot is already trying to connect! Enter the chill zone!").queue();
|
|
56
|
+ return;
|
|
57
|
+ }
|
|
58
|
+ // Connects to the channel.
|
|
59
|
+ audioManager.openAudioConnection(connectedChannel);
|
|
60
|
+ // Obviously people do not notice someone/something connecting.
|
|
61
|
+ channel.sendMessage("Connected to the voice channel!").queue();
|
|
62
|
+ } else if(message.equals("!leave")) { // Checks if the command is !leave.
|
|
63
|
+ // Gets the channel in which the bot is currently connected.
|
|
64
|
+ VoiceChannel connectedChannel = event.getGuild().getSelfMember().getVoiceState().getChannel();
|
|
65
|
+ // Checks if the bot is connected to a voice channel.
|
|
66
|
+ if(connectedChannel == null) {
|
|
67
|
+ // Get slightly fed up at the user.
|
|
68
|
+ channel.sendMessage("I am not connected to a voice channel!").queue();
|
|
69
|
+ return;
|
|
70
|
+ }
|
|
71
|
+ // Disconnect from the channel.
|
|
72
|
+ event.getGuild().getAudioManager().closeAudioConnection();
|
|
73
|
+ // Notify the user.
|
|
74
|
+ channel.sendMessage("Disconnected from the voice channel!").queue();
|
|
75
|
+ }
|
|
76
|
+
|
|
77
|
+ }
|
13
|
78
|
|
14
|
79
|
@Override
|
15
|
80
|
public void onMessageReceived(MessageReceivedEvent event) {
|
|
@@ -18,95 +83,131 @@ public class LayoutListener extends ListenerAdapter{
|
18
|
83
|
TextChannel tc = event.getTextChannel();
|
19
|
84
|
Message msg = event.getMessage();
|
20
|
85
|
if(user.isBot()) return;
|
21
|
|
-
|
22
|
|
-
|
|
86
|
+
|
23
|
87
|
String message = msg.getContentRaw();
|
24
|
|
- System.out.println(message.substring(0, 3));
|
25
|
|
-
|
26
|
|
- String m=message;
|
27
|
|
- if(message.substring(0, 3).equals("!! ")) {
|
28
|
|
- m = message.substring(3);
|
|
88
|
+ if(message.substring(0, 3).equals("!l ")) {
|
|
89
|
+ String title = message.substring(3);
|
|
90
|
+
|
|
91
|
+ Youtube y = new Youtube();
|
|
92
|
+ ArrayList<String> arr = y.audio(title);
|
|
93
|
+
|
|
94
|
+ PlayerManager Playermanager = PlayerManager.getINSTANCE();
|
|
95
|
+ Playermanager.loadAndPlay(tc, arr.get(0));
|
|
96
|
+ Playermanager.getGuildMusicManager(tc.getGuild()).player.setVolume(10);
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+// for(String s : arr) {
|
|
100
|
+// // Create the EmbedBuilder instance
|
|
101
|
+// EmbedBuilder eb = new EmbedBuilder();
|
|
102
|
+//
|
|
103
|
+// /*
|
|
104
|
+// Set the title:
|
|
105
|
+// 1. Arg: title as string
|
|
106
|
+// 2. Arg: URL as string or could also be null
|
|
107
|
+// */
|
|
108
|
+// eb.setTitle(title, null);
|
|
109
|
+// eb.setThumbnail("https://swhcoding.com/img/testimonials/person-1.gif");
|
|
110
|
+// eb.setColor(Color.red);
|
|
111
|
+// eb.setColor(new Color(0xF40C0C));
|
|
112
|
+// eb.setColor(new Color(255, 0, 54));
|
|
113
|
+//
|
|
114
|
+// eb.addField(title, s, false);
|
|
115
|
+//// tc.sendMessage(eb.build()).queue(response /* => Message */ -> {
|
|
116
|
+////
|
|
117
|
+//// response.editMessage(s).queue();
|
|
118
|
+////
|
|
119
|
+//// });
|
|
120
|
+// tc.sendMessage(title) /* => RestAction<Message> */
|
|
121
|
+// .queue(response /* => Message */ -> {
|
|
122
|
+//
|
|
123
|
+// response.editMessage(s).queue();
|
|
124
|
+//
|
|
125
|
+// });
|
|
126
|
+// }
|
29
|
127
|
}
|
30
|
|
-
|
31
|
|
-// // 형태소 분석
|
32
|
|
-// for (Eojeol eojeol : Analyzer.parseEojeolJava(msg.getContentRaw())) {
|
33
|
|
-// for (LNode node : eojeol.nodesJava()) {
|
34
|
|
-// Morpheme m = node.morpheme();
|
35
|
|
-// tc.sendMessage(m.surface() + " / 품사:" + m.feature().head()).queue();
|
36
|
|
-// }
|
37
|
|
-// }
|
38
|
|
-
|
39
|
|
-// EmbedBuilder eb = new EmbedBuilder();
|
40
|
|
-// eb.setTitle("It's GIVEAWAY-TIME!");
|
41
|
|
-// eb.setDescription("Prize: " + "\n Winners: " + 1);
|
42
|
|
-// eb.setColor(Color.BLUE);
|
43
|
|
-// eb.setFooter("바닥");
|
44
|
|
-
|
45
|
|
- // Create the EmbedBuilder instance
|
46
|
|
- EmbedBuilder eb = new EmbedBuilder();
|
47
|
|
-
|
48
|
|
- /*
|
49
|
|
- Set the title:
|
50
|
|
- 1. Arg: title as string
|
51
|
|
- 2. Arg: URL as string or could also be null
|
52
|
|
- */
|
53
|
|
- eb.setTitle(m, null);
|
54
|
128
|
|
55
|
|
- /*
|
56
|
|
- Set the color
|
57
|
|
- */
|
58
|
|
- eb.setColor(Color.red);
|
59
|
|
- eb.setColor(new Color(0xF40C0C));
|
60
|
|
- eb.setColor(new Color(255, 0, 54));
|
61
|
129
|
|
62
|
|
- /*
|
63
|
|
- Set the text of the Embed:
|
64
|
|
- Arg: text as string
|
65
|
|
- */
|
66
|
|
- eb.setDescription("Text");
|
67
|
130
|
|
68
|
|
- /*
|
69
|
|
- Add fields to embed:
|
70
|
|
- 1. Arg: title as string
|
71
|
|
- 2. Arg: text as string
|
72
|
|
- 3. Arg: inline mode true / false
|
73
|
|
- */
|
74
|
|
- eb.addField("Title of field", "test of field", false);
|
|
131
|
+ // // 형태소 분석
|
|
132
|
+ // for (Eojeol eojeol : Analyzer.parseEojeolJava(msg.getContentRaw())) {
|
|
133
|
+ // for (LNode node : eojeol.nodesJava()) {
|
|
134
|
+ // Morpheme m = node.morpheme();
|
|
135
|
+ // tc.sendMessage(m.surface() + " / 품사:" + m.feature().head()).queue();
|
|
136
|
+ // }
|
|
137
|
+ // }
|
75
|
138
|
|
76
|
|
- /*
|
77
|
|
- Add spacer like field
|
78
|
|
- Arg: inline mode true / false
|
79
|
|
- */
|
80
|
|
- eb.addBlankField(false);
|
|
139
|
+ // EmbedBuilder eb = new EmbedBuilder();
|
|
140
|
+ // eb.setTitle("It's GIVEAWAY-TIME!");
|
|
141
|
+ // eb.setDescription("Prize: " + "\n Winners: " + 1);
|
|
142
|
+ // eb.setColor(Color.BLUE);
|
|
143
|
+ // eb.setFooter("바닥");
|
81
|
144
|
|
82
|
|
- /*
|
83
|
|
- Add embed author:
|
84
|
|
- 1. Arg: name as string
|
85
|
|
- 2. Arg: url as string (can be null)
|
86
|
|
- 3. Arg: icon url as string (can be null)
|
87
|
|
- */
|
88
|
|
-// eb.setAuthor("name", null, "https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/zekroBot_Logo_-_round_small.png");
|
89
|
|
-
|
90
|
|
- /*
|
91
|
|
- Set footer:
|
92
|
|
- 1. Arg: text as string
|
93
|
|
- 2. icon url as string (can be null)
|
94
|
|
- */
|
95
|
|
-// eb.setFooter("Text", "https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/zekroBot_Logo_-_round_small.png");
|
96
|
|
-
|
97
|
|
- /*
|
98
|
|
- Set image:
|
99
|
|
- Arg: image url as string
|
100
|
|
- */
|
101
|
|
-// eb.setImage("https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/logo%20-%20title.png");
|
|
145
|
+// // Create the EmbedBuilder instance
|
|
146
|
+// EmbedBuilder eb = new EmbedBuilder();
|
|
147
|
+//
|
|
148
|
+// /*
|
|
149
|
+// Set the title:
|
|
150
|
+// 1. Arg: title as string
|
|
151
|
+// 2. Arg: URL as string or could also be null
|
|
152
|
+// */
|
|
153
|
+// eb.setTitle(m, null);
|
|
154
|
+// eb.setThumbnail("https://swhcoding.com/img/testimonials/person-1.gif");
|
|
155
|
+//
|
|
156
|
+// /*
|
|
157
|
+// Set the color
|
|
158
|
+// */
|
|
159
|
+// eb.setColor(Color.red);
|
|
160
|
+// eb.setColor(new Color(0xF40C0C));
|
|
161
|
+// eb.setColor(new Color(255, 0, 54));
|
|
162
|
+//
|
|
163
|
+// /*
|
|
164
|
+// Set the text of the Embed:
|
|
165
|
+// Arg: text as string
|
|
166
|
+// */
|
|
167
|
+//// eb.setDescription("Text");
|
|
168
|
+//
|
|
169
|
+// /*
|
|
170
|
+// Add fields to embed:
|
|
171
|
+// 1. Arg: title as string
|
|
172
|
+// 2. Arg: text as string
|
|
173
|
+// 3. Arg: inline mode true / false
|
|
174
|
+// */
|
|
175
|
+// eb.addField("Title of field", "test of field", false);
|
|
176
|
+//
|
|
177
|
+//// /*
|
|
178
|
+//// Add spacer like field
|
|
179
|
+//// Arg: inline mode true / false
|
|
180
|
+//// */
|
|
181
|
+//// eb.addBlankField(false);
|
|
182
|
+//
|
|
183
|
+// /*
|
|
184
|
+// Add embed author:
|
|
185
|
+// 1. Arg: name as string
|
|
186
|
+// 2. Arg: url as string (can be null)
|
|
187
|
+// 3. Arg: icon url as string (can be null)
|
|
188
|
+// */
|
|
189
|
+// // eb.setAuthor("name", null, "https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/zekroBot_Logo_-_round_small.png");
|
|
190
|
+//
|
|
191
|
+// /*
|
|
192
|
+// Set footer:
|
|
193
|
+// 1. Arg: text as string
|
|
194
|
+// 2. icon url as string (can be null)
|
|
195
|
+// */
|
|
196
|
+// // eb.setFooter("Text", "https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/zekroBot_Logo_-_round_small.png");
|
|
197
|
+//
|
|
198
|
+// /*
|
|
199
|
+// Set image:
|
|
200
|
+// Arg: image url as string
|
|
201
|
+// */
|
|
202
|
+// // eb.setImage("https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/logo%20-%20title.png");
|
|
203
|
+//
|
|
204
|
+// /*
|
|
205
|
+// Set thumbnail image:
|
|
206
|
+// Arg: image url as string
|
|
207
|
+// */
|
|
208
|
+// // eb.setThumbnail("https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/logo%20-%20title.png");
|
|
209
|
+// event.getTextChannel().sendMessage(eb.build()).queue();
|
102
|
210
|
|
103
|
|
- /*
|
104
|
|
- Set thumbnail image:
|
105
|
|
- Arg: image url as string
|
106
|
|
- */
|
107
|
|
-// eb.setThumbnail("https://github.com/zekroTJA/DiscordBot/blob/master/.websrc/logo%20-%20title.png");
|
108
|
|
- event.getTextChannel().sendMessage(eb.build()).queue();
|
109
|
|
-
|
110
|
211
|
}
|
111
|
212
|
|
112
|
213
|
}
|