Skip to content

Commit

Permalink
Merge pull request #6 from Tzesh/onVoiceChannelLeaveDisconnectBug
Browse files Browse the repository at this point in the history
On voice channel leave disconnect bug
  • Loading branch information
Tzesh authored Apr 5, 2023
2 parents f5ee066 + a635507 commit 4238ec0
Show file tree
Hide file tree
Showing 22 changed files with 61 additions and 65 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ dependencies {

compileJava.options.encoding = 'UTF-8'
mainClassName = 'com.tzesh.tzebot.Main'
version '3.01'
version '3.02'
4 changes: 1 addition & 3 deletions src/main/java/com/tzesh/tzebot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

import com.tzesh.tzebot.gui.TzeGUI;

import javax.security.auth.login.LoginException;

public class Main {

public static void main(String[] args) {
new TzeGUI().start(); // All the functions and required things will be called and operated in TzeGUI.java
new TzeGUI().start(); // All the functions and required things will be called and operated in TzeGUI.java
}
}
6 changes: 0 additions & 6 deletions src/main/java/com/tzesh/tzebot/commands/Help.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.tzesh.tzebot.commands;

import com.tzesh.tzebot.essentials.CommandContext;
import com.tzesh.tzebot.essentials.CommandManager;
import com.tzesh.tzebot.essentials.Config;
import com.tzesh.tzebot.essentials.ICommand;
import com.tzesh.tzebot.essentials.*;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
Expand All @@ -12,8 +8,6 @@
import java.time.Instant;
import java.util.List;

import static com.tzesh.tzebot.essentials.LanguageManager.getMessage;

public class Help implements ICommand {

private final CommandManager manager;
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/tzesh/tzebot/commands/moderation/Ban.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import java.util.List;
import java.util.concurrent.TimeUnit;

import static com.tzesh.tzebot.essentials.LanguageManager.getMessage;

public class Ban implements ICommand {

@Override
Expand Down Expand Up @@ -72,7 +70,7 @@ public void handle(CommandContext ctx) {
return;
}

String reason = message.replace(banRequested.toString() + " ", "");
String reason = message.replace(banRequested + " ", "");

if (args.size() != 1) banRequested.ban(1, TimeUnit.DAYS)
.reason(String.format(LanguageManager.getMessage("ban.banned.with"), member, reason)).queue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void handle(CommandContext ctx) {

} else {
if (Config.LANGUAGES.get(ctx.getGuild().getIdLong()).equals("en_en")) {
if (args.get(0).toLowerCase().equals("turkish")) {
if (args.get(0).equalsIgnoreCase("turkish")) {
Config.LANGUAGES.put(ctx.getGuild().getIdLong(), "tr_tr");
EmbedBuilder success = new EmbedBuilder();
success.setColor(0x00ff00);
Expand All @@ -60,7 +60,7 @@ public void handle(CommandContext ctx) {
channel.sendMessage(MessageCreateData.fromEmbeds(success.build())).queue();
return;
}
if (args.get(0).toLowerCase().equals("english")) {
if (args.get(0).equalsIgnoreCase("english")) {
EmbedBuilder error = new EmbedBuilder();
error.setColor(0xff3923);
error.setTitle(LanguageManager.getMessage("general.icon.error", guildID) + LanguageManager.getMessage("language.already.setTitle", guildID));
Expand Down Expand Up @@ -92,7 +92,7 @@ public void handle(CommandContext ctx) {
channel.sendMessage(MessageCreateData.fromEmbeds(success.build())).queue();
return;
}
if (LanguageManager.normalizer(args.get(0)).toLowerCase().equals("turkce")) {
if (LanguageManager.normalizer(args.get(0)).equalsIgnoreCase("turkce")) {
EmbedBuilder error = new EmbedBuilder();
error.setColor(0xff3923);
error.setTitle(LanguageManager.getMessage("general.icon.error", guildID) + LanguageManager.getMessage("language.already.setTitle", guildID));
Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/tzesh/tzebot/commands/music/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.HashMap;
import java.util.List;

import static com.tzesh.tzebot.essentials.LanguageManager.getMessage;
import static com.tzesh.tzebot.utils.Controller.isExists;


Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/tzesh/tzebot/commands/music/Join.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.tzesh.tzebot.music.PlayerManager;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.*;

import net.dv8tion.jda.api.entities.GuildVoiceState;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.managers.AudioManager;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tzesh/tzebot/commands/music/Leave.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.tzesh.tzebot.commands.music;

import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.tzesh.tzebot.essentials.CommandContext;
import com.tzesh.tzebot.essentials.ICommand;
import com.tzesh.tzebot.music.GuildMusicManager;
import com.tzesh.tzebot.music.PlayerManager;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tzesh/tzebot/commands/music/Loop.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void handle(CommandContext ctx) {

channel.sendMessage(MessageCreateData.fromEmbeds(error.build())).queue();
} else {
if (scheduler.isRepeating() == false) {
if (!scheduler.isRepeating()) {
scheduler.setRepeating(!scheduler.isRepeating());

EmbedBuilder success = new EmbedBuilder();
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/tzesh/tzebot/commands/music/NowPlaying.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.tzesh.tzebot.commands.music;

import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import com.tzesh.tzebot.essentials.CommandContext;
import com.tzesh.tzebot.essentials.ICommand;
import com.tzesh.tzebot.music.GuildMusicManager;
import com.tzesh.tzebot.music.PlayerManager;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tzesh/tzebot/commands/music/Pause.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.tzesh.tzebot.commands.music;

import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.tzesh.tzebot.essentials.CommandContext;
import com.tzesh.tzebot.essentials.ICommand;
import com.tzesh.tzebot.music.GuildMusicManager;
import com.tzesh.tzebot.music.PlayerManager;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/com/tzesh/tzebot/commands/music/Play.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package com.tzesh.tzebot.commands.music;

import com.tzesh.tzebot.essentials.CommandContext;
import com.tzesh.tzebot.essentials.Config;
import com.tzesh.tzebot.essentials.ICommand;
import com.tzesh.tzebot.music.GuildMusicManager;
import com.tzesh.tzebot.music.PlayerManager;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.youtube.YouTube;
import com.google.api.services.youtube.model.SearchResult;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import com.tzesh.tzebot.essentials.CommandContext;
import com.tzesh.tzebot.essentials.Config;
import com.tzesh.tzebot.essentials.ICommand;
import com.tzesh.tzebot.music.GuildMusicManager;
import com.tzesh.tzebot.music.PlayerManager;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.GuildVoiceState;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.managers.AudioManager;
Expand Down Expand Up @@ -183,7 +184,7 @@ public void handle(CommandContext ctx) {
return;
}

if (!selfmember.hasPermission(voiceChannel, Permission.VOICE_CONNECT) || !selfmember.hasPermission(voiceChannel, Permission.VOICE_SPEAK)) {
if (voiceChannel == null || !selfmember.hasPermission(voiceChannel, Permission.VOICE_CONNECT) || !selfmember.hasPermission(voiceChannel, Permission.VOICE_SPEAK)) {
EmbedBuilder error = new EmbedBuilder();
error.setColor(0xff3923);
error.setTitle(getMessage("general.icon.error", guildID) + getMessage("join.cannotjoin.setTitle", guildID));
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/tzesh/tzebot/commands/music/Queue.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.tzesh.tzebot.commands.music;

import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import com.tzesh.tzebot.essentials.CommandContext;
import com.tzesh.tzebot.essentials.ICommand;
import com.tzesh.tzebot.music.GuildMusicManager;
import com.tzesh.tzebot.music.PlayerManager;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tzesh/tzebot/commands/music/Resume.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.tzesh.tzebot.commands.music;

import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.tzesh.tzebot.essentials.CommandContext;
import com.tzesh.tzebot.essentials.ICommand;
import com.tzesh.tzebot.music.GuildMusicManager;
import com.tzesh.tzebot.music.PlayerManager;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tzesh/tzebot/commands/music/Seek.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.tzesh.tzebot.commands.music;

import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.tzesh.tzebot.essentials.CommandContext;
import com.tzesh.tzebot.essentials.Config;
import com.tzesh.tzebot.essentials.ICommand;
import com.tzesh.tzebot.essentials.LanguageManager;
import com.tzesh.tzebot.music.GuildMusicManager;
import com.tzesh.tzebot.music.PlayerManager;
import com.tzesh.tzebot.music.TrackScheduler;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.emoji.Emoji;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tzesh/tzebot/commands/music/Skip.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.tzesh.tzebot.commands.music;

import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.tzesh.tzebot.essentials.CommandContext;
import com.tzesh.tzebot.essentials.ICommand;
import com.tzesh.tzebot.music.GuildMusicManager;
import com.tzesh.tzebot.music.PlayerManager;
import com.tzesh.tzebot.music.TrackScheduler;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.utils.messages.MessageCreateData;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tzesh/tzebot/essentials/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Config {
public static Map<Long, HashMap<Long, Long>> MUSICCHANNELS = new HashMap<>(); // Music channels that are created and initialized.
public static Map<Long, Integer> VOLUMES = new HashMap<>(); // Volumes of the servers default is 50%
public static Map<Long, Long> CHANNELCREATED = new HashMap<>(); // Music channels that are created but either initialized or not. It's important value for preventing some kind of abusing of channel creation.
public static double currentVersion = 3.01; // Check if there's an update or not.
public static double currentVersion = 3.02; // Check if there's an update or not.
public static String downloadURL = ""; // to download the latest release

public static String get(String key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ public static void getMessages() {

if (jsonString.isBlank() || jsonString.isEmpty()) getMessagesFromRepository();
else {
TypeToken<Map<String, Map<String, String>>> map = new TypeToken<>(){};
TypeToken<Map<String, Map<String, String>>> map = new TypeToken<>() {
};
localizer = gson.fromJson(jsonString, map.getType());
System.out.println("All messages are loaded from 'localizer.json'. Supported languages are 'English' and 'Turkish'.");
}
Expand All @@ -63,8 +64,7 @@ public static String getMessage(String key, long guildID) {
String shortening = Config.LANGUAGES.computeIfAbsent(guildID, (id) -> "en_en");
if (shortening.equals("en_en")) {
return localizer.get(key).get("en_en");
}
else if (shortening.equals("tr_tr")) {
} else if (shortening.equals("tr_tr")) {
return localizer.get(key).get("tr_tr");
} else {
return "Error_Message_Not_Found";
Expand Down
18 changes: 12 additions & 6 deletions src/main/java/com/tzesh/tzebot/essentials/Listener.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package com.tzesh.tzebot.essentials;

import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.tzesh.tzebot.moderation.VoteRole;
import com.tzesh.tzebot.music.GuildMusicManager;
import com.tzesh.tzebot.music.MusicChannel;
import com.tzesh.tzebot.music.PlayerManager;
import com.tzesh.tzebot.utils.EmojiUnicodes;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.tzesh.tzebot.moderation.VoteRole;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.MessageEmbed;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.events.Event;
Expand All @@ -20,7 +22,7 @@
import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent;
import net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent;
import net.dv8tion.jda.api.events.session.ReadyEvent;
import net.dv8tion.jda.api.events.thread.member.ThreadMemberLeaveEvent;
import net.dv8tion.jda.api.events.session.SessionDisconnectEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import net.dv8tion.jda.api.managers.AudioManager;
import net.dv8tion.jda.api.utils.messages.MessageEditData;
Expand Down Expand Up @@ -149,9 +151,13 @@ public void onMessageReactionRemove(@NotNull MessageReactionRemoveEvent event) {
}
}

@Override
public void onSessionDisconnect(@NotNull SessionDisconnectEvent event) {
}

@Override
public void onGuildVoiceUpdate(@NotNull GuildVoiceUpdateEvent event) {
checkMembersAndLeave(event.getGuild(), event.getChannelJoined(), event);
checkMembersAndLeave(event.getGuild(), event.getChannelLeft(), event);
}

private void checkMembersAndLeave(Guild guild, AudioChannel channelLeft, @Nonnull Event event) {
Expand All @@ -160,7 +166,7 @@ private void checkMembersAndLeave(Guild guild, AudioChannel channelLeft, @Nonnul
final GuildMusicManager musicManager = playerManager.getGuildMusicManager(guild);
final AudioPlayer player = musicManager.player;
if (!audioManager.isConnected()) return;
if (audioManager.getConnectedChannel() == channelLeft && channelLeft.getMembers().size() == 1) {
if (audioManager.getConnectedChannel() == channelLeft && channelLeft.getMembers().size() == 1 || (!channelLeft.getMembers().contains(channelLeft.getGuild().getSelfMember()))) {
if (player.getPlayingTrack() != null) {
musicManager.scheduler.getQueue().clear();
musicManager.player.stopTrack();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tzesh/tzebot/gui/TzeGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void keyTyped(KeyEvent e) {

public void checkVersion() {
versionNumber.setText("v" + Config.currentVersion);
if (Config.versionControl() == true) {
if (Config.versionControl()) {
System.out.println("You are using the latest version of TzeBot v" + Config.currentVersion);
} else {
updateButton.setVisible(true);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/tzesh/tzebot/music/MusicChannel.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.tzesh.tzebot.music;

import com.tzesh.tzebot.essentials.Config;
import com.tzesh.tzebot.utils.EmojiUnicodes;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.track.AudioTrack;
import com.sedmelluq.discord.lavaplayer.track.AudioTrackInfo;
import com.tzesh.tzebot.essentials.Config;
import com.tzesh.tzebot.utils.EmojiUnicodes;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.GuildVoiceState;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/com/tzesh/tzebot/utils/EmojiUnicodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
import net.dv8tion.jda.api.entities.emoji.UnicodeEmoji;

public enum EmojiUnicodes {
nowPlaying ("U+23EF"),
stop ("U+23F9"),
skip ("U+23ED"),
loop ("U+1F501"),
shuffle ("U+1F500"),
next ("U+21AA"),
previous ("U+21A9"),
volumedown ("U+1F509"),
volumeup ("U+1F50A"),
queue ("U+1F4DC");
nowPlaying("U+23EF"),
stop("U+23F9"),
skip("U+23ED"),
loop("U+1F501"),
shuffle("U+1F500"),
next("U+21AA"),
previous("U+21A9"),
volumedown("U+1F509"),
volumeup("U+1F50A"),
queue("U+1F4DC");

private final String unicode;

private EmojiUnicodes(String unicode) {
this.unicode = unicode;
}
EmojiUnicodes(String unicode) {
this.unicode = unicode;
}

public UnicodeEmoji getUnicode() {
return Emoji.fromUnicode(unicode);
}
public UnicodeEmoji getUnicode() {
return Emoji.fromUnicode(unicode);
}

}

0 comments on commit 4238ec0

Please sign in to comment.