mirror of
https://github.com/JonasunderscoreJones/ZtereoMUSIC.git
synced 2025-10-25 13:39:19 +02:00
change: clean up code and fix a few issues
This commit is contained in:
parent
4b9b92d54b
commit
2bbc6b9f1d
8 changed files with 32 additions and 25 deletions
|
|
@ -52,7 +52,7 @@ public class ZtereoMUSIC {
|
|||
EnumSet<GatewayIntent> intents = EnumSet.of(GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.GUILD_EMOJIS);
|
||||
|
||||
ztereoMUSIC.setConfig(Config.loadFrom("./config.json5"));
|
||||
ztereoMUSIC.setJda(JDABuilder.createDefault(ztereoMUSIC.getConfig().getPropreties().get("token"), intents)
|
||||
ztereoMUSIC.setJda(JDABuilder.createDefault(ztereoMUSIC.getConfig().getPropreties().getProperty("token"), intents)
|
||||
.enableCache(CacheFlag.VOICE_STATE)
|
||||
.build()
|
||||
.awaitReady());
|
||||
|
|
@ -92,7 +92,7 @@ public class ZtereoMUSIC {
|
|||
|
||||
for (String commandName : this.getCommandMap().keySet()) {
|
||||
for (String aliasName : this.getCommandMap().get(commandName).getMeta().getAliases()) {
|
||||
System.out.println("Loaded alias \"" + aliasName + "\" for command: " + commandName);
|
||||
// System.out.println("Loaded alias \"" + aliasName + "\" for command: " + commandName);
|
||||
this.getCommandAliases().put(aliasName, commandName);
|
||||
}
|
||||
}
|
||||
|
|
@ -103,10 +103,12 @@ public class ZtereoMUSIC {
|
|||
AudioSourceManagers.registerRemoteSources(this.getPlayerManager());
|
||||
AudioSourceManagers.registerLocalSource(this.getPlayerManager());
|
||||
SpotifyApiHelper.startTokenTimer();
|
||||
System.out.println("started audio");
|
||||
}
|
||||
|
||||
private void setListeners() {
|
||||
this.getJda().addEventListener(new CommandListener());
|
||||
this.getJda().addEventListener(new AloneDisconnectListener());
|
||||
System.out.println("started listeners");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,8 +22,9 @@ public class CustomAudioLoadResultHandler implements AudioLoadResultHandler {
|
|||
|
||||
@Override public void playlistLoaded(AudioPlaylist playlist) {
|
||||
for (AudioTrack track : playlist.getTracks()) {
|
||||
this.trackManager.queue(track);
|
||||
this.trackManager.getTrackQueue().add(track);
|
||||
}
|
||||
this.messageChannel.sendMessage("Queued " + playlist.getTracks().size() + " songs from: " + playlist.getName()).queue();
|
||||
}
|
||||
|
||||
@Override public void noMatches() {
|
||||
|
|
@ -31,8 +32,7 @@ public class CustomAudioLoadResultHandler implements AudioLoadResultHandler {
|
|||
}
|
||||
|
||||
@Override public void loadFailed(FriendlyException throwable) {
|
||||
this.messageChannel.sendMessage("Failed loading that audio. Try with a different source (eg. YouTube URL)")
|
||||
.queue();
|
||||
this.messageChannel.sendMessage("Failed loading that audio. Try with a different source (eg. YouTube URL)").queue();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,11 +17,14 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class TrackManager extends AudioEventAdapter {
|
||||
public final List<AudioTrack> trackQueue = new ArrayList<>();
|
||||
private final @Getter AudioPlayer player;
|
||||
private final @Getter
|
||||
List<AudioTrack> trackQueue = new ArrayList<>();
|
||||
private final @Getter
|
||||
AudioPlayer player;
|
||||
private String hasRetriedId;
|
||||
private @Getter
|
||||
@Setter MessageChannel infoChannel;
|
||||
@Setter
|
||||
MessageChannel infoChannel;
|
||||
|
||||
public TrackManager(AudioPlayerManager playerManager, MessageChannel infoChannel) {
|
||||
this.player = playerManager.createPlayer();
|
||||
|
|
@ -90,6 +93,7 @@ public class TrackManager extends AudioEventAdapter {
|
|||
case FINISHED -> playNext();
|
||||
|
||||
case LOAD_FAILED -> {
|
||||
System.out.println("tracc failed");
|
||||
String identifier;
|
||||
String trackTitle = track.getInfo().title;
|
||||
|
||||
|
|
@ -118,7 +122,7 @@ public class TrackManager extends AudioEventAdapter {
|
|||
|
||||
@Override public void onTrackException(AudioPlayer player, AudioTrack track, FriendlyException exception) {
|
||||
// infoChannel.sendMessage("Uh oh, a track did something strange. Ask the owner to check for errors in console. ").queue();
|
||||
// System.out.println(exception.getCause().getMessage());
|
||||
System.out.println(exception.getCause().getMessage());
|
||||
onTrackEnd(player, track, AudioTrackEndReason.LOAD_FAILED);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ import net.dv8tion.jda.api.entities.MessageChannel;
|
|||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||
|
||||
public class Clear implements Command {
|
||||
private @Getter final CommandMeta meta;
|
||||
private @Getter
|
||||
final CommandMeta meta;
|
||||
|
||||
public Clear() {
|
||||
this.meta = CommandMeta.builder()
|
||||
|
|
@ -20,10 +21,7 @@ public class Clear implements Command {
|
|||
.description("Clears the queue and stops playing.")
|
||||
.isNsfw(false)
|
||||
.isHidden(false)
|
||||
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED,
|
||||
VoiceChecks.BOT_PLAYING,
|
||||
VoiceChecks.USER_CONNECTED,
|
||||
VoiceChecks.SAME_VC_IF_CONNECTED })
|
||||
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED, VoiceChecks.BOT_PLAYING, VoiceChecks.USER_CONNECTED, VoiceChecks.SAME_VC_IF_CONNECTED })
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -34,7 +32,7 @@ public class Clear implements Command {
|
|||
|
||||
assert trackManager != null; // the command will not execute if it is anyway because of our VoiceChecks (BOT_PLAYING)
|
||||
|
||||
int tracksLeft = trackManager.trackQueue.size();
|
||||
int tracksLeft = trackManager.getTrackQueue().size();
|
||||
for (int i = 0; i < tracksLeft; i++) {
|
||||
trackManager.removeQueueItem(0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ import java.util.Locale;
|
|||
import java.util.Map;
|
||||
|
||||
public class Remove implements Command {
|
||||
private @Getter final CommandMeta meta;
|
||||
private @Getter
|
||||
final CommandMeta meta;
|
||||
|
||||
public Remove() {
|
||||
this.meta = CommandMeta.builder()
|
||||
|
|
@ -53,13 +54,13 @@ public class Remove implements Command {
|
|||
TrackManager trackManager = TrackManagers.getGuildTrackManager(guild, messageChannel);
|
||||
assert trackManager != null; // the command will not execute if it is anyway because of our VoiceChecks (BOT_PLAYING)
|
||||
|
||||
if (trackManager.trackQueue.size() == 0) {
|
||||
if (trackManager.getTrackQueue().size() == 0) {
|
||||
messageChannel.sendMessage("There are no songs in queue.").queue();
|
||||
}
|
||||
|
||||
Map<String, Integer> indexAliases = new HashMap<>();
|
||||
indexAliases.put("first", 1);
|
||||
indexAliases.put("last", trackManager.trackQueue.size());
|
||||
indexAliases.put("last", trackManager.getTrackQueue().size());
|
||||
|
||||
int parsedIndex;
|
||||
String index = args[0];
|
||||
|
|
@ -75,7 +76,7 @@ public class Remove implements Command {
|
|||
return;
|
||||
}
|
||||
|
||||
if (parsedIndex > trackManager.trackQueue.size() || parsedIndex < 1) {
|
||||
if (parsedIndex > trackManager.getTrackQueue().size() || parsedIndex < 1) {
|
||||
messageChannel.sendMessage("That index is out of bounds.").queue();
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,22 +6,24 @@ import net.shadew.json.JsonNode;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
public class Config {
|
||||
private final static Json json5 = Json.json5();
|
||||
private @Getter final Map<String, String> propreties = new HashMap<>();
|
||||
private @Getter
|
||||
final Properties propreties = new Properties();
|
||||
private String path;
|
||||
|
||||
public static Config loadFrom(String path) throws IOException {
|
||||
Config config = new Config();
|
||||
|
||||
System.out.println("Working Directory = " + System.getProperty("user.dir"));
|
||||
|
||||
JsonNode tree = json5.parse(new File(path));
|
||||
config.path = path;
|
||||
|
||||
for (String key : tree.keySet()) {
|
||||
config.getPropreties().put(key, tree.get(key).asString());
|
||||
config.getPropreties().setProperty(key, tree.get(key).asString());
|
||||
}
|
||||
|
||||
return config;
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import java.util.Map;
|
|||
|
||||
public class CommandListener extends ListenerAdapter {
|
||||
// TODO: load prefix from a database on a per-server basis
|
||||
private static final String PREFIX = ZtereoMUSIC.getInstance().getConfig().getPropreties().get("prefix");
|
||||
private static final String PREFIX = ZtereoMUSIC.getInstance().getConfig().getPropreties().getProperty("prefix");
|
||||
private static final Map<String, Command> COMMAND_MAP = ZtereoMUSIC.getInstance().getCommandMap();
|
||||
private static final Map<String, String> COMMAND_ALIASES = ZtereoMUSIC.getInstance().getCommandAliases();
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import java.io.IOException;
|
|||
import java.net.URL;
|
||||
|
||||
public class YoutubeSearch {
|
||||
private static final String API_KEY = ZtereoMUSIC.getInstance().getConfig().getPropreties().get("yt_api_key");
|
||||
private static final String API_KEY = ZtereoMUSIC.getInstance().getConfig().getPropreties().getProperty("yt_api_key");
|
||||
private static final Json JSON = Json.json();
|
||||
|
||||
public static Pair<Boolean, String> query(String title) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue