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

Commit f542331

Browse files
committed
Updated Bot to new Version
1 parent 45dc970 commit f542331

File tree

3 files changed

+100
-68
lines changed

3 files changed

+100
-68
lines changed

pom.xml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,41 @@
2525
<dependency>
2626
<groupId>net.dv8tion</groupId>
2727
<artifactId>JDA</artifactId>
28-
<version>4.2.0_228</version>
28+
<version>5.0.0-alpha.22</version>
2929
</dependency>
30+
<!-- https://mvnrepository.com/artifact/com.jagrosh/jda-utilities-commons -->
3031
<dependency>
3132
<groupId>com.jagrosh</groupId>
32-
<artifactId>jda-utilities</artifactId>
33-
<version>3.0.5</version>
34-
<scope>compile</scope>
35-
<type>pom</type>
33+
<artifactId>jda-utilities-commons</artifactId>
34+
<version>2.1.2</version>
35+
</dependency>
36+
<!-- https://mvnrepository.com/artifact/com.jagrosh/jda-utilities-command -->
37+
<dependency>
38+
<groupId>com.jagrosh</groupId>
39+
<artifactId>jda-utilities-command</artifactId>
40+
<version>2.1.2</version>
41+
</dependency>
42+
<!-- https://mvnrepository.com/artifact/com.jagrosh/jda-utilities-menu -->
43+
<dependency>
44+
<groupId>com.jagrosh</groupId>
45+
<artifactId>jda-utilities-menu</artifactId>
46+
<version>2.1.1</version>
47+
</dependency>
48+
<!-- https://mvnrepository.com/artifact/com.jagrosh/jda-utilities-doc -->
49+
<dependency>
50+
<groupId>com.jagrosh</groupId>
51+
<artifactId>jda-utilities-doc</artifactId>
52+
<version>2.1.2</version>
3653
</dependency>
3754
<dependency>
3855
<groupId>org.slf4j</groupId>
3956
<artifactId>slf4j-api</artifactId>
40-
<version>1.7.36</version>
57+
<version>2.0.3</version>
4158
</dependency>
4259
<dependency>
4360
<groupId>org.slf4j</groupId>
4461
<artifactId>slf4j-simple</artifactId>
45-
<version>1.7.36</version>
62+
<version>2.0.3</version>
4663
</dependency>
4764
</dependencies>
4865

src/main/java/HandleChannelMovement.java

Lines changed: 74 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
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.ChannelType;
5+
import net.dv8tion.jda.api.entities.channel.concrete.Category;
6+
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
7+
import net.dv8tion.jda.api.entities.channel.concrete.VoiceChannel;
8+
import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel;
9+
import net.dv8tion.jda.api.events.guild.GuildLeaveEvent;
410
import net.dv8tion.jda.api.events.guild.voice.*;
11+
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
512
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
613
import net.dv8tion.jda.api.hooks.ListenerAdapter;
714
import net.dv8tion.jda.api.requests.restaction.ChannelAction;
@@ -298,75 +305,82 @@ else if (content.startsWith(prefix + "setup")){
298305
}
299306

300307
@Override
301-
public void onGuildVoiceJoin(GuildVoiceJoinEvent event){
302-
handleJoin(event);
303-
}
304-
305-
@Override
306-
public void onGuildVoiceLeave(@NotNull GuildVoiceLeaveEvent event) {
307-
handleLeft(event);
308-
}
309-
310-
@Override
311-
public void onGuildVoiceMove(@NotNull GuildVoiceMoveEvent event) {
312-
System.out.println("Moved from "+event.getChannelLeft().getName() + " to "+event.getChannelJoined().getName());
313-
handleJoin(event);
314-
handleLeft(event);
308+
public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent event) {
309+
//if left
310+
if (event.getChannelLeft() != null && event.getChannelJoined() == null){
311+
handleLeft(event);
312+
}
313+
//if joined
314+
else if (event.getChannelLeft() == null && event.getChannelJoined() != null){
315+
handleJoin(event);
316+
}
317+
//if moved
318+
else if (event.getChannelLeft() != null && event.getChannelJoined() != null){
319+
if (!event.getChannelLeft().equals(event.getChannelJoined())){
320+
handleLeft(event);
321+
handleJoin(event);
322+
}
323+
}
324+
super.onGuildVoiceUpdate(event);
315325
}
316326

317-
public void handleJoin(GenericGuildVoiceUpdateEvent event){
318-
VoiceChannel vc = event.getChannelJoined();
319-
int usersInVC = vc.getMembers().size();
320-
if (usersInVC == 1){
321-
if (tmpChannelList.contains(vc)){
322-
VoiceChannel master = tmpChannelMapMaster.get(vc);
323-
createTmpChannel(event.getGuild(), masterNames.get(master),tmpChannelCount.get(master)+1,vc.getPosition(),vc.getUserLimit(),master,vc.getParent(),vc.getBitrate());
324-
tmpChannelCount.put(master,tmpChannelCount.get(master)+1);
325-
}else if (tmpMasterChannelList.contains(vc) && tmpChannelCount.get(vc) == 0){
326-
createTmpChannel(event.getGuild(), vc.getName(),1,vc.getPosition(),vc.getUserLimit(),vc,vc.getParent(),vc.getBitrate());
327-
tmpChannelCount.put(vc,1);
327+
public void handleJoin(GuildVoiceUpdateEvent event){
328+
if (event.getChannelJoined() != null){
329+
VoiceChannel vc = event.getChannelJoined().asVoiceChannel();
330+
int usersInVC = vc.getMembers().size();
331+
if (usersInVC == 1){
332+
if (tmpChannelList.contains(vc)){
333+
VoiceChannel master = tmpChannelMapMaster.get(vc);
334+
createTmpChannel(event.getGuild(), masterNames.get(master),tmpChannelCount.get(master)+1,vc.getPosition(),vc.getUserLimit(),master,vc.getParentCategory(),vc.getBitrate());
335+
tmpChannelCount.put(master,tmpChannelCount.get(master)+1);
336+
}else if (tmpMasterChannelList.contains(vc) && tmpChannelCount.get(vc) == 0){
337+
createTmpChannel(event.getGuild(), vc.getName(),1,vc.getPosition(),vc.getUserLimit(),vc,vc.getParentCategory(),vc.getBitrate());
338+
tmpChannelCount.put(vc,1);
339+
}
328340
}
329341
}
330342
}
331343

332-
public void handleLeft(GenericGuildVoiceUpdateEvent event){
333-
VoiceChannel vc = event.getChannelLeft();
334-
int usersInVC = vc.getMembers().size();
335-
if (vc.getMembers().size() <= 0){
336-
if (tmpChannelList.contains(vc)){
337-
VoiceChannel master = tmpChannelMapMaster.get(vc);
338-
int count = tmpChannelCount.get(master);
339-
count--;
340-
String name = vc.getName();
341-
int pos = Integer.parseInt(name.split(";")[1]);
342-
if (count <= 0){
343-
if (!isSomeoneInChannel(master)){
344+
public void handleLeft(GuildVoiceUpdateEvent event){
345+
if (event.getChannelLeft() != null){
346+
VoiceChannel vc = event.getChannelLeft().asVoiceChannel();
347+
int usersInVC = vc.getMembers().size();
348+
if (vc.getMembers().size() <= 0){
349+
if (tmpChannelList.contains(vc)){
350+
VoiceChannel master = tmpChannelMapMaster.get(vc);
351+
int count = tmpChannelCount.get(master);
352+
count--;
353+
String name = vc.getName();
354+
int pos = Integer.parseInt(name.split(";")[1]);
355+
if (count <= 0){
356+
if (!isSomeoneInChannel(master)){
357+
deleteChannel(vc);
358+
tmpChannelCount.put(master, 0);
359+
}
360+
}else if(pos <= count){
344361
deleteChannel(vc);
345-
tmpChannelCount.put(master, 0);
346-
}
347-
}else if(pos <= count){
348-
deleteChannel(vc);
349-
tmpChannelCount.put(master, count);
350-
List<VoiceChannel> tmpChannelListClone = new ArrayList<>(tmpChannelList);;
351-
for (VoiceChannel vcTmp : tmpChannelListClone){
352-
if (tmpChannelMapMaster.get(vcTmp) == master){
353-
if (count == 1 && !isSomeoneInChannel(master)){
354-
tmpChannelCount.put(master, 0);
355-
deleteChannel(vcTmp);
356-
}else {
357-
int tmppos = Integer.parseInt(vcTmp.getName().split(";")[1]);
358-
tmppos--;
359-
vcTmp.getManager().setName("⏰;"+tmppos+";"+masterNames.get(master)).queue();
362+
tmpChannelCount.put(master, count);
363+
List<VoiceChannel> tmpChannelListClone = new ArrayList<>(tmpChannelList);;
364+
for (VoiceChannel vcTmp : tmpChannelListClone){
365+
if (tmpChannelMapMaster.get(vcTmp) == master){
366+
if (count == 1 && !isSomeoneInChannel(master)){
367+
tmpChannelCount.put(master, 0);
368+
deleteChannel(vcTmp);
369+
}else {
370+
int tmppos = Integer.parseInt(vcTmp.getName().split(";")[1]);
371+
tmppos--;
372+
vcTmp.getManager().setName("⏰;"+tmppos+";"+masterNames.get(master)).queue();
373+
}
360374
}
361375
}
362376
}
363-
}
364-
}else if(tmpMasterChannelList.contains(vc) && tmpChannelCount.get(vc) <= 1){
365-
List<VoiceChannel> tmpChannelListClone = new ArrayList<>(tmpChannelList);
366-
for (VoiceChannel vc2 : tmpChannelListClone){
367-
if (tmpChannelMapMaster.get(vc2) == vc){
368-
deleteChannel(vc2);
369-
tmpChannelCount.put(vc, 0);
377+
}else if(tmpMasterChannelList.contains(vc) && tmpChannelCount.get(vc) <= 1){
378+
List<VoiceChannel> tmpChannelListClone = new ArrayList<>(tmpChannelList);
379+
for (VoiceChannel vc2 : tmpChannelListClone){
380+
if (tmpChannelMapMaster.get(vc2) == vc){
381+
deleteChannel(vc2);
382+
tmpChannelCount.put(vc, 0);
383+
}
370384
}
371385
}
372386
}
@@ -405,7 +419,7 @@ public void deleteAllTmpChannels(Guild guild){
405419
public void checkMasterChannels(){
406420
for (VoiceChannel vc : tmpMasterChannelList){
407421
if (vc.getMembers().size() > 0){
408-
createTmpChannel(vc.getGuild(), vc.getName(),1,vc.getPosition(),vc.getUserLimit(),vc,vc.getParent(),vc.getBitrate());
422+
createTmpChannel(vc.getGuild(), vc.getName(),1,vc.getPosition(),vc.getUserLimit(),vc,vc.getParentCategory(),vc.getBitrate());
409423
tmpChannelCount.put(vc,1);
410424
}
411425
}

src/main/java/StartBot.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public static void main(String[] args) throws Exception{
2727
GatewayIntent.DIRECT_MESSAGES,
2828
GatewayIntent.GUILD_PRESENCES,
2929
GatewayIntent.GUILD_VOICE_STATES,
30-
GatewayIntent.GUILD_EMOJIS,
30+
GatewayIntent.GUILD_EMOJIS_AND_STICKERS,
31+
GatewayIntent.MESSAGE_CONTENT,
3132
GatewayIntent.GUILD_MEMBERS)
3233
.setMemberCachePolicy(MemberCachePolicy.ALL)
3334
.build()

0 commit comments

Comments
 (0)