|
|
@ -1,10 +1,14 @@ |
|
|
|
package de.yannicpunktdee.yoshibot.command; |
|
|
|
|
|
|
|
import de.yannicpunktdee.yoshibot.audio.AudioLoadResultHandlerImpl; |
|
|
|
import de.yannicpunktdee.yoshibot.main.YoshiBot; |
|
|
|
import de.yannicpunktdee.yoshibot.utils.Logger; |
|
|
|
import de.yannicpunktdee.yoshibot.utils.Resources; |
|
|
|
import net.dv8tion.jda.api.entities.Message; |
|
|
|
import net.dv8tion.jda.api.entities.Message.Attachment; |
|
|
|
import net.dv8tion.jda.api.entities.MessageEmbed; |
|
|
|
import net.dv8tion.jda.api.entities.VoiceChannel; |
|
|
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.util.List; |
|
|
@ -58,23 +62,23 @@ public abstract class YoshiCommand { |
|
|
|
protected final void sendMessage(MessageEmbed messageEmbed) { |
|
|
|
context.getEvent().getTextChannel().sendMessage(messageEmbed).queue(); |
|
|
|
} |
|
|
|
|
|
|
|
protected File downloadAttachmentToFile(String directoryPath, String name){ |
|
|
|
if(directoryPath == null) directoryPath = Resources.getTempPath(); |
|
|
|
if(name == null) name = UUID.randomUUID().toString(); |
|
|
|
|
|
|
|
if(!(new File(directoryPath)).isDirectory()){ |
|
|
|
|
|
|
|
protected File downloadAttachmentToFile(String directoryPath, String name) { |
|
|
|
if (directoryPath == null) directoryPath = Resources.getTempPath(); |
|
|
|
if (name == null) name = UUID.randomUUID().toString(); |
|
|
|
|
|
|
|
if (!(new File(directoryPath)).isDirectory()) { |
|
|
|
Logger.logError("Das Download-Verzeichnis wurde nicht gefunden."); |
|
|
|
sendMessage("Der Anhang konnte nicht gedownloaded werden."); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
List<Attachment> attachments = context.getEvent().getMessage().getAttachments(); |
|
|
|
if(attachments.size() == 0){ |
|
|
|
if (attachments.size() == 0) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
Attachment attachment = attachments.get(0); |
|
|
|
|
|
|
|
|
|
|
|
File file = new File(directoryPath + name + "." + attachment.getFileExtension()); |
|
|
|
CompletableFuture<File> future = attachment.downloadToFile(file); |
|
|
|
future.exceptionally(e -> { |
|
|
@ -87,12 +91,27 @@ public abstract class YoshiCommand { |
|
|
|
sendMessage("Ein Anhang konnte nicht gedownloaded werden."); |
|
|
|
return null; |
|
|
|
} |
|
|
|
if(!file.exists()) { |
|
|
|
if (!file.exists()) { |
|
|
|
sendMessage("Ein Anhang konnte nicht gedownloaded werden."); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return file; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean sayToChannel(String path, String channel, MessageReceivedEvent event) { |
|
|
|
List<VoiceChannel> channels = YoshiBot.getInstance().jda |
|
|
|
.getVoiceChannelsByName(channel, true); |
|
|
|
if (!(channels.size() > 0)) { |
|
|
|
event.getTextChannel().sendMessage("Der Kanalname konnte nicht gefunden werden.").queue(); |
|
|
|
return false; |
|
|
|
} |
|
|
|
VoiceChannel vc = channels.get(0); |
|
|
|
|
|
|
|
YoshiBot.getInstance().audioPlayerManager.loadItem(path, new AudioLoadResultHandlerImpl()); |
|
|
|
vc.getGuild().getAudioManager().openAudioConnection(vc); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
} |