aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/pinapelz/Retriever.java
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-12-28 19:44:52 -0800
committerPinapelz <yukais@pinapelz.com>2025-12-28 19:44:52 -0800
commitfbe9b9eb7a462b42f235d100811b377659101b3c (patch)
tree0a1232f4b9e41a697c4cd066124a8a28a1e7e031 /src/main/java/com/pinapelz/Retriever.java
parentbe26d198646b28100c0e983af9d8e10545575dbe (diff)
implement basic file retrieval
Diffstat (limited to 'src/main/java/com/pinapelz/Retriever.java')
-rw-r--r--src/main/java/com/pinapelz/Retriever.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main/java/com/pinapelz/Retriever.java b/src/main/java/com/pinapelz/Retriever.java
new file mode 100644
index 0000000..1d78785
--- /dev/null
+++ b/src/main/java/com/pinapelz/Retriever.java
@@ -0,0 +1,34 @@
+package com.pinapelz;
+
+import net.dv8tion.jda.api.JDA;
+import net.dv8tion.jda.api.entities.Message;
+import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
+
+import java.util.concurrent.CompletableFuture;
+
+public class Retriever {
+
+ private final JDA jda;
+
+ public Retriever(JDA jda) {
+ this.jda = jda;
+ }
+
+ public String getFileUrl(String channelId, String messageId, String fileName) {
+ TextChannel channel = jda.getTextChannelById(channelId);
+ if (channel == null) {
+ throw new RuntimeException("Channel not found or deleted");
+ }
+ System.out.println(channelId + " " + messageId + fileName);
+
+ Message message = channel.retrieveMessageById(messageId).complete();
+
+ for (Message.Attachment file : message.getAttachments()) {
+ if (file.getFileName().equals(fileName)) {
+ return file.getUrl();
+ }
+ }
+
+ throw new RuntimeException("Matching attachment not found");
+ }
+} \ No newline at end of file
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage