|
@ -1,20 +1,15 @@ |
|
|
package de.yannicpunktdee.yoshibot.command; |
|
|
package de.yannicpunktdee.yoshibot.command; |
|
|
|
|
|
|
|
|
import de.yannicpunktdee.yoshibot.audio.AudioLoadResultHandlerImpl; |
|
|
|
|
|
import de.yannicpunktdee.yoshibot.command.commands.SayCommand; |
|
|
|
|
|
import de.yannicpunktdee.yoshibot.main.YoshiBot; |
|
|
import de.yannicpunktdee.yoshibot.main.YoshiBot; |
|
|
import de.yannicpunktdee.yoshibot.utils.Logger; |
|
|
import de.yannicpunktdee.yoshibot.utils.Logger; |
|
|
import de.yannicpunktdee.yoshibot.utils.Resources; |
|
|
import de.yannicpunktdee.yoshibot.utils.Resources; |
|
|
import net.dv8tion.jda.api.entities.Message; |
|
|
|
|
|
|
|
|
import net.dv8tion.jda.api.EmbedBuilder; |
|
|
import net.dv8tion.jda.api.entities.Message.Attachment; |
|
|
import net.dv8tion.jda.api.entities.Message.Attachment; |
|
|
import net.dv8tion.jda.api.entities.MessageEmbed; |
|
|
import net.dv8tion.jda.api.entities.MessageEmbed; |
|
|
import net.dv8tion.jda.api.entities.VoiceChannel; |
|
|
import net.dv8tion.jda.api.entities.VoiceChannel; |
|
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.BufferedReader; |
|
|
|
|
|
|
|
|
import java.awt.*; |
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
import java.io.IOException; |
|
|
|
|
|
import java.io.InputStreamReader; |
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.UUID; |
|
|
import java.util.UUID; |
|
|
import java.util.concurrent.CompletableFuture; |
|
|
import java.util.concurrent.CompletableFuture; |
|
@ -55,19 +50,44 @@ public abstract class YoshiCommand { |
|
|
*/ |
|
|
*/ |
|
|
public boolean execute() { |
|
|
public boolean execute() { |
|
|
if (!context.containsArguments(requiredArguments)) { |
|
|
if (!context.containsArguments(requiredArguments)) { |
|
|
sendMessage("Fehlende Argumente"); |
|
|
|
|
|
|
|
|
sendErrorMessage("Fehlende Argumente"); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected final void sendMessage(String message) { |
|
|
|
|
|
context.getEvent().getTextChannel().sendMessage(message).queue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected final void sendMessage(String message){ |
|
|
|
|
|
EmbedBuilder eb = new EmbedBuilder(); |
|
|
|
|
|
eb.setTitle("INFO"); |
|
|
|
|
|
eb.setColor(Color.pink); |
|
|
|
|
|
eb.setDescription(message); |
|
|
|
|
|
context.getEvent().getTextChannel().sendMessage(eb.build()).queue(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected final void sendMessage(MessageEmbed messageEmbed) { |
|
|
|
|
|
|
|
|
protected final void sendFile(File file, String description){ |
|
|
|
|
|
EmbedBuilder eb = new EmbedBuilder(); |
|
|
|
|
|
eb.setTitle("INFO"); |
|
|
|
|
|
eb.setColor(Color.pink); |
|
|
|
|
|
if(description != null) eb.setDescription(description); |
|
|
|
|
|
context.getEvent().getTextChannel().sendFile(file).queue(); |
|
|
|
|
|
} |
|
|
|
|
|
protected final void sendInfoMessage(String message){ |
|
|
|
|
|
EmbedBuilder eb = new EmbedBuilder(); |
|
|
|
|
|
eb.setTitle("INFO"); |
|
|
|
|
|
eb.setColor(Color.blue); |
|
|
|
|
|
eb.setDescription(message); |
|
|
|
|
|
context.getEvent().getTextChannel().sendMessage(eb.build()).queue(); |
|
|
|
|
|
} |
|
|
|
|
|
protected final void sendErrorMessage(String message) { |
|
|
|
|
|
EmbedBuilder eb = new EmbedBuilder(); |
|
|
|
|
|
eb.setTitle("ERROR"); |
|
|
|
|
|
eb.setColor(Color.red); |
|
|
|
|
|
eb.setDescription(message); |
|
|
|
|
|
context.getEvent().getTextChannel().sendMessage(eb.build()).queue(); |
|
|
|
|
|
} |
|
|
|
|
|
protected final void sendCustomMessage(MessageEmbed messageEmbed) { |
|
|
context.getEvent().getTextChannel().sendMessage(messageEmbed).queue(); |
|
|
context.getEvent().getTextChannel().sendMessage(messageEmbed).queue(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected File downloadAttachmentToFile(String directoryPath, String name) { |
|
|
protected File downloadAttachmentToFile(String directoryPath, String name) { |
|
|
if (directoryPath == null) directoryPath = Resources.getTempPath(); |
|
|
if (directoryPath == null) directoryPath = Resources.getTempPath(); |
|
@ -75,7 +95,7 @@ public abstract class YoshiCommand { |
|
|
|
|
|
|
|
|
if (!(new File(directoryPath)).isDirectory()) { |
|
|
if (!(new File(directoryPath)).isDirectory()) { |
|
|
Logger.logError("Das Download-Verzeichnis wurde nicht gefunden."); |
|
|
Logger.logError("Das Download-Verzeichnis wurde nicht gefunden."); |
|
|
sendMessage("Der Anhang konnte nicht gedownloaded werden."); |
|
|
|
|
|
|
|
|
sendErrorMessage("Der Anhang konnte nicht gedownloaded werden."); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -88,17 +108,17 @@ public abstract class YoshiCommand { |
|
|
File file = new File(directoryPath + name + "." + attachment.getFileExtension()); |
|
|
File file = new File(directoryPath + name + "." + attachment.getFileExtension()); |
|
|
CompletableFuture<File> future = attachment.downloadToFile(file); |
|
|
CompletableFuture<File> future = attachment.downloadToFile(file); |
|
|
future.exceptionally(e -> { |
|
|
future.exceptionally(e -> { |
|
|
sendMessage("Ein Anhang konnte nicht gedownloaded werden."); |
|
|
|
|
|
|
|
|
sendErrorMessage("Ein Anhang konnte nicht gedownloaded werden."); |
|
|
return null; |
|
|
return null; |
|
|
}); |
|
|
}); |
|
|
try { |
|
|
try { |
|
|
future.get(); |
|
|
future.get(); |
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
} catch (InterruptedException | ExecutionException e) { |
|
|
sendMessage("Ein Anhang konnte nicht gedownloaded werden."); |
|
|
|
|
|
|
|
|
sendErrorMessage("Ein Anhang konnte nicht gedownloaded werden."); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
if (!file.exists()) { |
|
|
if (!file.exists()) { |
|
|
sendMessage("Ein Anhang konnte nicht gedownloaded werden."); |
|
|
|
|
|
|
|
|
sendErrorMessage("Ein Anhang konnte nicht gedownloaded werden."); |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|