mirror of
https://github.com/JonasunderscoreJones/ZtereoMUSIC.git
synced 2025-10-24 13:09:18 +02:00
reformat: final reformat
This commit is contained in:
parent
099408f545
commit
e2b3c776e6
9 changed files with 47 additions and 61 deletions
23
README.md
23
README.md
|
|
@ -1,7 +1,9 @@
|
|||
# ZtereoMUSIC
|
||||
|
||||
### Is a discord music bot written in java using JDA. The name is prone to be changed in the future.
|
||||
|
||||
## How to use:
|
||||
|
||||
1. Run `./gradlew build` or your system's equivalent in this repo
|
||||
2. Move `ZtereoMUSIC-0.0.1-all.jar` in a directory of your choice
|
||||
3. Create a `config.json5` file with the following structure:
|
||||
|
|
@ -17,7 +19,9 @@
|
|||
4. Execute with your jvm of choice, requires java 16 for now.
|
||||
|
||||
## Roadmap:
|
||||
|
||||
### First alpha:
|
||||
|
||||
- [x] Play command with search on YouTube for title.
|
||||
- [x] Pause command
|
||||
- [x] Skip command
|
||||
|
|
@ -28,25 +32,28 @@
|
|||
- [x] Clean up todos and code!
|
||||
|
||||
### Second alpha:
|
||||
|
||||
- [ ] Fancy embeds for everything!
|
||||
- [x] VoiceChecks class to check for tunable micro-permissions (eg. if someone in a different channel calls the bot, don't connect)
|
||||
- [x] Various listeners if there's nobody in vc for a while or if it gets disconnected or if last disconnects (stop playin) (very important as cleanup doesnt always get called)
|
||||
- [x] Various listeners if there's nobody in vc for a while or if it gets disconnected or if last disconnects (stop playin) (very important
|
||||
as cleanup doesnt always get called)
|
||||
- [ ] Help command (on ping too)
|
||||
- [x] Spotify URLs/playlists support (search on YouTube)
|
||||
- [ ] When a track fails try to play it again and if that fails send the error message.
|
||||
- [x] When a track fails try to play it again and if that fails send the error message.
|
||||
|
||||
### Later:
|
||||
|
||||
- [ ] Toggleable permissions system based on DJ role and based on server
|
||||
- [ ] Per-server prefix with database
|
||||
- [ ] fast forward command
|
||||
- [ ] Ability to search the song name
|
||||
- [ ] Slash commands?
|
||||
- [ ] Slash commands?
|
||||
- [ ] Proper database for server preferences (prefix etc)
|
||||
- what if i made a command system
|
||||
kinda like method overloading
|
||||
that will execute different methods of the command depending on what and how many args are passed
|
||||
- what if i made a command system kinda like method overloading that will execute different methods of the command depending on what and how
|
||||
many args are passed
|
||||
- Other TBA...
|
||||
|
||||
## Thankies
|
||||
This wouldn't have been possible without the amazing folks behind [lavaplayer](https://github.com/sedmelluq/lavaplayer) and [JDA](https://github.com/DV8FromTheWorld/JDA).
|
||||
And without ReperakDev and FoxShadew. Thank you.
|
||||
|
||||
This wouldn't have been possible without the amazing folks behind [lavaplayer](https://github.com/sedmelluq/lavaplayer)
|
||||
and [JDA](https://github.com/DV8FromTheWorld/JDA). And without ReperakDev and FoxShadew. Thank you.
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,10 +21,8 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
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+))$");
|
||||
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+))$");
|
||||
|
||||
private final CommandMeta meta;
|
||||
|
||||
|
|
@ -55,9 +53,7 @@ public class Play implements Command {
|
|||
TrackManager trackManager = TrackManagers.getGuildTrackManager(guild, messageChannel);
|
||||
|
||||
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();
|
||||
messageChannel.sendMessage("What should I play? Type the name of the song after the command or use a YouTube link!").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -99,8 +95,6 @@ public class Play implements Command {
|
|||
|
||||
TrackManager trackManager = TrackManagers.getOrCreateGuildTrackManager(guild, messageChannel, voiceChannel);
|
||||
|
||||
ZtereoMUSIC.getInstance()
|
||||
.getPlayerManager()
|
||||
.loadItem(identifier, new CustomAudioLoadResultHandler(trackManager, messageChannel));
|
||||
ZtereoMUSIC.getInstance().getPlayerManager().loadItem(identifier, new CustomAudioLoadResultHandler(trackManager, messageChannel));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -24,10 +24,7 @@ public class Remove implements Command {
|
|||
.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 })
|
||||
.checks(new VoiceChecks[] { VoiceChecks.BOT_CONNECTED, VoiceChecks.BOT_PLAYING, VoiceChecks.USER_CONNECTED, VoiceChecks.SAME_VC_IF_CONNECTED })
|
||||
.build();
|
||||
}
|
||||
|
||||
|
|
@ -49,9 +46,7 @@ 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();
|
||||
messageChannel.sendMessage("Usage: `remove [index of song to remove]/first/last`. Use the `queue` command to find the index.").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -76,9 +71,7 @@ public class Remove implements Command {
|
|||
} else if (indexAliases.containsKey(index.toLowerCase(Locale.ROOT))) {
|
||||
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();
|
||||
messageChannel.sendMessage("Usage: `remove [index of song to remove]/first/last`. Use the `queue` command to find the index.").queue();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,14 +20,8 @@ import java.util.regex.Matcher;
|
|||
import java.util.regex.Pattern;
|
||||
|
||||
public class SpotifyApiHelper {
|
||||
private static final String CLIENT_ID = ZtereoMUSIC.getInstance()
|
||||
.getConfig()
|
||||
.getPropreties()
|
||||
.get("spotify_client_id");
|
||||
private static final String CLIENT_SECRET = ZtereoMUSIC.getInstance()
|
||||
.getConfig()
|
||||
.getPropreties()
|
||||
.get("spotify_client_secret");
|
||||
private static final String CLIENT_ID = ZtereoMUSIC.getInstance().getConfig().getPropreties().get("spotify_client_id");
|
||||
private static final String CLIENT_SECRET = ZtereoMUSIC.getInstance().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 final Json JSON = Json.json();
|
||||
|
|
@ -52,14 +46,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();
|
||||
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();
|
||||
|
||||
JsonPath tokenPath = JsonPath.parse("access_token");
|
||||
try {
|
||||
|
|
@ -96,10 +89,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");
|
||||
|
|
|
|||
|
|
@ -14,8 +14,7 @@ public class YoutubeSearch {
|
|||
private static final Json JSON = Json.json();
|
||||
|
||||
public static Pair<Boolean, String> query(String title) {
|
||||
String query = "https://www.googleapis.com/youtube/v3/search?part=snippet&q=%22" + title.replace(' ',
|
||||
'+') + "%22&type=video&key=" + API_KEY;
|
||||
String query = "https://www.googleapis.com/youtube/v3/search?part=snippet&q=%22" + title.replace(' ', '+') + "%22&type=video&key=" + API_KEY;
|
||||
|
||||
String jsonResponse;
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue