Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit ef10469

Browse files
committed
Migrated all Commands to SlashCommands
1 parent 813bb01 commit ef10469

File tree

1 file changed

+154
-172
lines changed

1 file changed

+154
-172
lines changed

src/main/java/HandleChannelMovement.java

Lines changed: 154 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import net.dv8tion.jda.api.JDA;
22
import net.dv8tion.jda.api.Permission;
33
import net.dv8tion.jda.api.entities.*;
4+
import net.dv8tion.jda.api.entities.channel.Channel;
45
import net.dv8tion.jda.api.entities.channel.ChannelType;
56
import net.dv8tion.jda.api.entities.channel.concrete.Category;
67
import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel;
@@ -85,172 +86,6 @@ public void run() {
8586
});
8687
}
8788

88-
@Override
89-
public void onMessageReceived(MessageReceivedEvent event) {
90-
Message message = event.getMessage();
91-
MessageChannel channel = event.getChannel();
92-
String content = message.getContentRaw();
93-
User user = event.getAuthor();
94-
Member member = event.getMember();
95-
if (!event.isFromType(ChannelType.PRIVATE) && !user.isBot()){
96-
//_____________________________
97-
//Add Master
98-
//_____________________________
99-
if (content.startsWith(prefix + "addMaster")){
100-
if (member != null && member.hasPermission(Permission.ADMINISTRATOR)) {
101-
long channelid = -1L;
102-
try {
103-
channelid = Long.parseLong(content.substring(10+prefix.length()));
104-
} catch (Exception ignore){
105-
channel.sendMessage("No valid Channel-ID provided").queue();
106-
return;
107-
}
108-
if(channelid != -1L){
109-
VoiceChannel vc = (VoiceChannel) event.getGuild().getGuildChannelById(ChannelType.VOICE,channelid);
110-
if (vc != null){
111-
tmpMasterChannelList.add(vc);
112-
tmpChannelCount.put(vc,0);
113-
masterNames.put(vc,vc.getName());
114-
recreateTmpChannels(event.getGuild());
115-
saveConfig();
116-
channel.sendMessage("Added Master: <#" + channelid +">").queue();
117-
}else {
118-
channel.sendMessage("Channel not found").queue();
119-
}
120-
}else {
121-
channel.sendMessage("Channel not found").queue();
122-
}
123-
}else {
124-
channel.sendMessage("You are not an Administrator").queue();
125-
}
126-
}
127-
//_____________________________
128-
//Remove Master
129-
//_____________________________
130-
else if (content.startsWith(prefix + "removeMaster")){
131-
if (member != null && member.hasPermission(Permission.ADMINISTRATOR)) {
132-
long channelid = -1L;
133-
try {
134-
channelid = Long.parseLong(content.substring(13+prefix.length()));
135-
}
136-
catch (Exception ignore){
137-
channel.sendMessage("No valid Channel-ID provided").queue();
138-
return;
139-
}
140-
if(channelid != -1L){
141-
VoiceChannel vc = (VoiceChannel) event.getGuild().getGuildChannelById(ChannelType.VOICE,channelid);
142-
if (vc != null){
143-
if (tmpMasterChannelList.contains(vc)){
144-
tmpMasterChannelList.remove(vc);
145-
tmpChannelCount.remove(vc);
146-
masterNames.remove(vc);
147-
channel.sendMessage("Removed Master: <#" + channelid +">").queue();
148-
saveConfig();
149-
recreateTmpChannels(event.getGuild());
150-
}
151-
else {
152-
channel.sendMessage("Channel isn't a Master Channel").queue();
153-
}
154-
}
155-
else {
156-
channel.sendMessage("Channel not found").queue();
157-
}
158-
}
159-
}else {
160-
channel.sendMessage("You are not an Administrator").queue();
161-
}
162-
}
163-
//_____________________________
164-
//Get TmpChannels
165-
//_____________________________
166-
else if (content.startsWith(prefix + "getTmpChannels")){
167-
if (member != null && member.hasPermission(Permission.MANAGE_ROLES)) {
168-
StringBuilder sb = new StringBuilder();
169-
sb.append("tmpChannels: \n");
170-
for (VoiceChannel vc : tmpChannelList){
171-
sb.append("<#").append(vc.getId()).append("> \n");
172-
}
173-
channel.sendMessage(sb.toString()).queue();
174-
}else {
175-
channel.sendMessage("You haven't got enough Permissions").queue();
176-
}
177-
}
178-
//_____________________________
179-
//Get Masters
180-
//_____________________________
181-
else if (content.startsWith(prefix + "getMasters")){
182-
if (member != null && member.hasPermission(Permission.MANAGE_ROLES)) {
183-
StringBuilder sb = new StringBuilder();
184-
sb.append("Masters: \n");
185-
for (VoiceChannel vc : tmpMasterChannelList){
186-
sb.append("<#").append(vc.getId()).append("> \n");
187-
}
188-
channel.sendMessage(sb.toString()).queue();
189-
}
190-
else {
191-
channel.sendMessage("You haven't got enough Permissions").queue();
192-
}
193-
}
194-
//_____________________________
195-
//Set Debug channel
196-
//_____________________________
197-
else if (content.startsWith(prefix + "setDebugChannel")){
198-
if (member != null && member.hasPermission(Permission.ADMINISTRATOR)) {
199-
long channelid = -1L;
200-
try {
201-
channelid = Long.parseLong(content.substring(16+prefix.length()));
202-
} catch (Exception ignore){
203-
channel.sendMessage("No valid Channel-ID provided").queue();
204-
return;
205-
}
206-
if(channelid != -1L){
207-
TextChannel tc = event.getGuild().getTextChannelById(channelid);
208-
if (tc != null){
209-
debugChannel = tc;
210-
saveConfig();
211-
channel.sendMessage("Debug Channel set to: <#" + channelid +">").queue();
212-
tc.sendMessage("This is now the Debug Channel").queue();
213-
}
214-
else {
215-
channel.sendMessage("Channel not found").queue();
216-
}
217-
}
218-
}
219-
else {
220-
channel.sendMessage("You are not an Administrator").queue();
221-
}
222-
}
223-
//_____________________________
224-
//Get Debug channel
225-
//_____________________________
226-
else if (content.startsWith(prefix + "getDebugChannel")){
227-
if (member != null && member.hasPermission(Permission.MANAGE_ROLES)) {
228-
if (debugChannel != null){
229-
channel.sendMessage("Debug Channel is: <#" + debugChannel.getId() +">").queue();
230-
}
231-
else {
232-
channel.sendMessage("No Debug Channel set").queue();
233-
}
234-
}
235-
else {
236-
channel.sendMessage("You haven't got enough Permissions").queue();
237-
}
238-
}
239-
//_____________________________
240-
//Recreate Tmp-Channels
241-
//_____________________________
242-
else if (content.startsWith(prefix + "recreateTmpChannels")){
243-
if (member != null && member.hasPermission(Permission.ADMINISTRATOR)) {
244-
recreateTmpChannels(event.getGuild());
245-
channel.sendMessage("All Tmp-Channels deleted").queue();
246-
}
247-
else {
248-
channel.sendMessage("You are not an Administrator").queue();
249-
}
250-
}
251-
}
252-
}
253-
25489
@Override
25590
public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent event) {
25691
//if left
@@ -315,7 +150,7 @@ else if (command.equals("miesmuschel")){
315150
//random
316151
//_____________________________
317152
else if (command.equals("rand")) {
318-
String arguments = event.getOption("options") != null ? event.getOption("options").getAsString() : "";
153+
String arguments = event.getOption("options").getAsString();
319154
if (arguments.equals("")){
320155
event.reply("No Options provided").queue();
321156
return;
@@ -332,6 +167,7 @@ else if (command.equals("setup") && !event.isFromGuild()){
332167
//Guild Commands
333168
//_____________________________
334169
else if (event.isFromGuild()){
170+
Member member = event.getMember();
335171
//_____________________________
336172
//Setup
337173
//_____________________________
@@ -341,6 +177,143 @@ else if (event.isFromGuild()){
341177
addGuildSlashCommands();
342178
event.reply("Setup done").queue();
343179
}
180+
181+
//_____________________________
182+
//Add Master
183+
//_____________________________
184+
else if (command.equals("addmaster")){
185+
if (member != null && member.hasPermission(Permission.ADMINISTRATOR)) {
186+
Channel channel = event.getOption("channel").getAsChannel();
187+
if (channel.getType() == ChannelType.VOICE){
188+
VoiceChannel vc = event.getOption("channel").getAsChannel().asVoiceChannel();
189+
if (!tmpMasterChannelList.contains(vc)){
190+
tmpMasterChannelList.add(vc);
191+
tmpChannelCount.put(vc,0);
192+
masterNames.put(vc,vc.getName());
193+
recreateTmpChannels(event.getGuild());
194+
saveConfig();
195+
event.reply("Added <#" + vc.getId() + "> as Master Channel").queue();
196+
}else {
197+
event.reply("<#" + vc.getId() + "> is already a Master Channel").queue();
198+
}
199+
}else {
200+
event.reply("Channel is not a Voice Channel").queue();
201+
}
202+
}else {
203+
event.reply("You are not an Administrator").queue();
204+
}
205+
}
206+
207+
//_____________________________
208+
//Remove Master
209+
//_____________________________
210+
else if (command.equals("removemaster")){
211+
if (member != null && member.hasPermission(Permission.ADMINISTRATOR)) {
212+
Channel channel = event.getOption("channel").getAsChannel();
213+
if (channel.getType() == ChannelType.VOICE){
214+
VoiceChannel vc = event.getOption("channel").getAsChannel().asVoiceChannel();
215+
if (tmpMasterChannelList.contains(vc)){
216+
tmpMasterChannelList.remove(vc);
217+
tmpChannelCount.remove(vc);
218+
masterNames.remove(vc);
219+
event.reply("Removed <#" + vc.getId() + "> as Master Channel").queue();
220+
saveConfig();
221+
recreateTmpChannels(event.getGuild());
222+
}
223+
else {
224+
event.reply("Channel is not a Master Channel").queue();
225+
}
226+
}else {
227+
event.reply("Channel is not a Voice Channel").queue();
228+
}
229+
}else {
230+
event.reply("You are not an Administrator").queue();
231+
}
232+
}
233+
234+
//_____________________________
235+
//Get TmpChannels
236+
//_____________________________
237+
else if (command.equals( "gettmpchannels")){
238+
if (member != null && member.hasPermission(Permission.MANAGE_ROLES)) {
239+
StringBuilder sb = new StringBuilder();
240+
sb.append("tmpChannels: \n");
241+
for (VoiceChannel vc : tmpChannelList){
242+
sb.append("<#").append(vc.getId()).append("> \n");
243+
}
244+
event.reply(sb.toString()).queue();
245+
}else {
246+
event.reply("You haven't got enough Permissions").queue();
247+
}
248+
}
249+
250+
//_____________________________
251+
//Get Masters
252+
//_____________________________
253+
else if (command.equals("getmasterchannels")){
254+
if (member != null && member.hasPermission(Permission.MANAGE_ROLES)) {
255+
StringBuilder sb = new StringBuilder();
256+
sb.append("Masters: \n");
257+
for (VoiceChannel vc : tmpMasterChannelList){
258+
sb.append("<#").append(vc.getId()).append("> \n");
259+
}
260+
event.reply(sb.toString()).queue();
261+
}
262+
else {
263+
event.reply("You haven't got enough Permissions").queue();
264+
}
265+
}
266+
267+
//_____________________________
268+
//Set Debug channel
269+
//_____________________________
270+
else if (command.equals("setdebugchannel")){
271+
if (member != null && member.hasPermission(Permission.ADMINISTRATOR)) {
272+
Channel channel = event.getOption("channel").getAsChannel();
273+
if (channel.getType() == ChannelType.TEXT){
274+
TextChannel tc = event.getOption("channel").getAsChannel().asTextChannel();
275+
debugChannel = tc;
276+
saveConfig();
277+
event.reply("Set <#" + tc.getId() + "> as Debug Channel").queue();
278+
tc.sendMessage("This is now the Debug Channel").queue();
279+
}else {
280+
event.reply("Channel is not a Text Channel").queue();
281+
}
282+
}
283+
else {
284+
event.reply("You are not an Administrator").queue();
285+
}
286+
}
287+
288+
//_____________________________
289+
//Get Debug channel
290+
//_____________________________
291+
else if (command.equals("getdebugchannel")){
292+
if (member != null && member.hasPermission(Permission.MANAGE_ROLES)) {
293+
if (debugChannel != null){
294+
event.reply("Debug Channel is <#" + debugChannel.getId() + ">").queue();
295+
}
296+
else {
297+
event.reply("No Debug Channel set\nSet a debug channel with /setdebugchannel").queue();
298+
}
299+
}
300+
else {
301+
event.reply("You haven't got enough Permissions").queue();
302+
}
303+
}
304+
305+
//_____________________________
306+
//Recreate Tmp-Channels
307+
//_____________________________
308+
else if (command.equals("recreatetmpchannels")){
309+
if (member != null && member.hasPermission(Permission.ADMINISTRATOR)) {
310+
recreateTmpChannels(event.getGuild());
311+
event.reply("All Tmp-Channels deleted").queue();
312+
}
313+
else {
314+
event.reply("You are not an Administrator").queue();
315+
}
316+
}
344317
}
345318
super.onSlashCommandInteraction(event);
346319
}
@@ -519,7 +492,7 @@ public void addGlobalSlashCommands(){
519492
complete++;
520493
}
521494
}
522-
if (complete >= commandNames.length){
495+
if (complete < commandNames.length){
523496
//add commands
524497
jda.updateCommands().addCommands(
525498
Commands.slash("ping", "Ping the bot"),
@@ -534,18 +507,27 @@ public void addGlobalSlashCommands(){
534507

535508
public void addGuildSlashCommands(){
536509
//check if command exists
537-
List<Command> commands = jda.retrieveCommands().complete();
538-
final String[] commandNames = {};
510+
List<Command> commands = guild.retrieveCommands().complete();
511+
final String[] commandNames = {"addmaster","removemaster","gettmpchannels","getmasterchannels","setdebugchannel","getdebugchannel"};
539512
int complete = 0;
540513
for (Command c : commands){
541514
if (Arrays.binarySearch(commandNames,c.getName()) >= 0){
542515
complete++;
543516
}
544517
}
545-
if (complete >= commandNames.length){
518+
if (complete < commandNames.length){
546519
//add commands
547520
guild.updateCommands().addCommands(
548-
//Commands.slash("ping", "Ping the bot")
521+
Commands.slash("addmaster", "Adding a Master Channel which will be always available")
522+
.addOption(OptionType.CHANNEL, "channel", "The Channel you want to add", true),
523+
Commands.slash("removemaster", "Removing a Master Channel")
524+
.addOption(OptionType.CHANNEL, "channel", "The Channel you want to remove", true),
525+
Commands.slash("gettmpchannels", "Get a list of all tmp Channels"),
526+
Commands.slash("getmasterchannels", "Get a list of all master Channels"),
527+
Commands.slash("setdebugchannel", "Set the Debug Channel")
528+
.addOption(OptionType.CHANNEL, "channel", "The Channel you want to set", true),
529+
Commands.slash("getdebugchannel", "Get the Debug Channel"),
530+
Commands.slash("recreatetmpchannels", "Recreate all tmp Channels (WARNING: All Members will be kicked from the tmp and Master Channels)")
549531
).queue();
550532
}
551533
}

0 commit comments

Comments
 (0)