blob: db314fea108314bdfe5c59518e6fa021181e7aac (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
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;
public class Retriever {
private final JDA jda;
public Retriever(JDA jda) {
this.jda = jda;
}
public String getFileUrl(String channelId, String messageId, String fileName) {
return getFileUrl(channelId, messageId, fileName, false);
}
public String getFileUrl(String channelId, String messageId, String fileName, boolean isWebhookUpload) {
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 isWebhookUpload ? file.getUrl() : file.getProxyUrl();
}
}
throw new RuntimeException("Matching attachment not found");
}
}
|