Skip to content

Commit 086b7fa

Browse files
committed
Minor Fixes
1 parent 05eca74 commit 086b7fa

File tree

3 files changed

+39
-3
lines changed

3 files changed

+39
-3
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ dependencies {
6464
installer('org.mangorage:installer:4.0.5')
6565
bot('org.mangorage:mangobot:11.0.23')
6666

67-
plugin('org.mangorage:mangobotplugin:11.1.18')
67+
plugin('org.mangorage:mangobotplugin:11.1.28')
6868
plugin('org.mangorage:mangobotwebsite:1.0.21')
6969

7070
library('org.eclipse.mylyn.github:org.eclipse.egit.github.core:2.1.5')

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.mangorage.mangobotgithub.core.integration.MangoBotSiteIntegration;
2222
import java.io.IOException;
2323
import java.io.InputStream;
24+
import java.lang.classfile.AccessFlags;
25+
import java.lang.reflect.AccessFlag;
2426
import java.nio.charset.StandardCharsets;
2527
import java.util.HashMap;
2628
import java.util.List;
@@ -157,7 +159,9 @@ public static void onMessage(DiscordEvent<MessageReceivedEvent> event) {
157159
var dEvent = event.getInstance();
158160
var message = dEvent.getMessage();
159161
var attachments = message.getAttachments();
160-
analyser.scanMessage(message);
162+
163+
var builder = new StringBuilder();
164+
analyser.scanMessage(message, builder);
161165
if (!attachments.isEmpty()) {
162166
TaskScheduler.getExecutor().execute(() -> {
163167
var suceeeded = new AtomicBoolean(false);
@@ -168,14 +172,27 @@ public static void onMessage(DiscordEvent<MessageReceivedEvent> event) {
168172
String content = new String(bytes, StandardCharsets.UTF_8);
169173
if (containsPrintableCharacters(content)) {
170174
suceeeded.set(true);
171-
analyser.readLog(message, content);
175+
analyser.readLog(builder, content);
172176
break;
173177
}
174178
} catch (InterruptedException | ExecutionException e) {
175179
throw new RuntimeException(e);
176180
}
177181
}
178182

183+
if (!builder.isEmpty()) {
184+
String id = null;
185+
if (PluginManager.isLoaded("mangobotsite")) {
186+
try {
187+
id = MangoBotSiteIntegration.handleLogResult(builder);
188+
if (id != null) {
189+
message.reply("[[Log Analyzer](https://mangobot.mangorage.org/file?id=%s)]".formatted(id)).setSuppressEmbeds(true).mentionRepliedUser(false).queue();
190+
}
191+
} catch (IOException ignored) {}
192+
}
193+
}
194+
195+
179196
if (suceeeded.get()) message.addReaction(EMOJI).queue();
180197
});
181198
}

src/main/java/org/mangorage/mangobotgithub/core/integration/MangoBotSiteIntegration.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@
55
import org.mangorage.mangobotsite.MangoBotSite;
66
import org.mangorage.mangobotsite.website.file.FileStream;
77

8+
import java.io.BufferedInputStream;
9+
import java.io.ByteArrayInputStream;
810
import java.io.IOException;
11+
import java.io.InputStream;
12+
import java.nio.charset.StandardCharsets;
913
import java.util.List;
1014
import java.util.concurrent.ExecutionException;
1115

1216
public final class MangoBotSiteIntegration {
1317
private static final String ID = "5473b5bf-044b-4a57-a78d-be61289e4266";
1418

19+
public static InputStream stringBuilderToInputStream(StringBuilder sb) {
20+
return new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8));
21+
}
22+
1523
public static String handleUpload(List<Message.Attachment> attachments) throws IOException {
1624
return PluginManager.getPlugin("mangobotsite", MangoBotSite.class)
1725
.getFileUploadManager()
@@ -27,4 +35,15 @@ public static String handleUpload(List<Message.Attachment> attachments) throws I
2735
ID
2836
);
2937
}
38+
39+
public static String handleLogResult(StringBuilder builder) throws IOException {
40+
return PluginManager.getPlugin("mangobotsite", MangoBotSite.class)
41+
.getFileUploadManager()
42+
.createUpload(
43+
List.of(
44+
new FileStream("logResult.txt", () -> stringBuilderToInputStream(builder))
45+
),
46+
ID
47+
);
48+
}
3049
}

0 commit comments

Comments
 (0)