From 5ec62d4d439f49599438990bc46d7bf5f0739d64 Mon Sep 17 00:00:00 2001 From: Nekojimi Date: Sun, 14 Apr 2024 19:55:50 +0100 Subject: [PATCH] Add support for uploading tracks to play them. --- src/main/java/moe/nekojimi/chords/Chords.java | 44 +++++++++++++------ 1 file changed, 31 insertions(+), 13 deletions(-) diff --git a/src/main/java/moe/nekojimi/chords/Chords.java b/src/main/java/moe/nekojimi/chords/Chords.java index b117e60..8f17d04 100644 --- a/src/main/java/moe/nekojimi/chords/Chords.java +++ b/src/main/java/moe/nekojimi/chords/Chords.java @@ -29,6 +29,7 @@ import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent; +import net.dv8tion.jda.api.events.message.MessageEmbedEvent; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.managers.AudioManager; @@ -238,20 +239,35 @@ public final class Chords extends ListenerAdapter String cmd = split[0].toLowerCase(); - if (!cmd.startsWith("!")) - return; // doesn't start with prefix char - - cmd = cmd.substring(1); // strip prefix char - -// String arg = ""; - - if (commands.containsKey(cmd)) + if (cmd.startsWith("!")) { - Command command = commands.get(cmd); - command.call(invocation); - } else + cmd = cmd.substring(1); // strip prefix char + + if (commands.containsKey(cmd)) + { + Command command = commands.get(cmd); + command.call(invocation); + } else + { + helpCommand.call(invocation); + } + } else if (!event.getMessage().getAttachments().isEmpty()) { - helpCommand.call(invocation); + for (Message.Attachment attach : event.getMessage().getAttachments()) + { + if (attach.getContentType().startsWith("audio") || attach.getContentType().startsWith("video")) + { + try + { + invocation = new Invocation(event, List.of(new URL(attach.getUrl()).toExternalForm())); + invocation.setRequestMessage(message); + playCommand.call(invocation); + } catch (MalformedURLException ex) + { + Logger.getLogger(Chords.class.getName()).log(Level.WARNING, null, ex); + } + } + } } } catch (Exception ex) { @@ -261,6 +277,8 @@ public final class Chords extends ListenerAdapter event.getChannel().sendMessage("Error: " + ex.getMessage()).queue(); log("UERR", "Command error:" + ex.getMessage()); } + + // TODO: this will handle uploading files, maybe } public void queueDownload(TrackRequest request) @@ -488,7 +506,7 @@ public final class Chords extends ListenerAdapter String progressDetails = ""; if (track.getProgress() >= 0) { - if (track.getProgress() >= lastProgressUpdate + 10.0) + if (track.getProgress() >= lastProgressUpdate + 5.0) { shouldUpdate = true; lastProgressUpdate = track.getProgress();