Skip to content

Commit 4c0be6b

Browse files
committed
Fixed some stuff...
1 parent b82eada commit 4c0be6b

4 files changed

Lines changed: 63 additions & 10 deletions

File tree

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ dependencies {
8080
bot('org.mangorage:mangobot:11.0.18')
8181

8282
plugin('org.mangorage:mangobotplugin:11.1.6')
83+
plugin('org.mangorage:mangobotwebsite:1.0.10')
8384

8485
compileOnly('org.mangorage:MangoBotGradle:4.0.5')
8586

src/main/java/org/mangorage/mangobotgithub/core/PasteRequestModule.java

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
import org.mangorage.mangobot.modules.logs.LogAnalyser;
2020
import org.mangorage.mangobot.modules.logs.MissingDeps;
2121
import org.mangorage.mangobotapi.core.events.DiscordEvent;
22+
import org.mangorage.mangobotapi.core.plugin.PluginManager;
2223
import org.mangorage.mangobotgithub.MangoBotGithub;
24+
import org.mangorage.mangobotgithub.core.integration.MangoBotSiteIntegration;
2325

26+
import java.io.File;
2427
import java.io.IOException;
2528
import java.io.InputStream;
2629
import java.nio.charset.StandardCharsets;
@@ -159,6 +162,14 @@ public static void createGists(Message msg, User requester) {
159162
gist.setDescription("Automatically made from MangoBot.");
160163

161164
HashMap<String, GistFile> FILES = new HashMap<>();
165+
166+
String id = null;
167+
if (PluginManager.isLoaded("mangobotsite")) {
168+
try {
169+
id = MangoBotSiteIntegration.handleUpload(attachments);
170+
} catch (IOException ignored) {}
171+
}
172+
162173
attachments.forEach(attachment -> {
163174
try {
164175

@@ -180,19 +191,26 @@ public static void createGists(Message msg, User requester) {
180191

181192
gist.setFiles(FILES);
182193

183-
try {
184-
var remote = service.createGist(gist);
185-
StringBuilder result = new StringBuilder();
186-
result.append("Gist -> [[gist](%s)]".formatted(remote.getHtmlUrl()));
194+
if (FILES.isEmpty() && id != null) {
195+
msg.reply(("Upload -> [[mango](https://mangobot.mangorage.org/file?id=%s)]".formatted(id))).setSuppressEmbeds(true).mentionRepliedUser(false).queue();
196+
} else {
197+
try {
198+
var remote = service.createGist(gist);
199+
StringBuilder result = new StringBuilder();
200+
result.append("Gist -> [[gist](%s)]".formatted(remote.getHtmlUrl()));
187201

188-
remote.getFiles().forEach((key, file) -> {
189-
result.append(" [[raw %s](%s)]".formatted(file.getFilename(), file.getRawUrl()));
190-
});
202+
if (id != null) {
203+
result.append(" [[mango](https://mangobot.mangorage.org/file?id=%s)]".formatted(id));
204+
}
191205

192-
msg.reply(result).setSuppressEmbeds(true).mentionRepliedUser(false).queue();
206+
remote.getFiles().forEach((key, file) -> {
207+
result.append(" [[raw %s](%s)]".formatted(file.getFilename(), file.getRawUrl()));
208+
});
193209

194-
} catch (IOException e) {
195-
throw new RuntimeException(e);
210+
msg.reply(result).setSuppressEmbeds(true).mentionRepliedUser(false).queue();
211+
} catch (IOException e) {
212+
throw new RuntimeException(e);
213+
}
196214
}
197215

198216
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.mangorage.mangobotgithub.core.integration;
2+
3+
import net.dv8tion.jda.api.entities.Message;
4+
import org.mangorage.mangobotapi.core.plugin.PluginManager;
5+
import org.mangorage.mangobotsite.MangoBotSite;
6+
import org.mangorage.mangobotsite.website.file.FileStream;
7+
8+
import java.io.IOException;
9+
import java.util.List;
10+
import java.util.concurrent.ExecutionException;
11+
12+
public final class MangoBotSiteIntegration {
13+
private static final String ID = "5473b5bf-044b-4a57-a78d-be61289e4266";
14+
15+
public static String handleUpload(List<Message.Attachment> attachments) throws IOException {
16+
return PluginManager.getPlugin("mangobotsite", MangoBotSite.class)
17+
.getFileUploadManager()
18+
.createUpload(
19+
attachments.stream()
20+
.map(attachment -> new FileStream(attachment.getFileName(), () -> {
21+
try {
22+
return attachment.getProxy().download().get();
23+
} catch (InterruptedException | ExecutionException e) {
24+
throw new IOException(e);
25+
}
26+
})).toList(),
27+
ID
28+
);
29+
}
30+
}

src/main/resources/mangobotgithub.plugin.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
{
1212
"id": "mangobot",
1313
"type": "REQUIRED"
14+
},
15+
{
16+
"id": "mangobotsite",
17+
"type": "OPTIONAL"
1418
}
1519
]
1620
}

0 commit comments

Comments
 (0)