change: reformat code because i messed up first time

This commit is contained in:
ZtereoHYPE 2022-02-04 14:30:37 +01:00
parent 41438cae0d
commit 735d4bc193
13 changed files with 130 additions and 130 deletions

View file

@ -56,9 +56,9 @@ public class ZtereoMUSIC {
ztereoMUSIC.setConfig(Config.loadFrom("./config.json5"));
ztereoMUSIC.setJda(JDABuilder.createDefault(ztereoMUSIC.getConfig().getPropreties().get("token"), intents)
.enableCache(CacheFlag.VOICE_STATE)
.build()
.awaitReady());
.enableCache(CacheFlag.VOICE_STATE)
.build()
.awaitReady());
ztereoMUSIC.setupAudio();
ztereoMUSIC.setCommands();

View file

@ -32,7 +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();
.queue();
}
}

View file

@ -18,10 +18,10 @@ import java.util.ArrayList;
import java.util.List;
public class TrackManager extends AudioEventAdapter {
private final @Getter AudioPlayer player;
public final List<AudioTrack> trackQueue = new ArrayList<>();
private @Getter @Setter MessageChannel infoChannel;
private final @Getter AudioPlayer player;
private final Guild guild;
private @Getter @Setter MessageChannel infoChannel;
public TrackManager(AudioPlayerManager playerManager, MessageChannel infoChannel, Guild guild) {
this.player = playerManager.createPlayer();
@ -106,8 +106,8 @@ public class TrackManager extends AudioEventAdapter {
}
ZtereoMUSIC.getInstance()
.getPlayerManager()
.loadItem(identifier, new CustomAudioLoadResultHandler(this, infoChannel));
.getPlayerManager()
.loadItem(identifier, new CustomAudioLoadResultHandler(this, infoChannel));
}
}
@ -120,7 +120,8 @@ 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. Skpping...").queue();
"Uh oh, a track did something strange. Ask the owner to check for errors in console. Skpping...")
.queue();
System.out.println(exception.getCause().getMessage());
}

View file

@ -15,16 +15,16 @@ public class Clear implements Command {
public Clear() {
this.meta = CommandMeta.builder()
.name("clear")
.aliases(new String[] { "deleteall" })
.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 })
.build();
.name("clear")
.aliases(new String[] { "deleteall" })
.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 })
.build();
}
@Override public void execute(MessageReceivedEvent messageEvent, String[] args) {

View file

@ -12,15 +12,15 @@ public class Disconnect implements Command {
public Disconnect() {
this.meta = CommandMeta.builder()
.name("disconnect")
.description("A command to kick the bot from the vc.")
.aliases(new String[] { "fuckoff", "bye" })
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED,
VoiceChecks.USER_CONNECTED,
VoiceChecks.SAME_VC_IF_CONNECTED })
.build();
.name("disconnect")
.description("A command to kick the bot from the vc.")
.aliases(new String[] { "fuckoff", "bye" })
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED,
VoiceChecks.USER_CONNECTED,
VoiceChecks.SAME_VC_IF_CONNECTED })
.build();
}
@Override public CommandMeta getMeta() {

View file

@ -14,16 +14,16 @@ public class Pause implements Command {
public Pause() {
this.meta = CommandMeta.builder()
.name("pause")
.description("Pause the playing music")
.aliases(new String[] { "resume" })
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED,
VoiceChecks.BOT_PLAYING,
VoiceChecks.USER_CONNECTED,
VoiceChecks.SAME_VC_IF_CONNECTED })
.build();
.name("pause")
.description("Pause the playing music")
.aliases(new String[] { "resume" })
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED,
VoiceChecks.BOT_PLAYING,
VoiceChecks.USER_CONNECTED,
VoiceChecks.SAME_VC_IF_CONNECTED })
.build();
}
@Override public CommandMeta getMeta() {

View file

@ -10,13 +10,13 @@ public class Ping implements Command {
public Ping() {
this.meta = CommandMeta.builder()
.name("ping")
.description("A command to get pinged")
.aliases(new String[] { "pong", "pog" })
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[0])
.build();
.name("ping")
.description("A command to get pinged")
.aliases(new String[] { "pong", "pog" })
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[0])
.build();
}
@Override public CommandMeta getMeta() {
@ -24,7 +24,7 @@ public class Ping implements Command {
}
public void execute(MessageReceivedEvent messageEvent, String[] args) {
messageEvent.getMessage().reply("get ping'd lolmao").queue();
messageEvent.getMessage().reply("git ping'd lolmao").queue();
}
}

View file

@ -24,19 +24,19 @@ public class Play implements Command {
private static final Pattern URL_PATTERN = Pattern.compile("^(http|https)://([a-z]+\\.[a-z]+)+/\\S+$",
Pattern.CASE_INSENSITIVE);
private static final Pattern SPOTIFY_URL_PATTERN = Pattern.compile(
"^(?:https://open\\.spotify\\.com/(track|playlist)/)(\\S+(?:\\?si=\\S+))$");
"^(?:https://open\\.spotify\\.com/(track|playlist)/)(\\S+(?:\\?si=\\S+))$");
private final CommandMeta meta;
public Play() {
this.meta = CommandMeta.builder()
.name("play")
.description("Play music!")
.aliases(new String[] { "p" })
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[] { VoiceChecks.USER_CONNECTED, VoiceChecks.SAME_VC_IF_CONNECTED })
.build();
.name("play")
.description("Play music!")
.aliases(new String[] { "p" })
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[] { VoiceChecks.USER_CONNECTED, VoiceChecks.SAME_VC_IF_CONNECTED })
.build();
}
@Override public CommandMeta getMeta() {
@ -56,7 +56,8 @@ public class Play implements Command {
if (trackManager == null || !trackManager.getPlayer().isPaused()) {
messageChannel.sendMessage(
"What should I play? Type the name of the song after the command or use a YouTube link!").queue();
"What should I play? Type the name of the song after the command or use a YouTube link!")
.queue();
return;
}
@ -99,7 +100,7 @@ public class Play implements Command {
TrackManager trackManager = TrackManagers.getOrCreateGuildTrackManager(guild, messageChannel, voiceChannel);
ZtereoMUSIC.getInstance()
.getPlayerManager()
.loadItem(identifier, new CustomAudioLoadResultHandler(trackManager, messageChannel));
.getPlayerManager()
.loadItem(identifier, new CustomAudioLoadResultHandler(trackManager, messageChannel));
}
}

View file

@ -19,15 +19,15 @@ public class Queue implements Command {
public Queue() {
this.meta = CommandMeta.builder()
.name("queue")
.description("See the queue")
.aliases(new String[] { "q" })
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED,
VoiceChecks.USER_CONNECTED,
VoiceChecks.SAME_VC_IF_CONNECTED })
.build();
.name("queue")
.description("See the queue")
.aliases(new String[] { "q" })
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED,
VoiceChecks.USER_CONNECTED,
VoiceChecks.SAME_VC_IF_CONNECTED })
.build();
}
@Override public CommandMeta getMeta() {
@ -37,7 +37,7 @@ public class Queue implements Command {
public void execute(MessageReceivedEvent messageEvent, String[] args) {
Guild guild = messageEvent.getGuild();
VoiceChannel voiceChannel = Objects.requireNonNull(Objects.requireNonNull(messageEvent.getMember())
.getVoiceState()).getChannel();
.getVoiceState()).getChannel();
MessageChannel messageChannel = messageEvent.getChannel();
TrackManager trackManager = TrackManagers.getOrCreateGuildTrackManager(guild, messageChannel, voiceChannel);

View file

@ -19,16 +19,28 @@ public class Remove implements Command {
public Remove() {
this.meta = CommandMeta.builder()
.name("remove")
.aliases(new String[] { "delete" })
.description("Remove the chosen item.")
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED,
VoiceChecks.BOT_PLAYING,
VoiceChecks.USER_CONNECTED,
VoiceChecks.SAME_VC_IF_CONNECTED })
.build();
.name("remove")
.aliases(new String[] { "delete" })
.description("Remove the chosen item.")
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED,
VoiceChecks.BOT_PLAYING,
VoiceChecks.USER_CONNECTED,
VoiceChecks.SAME_VC_IF_CONNECTED })
.build();
}
public static boolean isNumeric(String strNum) {
if (strNum == null) {
return false;
}
try {
int i = Integer.parseInt(strNum);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
@Override public void execute(MessageReceivedEvent messageEvent, String[] args) {
@ -38,8 +50,8 @@ public class Remove implements Command {
// if there's the wrong amount of arguments send the usage
if (args.length != 1) {
messageChannel.sendMessage(
"Usage: `remove [index of song to remove]/first/last`. Use the `queue` command to find the index.")
.queue();
"Usage: `remove [index of song to remove]/first/last`. Use the `queue` command to find the index.")
.queue();
return;
}
@ -65,8 +77,8 @@ public class Remove implements Command {
parsedIndex = indexAliases.get(index);
} else {
messageChannel.sendMessage(
"Usage: `remove [index of song to remove]/first/last`. Use the `queue` command to find the index.")
.queue();
"Usage: `remove [index of song to remove]/first/last`. Use the `queue` command to find the index.")
.queue();
return;
}
@ -78,16 +90,4 @@ public class Remove implements Command {
String title = trackManager.removeQueueItem(parsedIndex - 1);
messageChannel.sendMessage("Removed " + title).queue();
}
public static boolean isNumeric(String strNum) {
if (strNum == null) {
return false;
}
try {
int i = Integer.parseInt(strNum);
} catch (NumberFormatException nfe) {
return false;
}
return true;
}
}

View file

@ -15,16 +15,16 @@ public class Skip implements Command {
public Skip() {
this.meta = CommandMeta.builder()
.name("skip")
.description("Skip the current track!")
.aliases(new String[] { "next" })
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED,
VoiceChecks.BOT_PLAYING,
VoiceChecks.USER_CONNECTED,
VoiceChecks.SAME_VC_IF_CONNECTED })
.build();
.name("skip")
.description("Skip the current track!")
.aliases(new String[] { "next" })
.isNsfw(false)
.isHidden(false)
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED,
VoiceChecks.BOT_PLAYING,
VoiceChecks.USER_CONNECTED,
VoiceChecks.SAME_VC_IF_CONNECTED })
.build();
}
@Override public CommandMeta getMeta() {

View file

@ -49,9 +49,9 @@ public class CommandListener extends ListenerAdapter {
// check if the command is allowed and stop at first failure (order is important)
for (VoiceChecks checkEnum : command.getMeta().getChecks()) {
if (!checkEnum.getCheck()
.getResult(message.getMember(),
guild.getAudioManager().getConnectedChannel(),
TrackManagers.getGuildTrackManager(guild, messageChannel))) {
.getResult(message.getMember(),
guild.getAudioManager().getConnectedChannel(),
TrackManagers.getGuildTrackManager(guild, messageChannel))) {
message.reply(checkEnum.getCheck().getErrorCode()).queue();
return;
}
@ -63,9 +63,9 @@ public class CommandListener extends ListenerAdapter {
} catch (Exception e) {
//todo: nicer embed with error pls
message.getChannel()
.sendMessage(
"uh oh something really bad happened and yeah so yeah everything is aborted and cancelled i give up this is too hard kthxbye")
.queue();
.sendMessage(
"uh oh something really bad happened and yeah so yeah everything is aborted and cancelled i give up this is too hard kthxbye")
.queue();
throw e;
}
}

View file

@ -21,19 +21,17 @@ import java.util.regex.Pattern;
public class SpotifyApiHelper {
private static final String CLIENT_ID = ZtereoMUSIC.getInstance()
.getConfig()
.getPropreties()
.get("spotify_client_id");
.getConfig()
.getPropreties()
.get("spotify_client_id");
private static final String CLIENT_SECRET = ZtereoMUSIC.getInstance()
.getConfig()
.getPropreties()
.get("spotify_client_secret");
.getConfig()
.getPropreties()
.get("spotify_client_secret");
private static final Pattern IDENTIFIER_PATTERN = Pattern.compile(
"(?:(?<=https://open\\.spotify\\.com/track/)|(?<=https://open\\.spotify\\.com/playlist/))(\\S+(?=\\?si=\\S))");
private static String spotifyToken;
"(?:(?<=https://open\\.spotify\\.com/track/)|(?<=https://open\\.spotify\\.com/playlist/))(\\S+(?=\\?si=\\S))");
private static final Json JSON = Json.json();
private static String spotifyToken;
public static void startTokenTimer() {
Timer timer = new Timer();
@ -55,13 +53,13 @@ public class SpotifyApiHelper {
@SneakyThrows private static Optional<String> getToken() {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(
"https://accounts.spotify.com/api/token?grant_type=client_credentials"))
.POST(HttpRequest.BodyPublishers.ofString(""))
.header("Authorization",
"Basic " + Base64.getEncoder()
.encodeToString((CLIENT_ID + ":" + CLIENT_SECRET).getBytes(StandardCharsets.UTF_8.toString())))
.header("Content-Type", "application/x-www-form-urlencoded")
.build();
"https://accounts.spotify.com/api/token?grant_type=client_credentials"))
.POST(HttpRequest.BodyPublishers.ofString(""))
.header("Authorization",
"Basic " + Base64.getEncoder()
.encodeToString((CLIENT_ID + ":" + CLIENT_SECRET).getBytes(StandardCharsets.UTF_8.toString())))
.header("Content-Type", "application/x-www-form-urlencoded")
.build();
JsonPath tokenPath = JsonPath.parse("access_token");
try {
@ -98,10 +96,10 @@ public class SpotifyApiHelper {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create(query))
.GET()
.header("Authorization", "Bearer " + spotifyToken)
.header("Content-Type", "application/json")
.build();
.GET()
.header("Authorization", "Bearer " + spotifyToken)
.header("Content-Type", "application/json")
.build();
JsonPath titlePath = JsonPath.parse("tracks[0].name");
// JsonPath authorPath = JsonPath.parse("tracks[0].artists[0].name");