Add support for uploading tracks to play them.
This commit is contained in:
parent
a9c5bb37f8
commit
5ec62d4d43
|
@ -29,6 +29,7 @@ import net.dv8tion.jda.api.JDABuilder;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.*;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
|
||||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
|
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.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import net.dv8tion.jda.api.managers.AudioManager;
|
import net.dv8tion.jda.api.managers.AudioManager;
|
||||||
|
@ -238,13 +239,10 @@ public final class Chords extends ListenerAdapter
|
||||||
|
|
||||||
String cmd = split[0].toLowerCase();
|
String cmd = split[0].toLowerCase();
|
||||||
|
|
||||||
if (!cmd.startsWith("!"))
|
if (cmd.startsWith("!"))
|
||||||
return; // doesn't start with prefix char
|
{
|
||||||
|
|
||||||
cmd = cmd.substring(1); // strip prefix char
|
cmd = cmd.substring(1); // strip prefix char
|
||||||
|
|
||||||
// String arg = "";
|
|
||||||
|
|
||||||
if (commands.containsKey(cmd))
|
if (commands.containsKey(cmd))
|
||||||
{
|
{
|
||||||
Command command = commands.get(cmd);
|
Command command = commands.get(cmd);
|
||||||
|
@ -253,6 +251,24 @@ public final class Chords extends ListenerAdapter
|
||||||
{
|
{
|
||||||
helpCommand.call(invocation);
|
helpCommand.call(invocation);
|
||||||
}
|
}
|
||||||
|
} else if (!event.getMessage().getAttachments().isEmpty())
|
||||||
|
{
|
||||||
|
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)
|
} catch (Exception ex)
|
||||||
{
|
{
|
||||||
if (invocation != null)
|
if (invocation != null)
|
||||||
|
@ -261,6 +277,8 @@ public final class Chords extends ListenerAdapter
|
||||||
event.getChannel().sendMessage("Error: " + ex.getMessage()).queue();
|
event.getChannel().sendMessage("Error: " + ex.getMessage()).queue();
|
||||||
log("UERR", "Command error:" + ex.getMessage());
|
log("UERR", "Command error:" + ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: this will handle uploading files, maybe
|
||||||
}
|
}
|
||||||
|
|
||||||
public void queueDownload(TrackRequest request)
|
public void queueDownload(TrackRequest request)
|
||||||
|
@ -488,7 +506,7 @@ public final class Chords extends ListenerAdapter
|
||||||
String progressDetails = "";
|
String progressDetails = "";
|
||||||
if (track.getProgress() >= 0)
|
if (track.getProgress() >= 0)
|
||||||
{
|
{
|
||||||
if (track.getProgress() >= lastProgressUpdate + 10.0)
|
if (track.getProgress() >= lastProgressUpdate + 5.0)
|
||||||
{
|
{
|
||||||
shouldUpdate = true;
|
shouldUpdate = true;
|
||||||
lastProgressUpdate = track.getProgress();
|
lastProgressUpdate = track.getProgress();
|
||||||
|
|
Loading…
Reference in New Issue