Skip to content

Commit 1e4e6dd

Browse files
committed
Add changelog in update embeds
1 parent ad076f4 commit 1e4e6dd

12 files changed

Lines changed: 459 additions & 175 deletions

File tree

src/commander/java/com/mcmoddev/mmdbot/commander/TheCommander.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
import com.mcmoddev.mmdbot.commander.config.Configuration;
4040
import com.mcmoddev.mmdbot.commander.custompings.CustomPings;
4141
import com.mcmoddev.mmdbot.commander.custompings.CustomPingsListener;
42-
import com.mcmoddev.mmdbot.core.commands.component.storage.ComponentStorage;
43-
import com.mcmoddev.mmdbot.core.util.event.DismissListener;
4442
import com.mcmoddev.mmdbot.commander.eventlistener.ReferencingListener;
4543
import com.mcmoddev.mmdbot.commander.eventlistener.ThreadListener;
4644
import com.mcmoddev.mmdbot.commander.migrate.QuotesMigrator;
@@ -49,16 +47,20 @@
4947
import com.mcmoddev.mmdbot.commander.reminders.SnoozingListener;
5048
import com.mcmoddev.mmdbot.commander.tricks.Tricks;
5149
import com.mcmoddev.mmdbot.commander.updatenotifiers.UpdateNotifiers;
50+
import com.mcmoddev.mmdbot.commander.updatenotifiers.forge.ForgeUpdateNotifier;
51+
import com.mcmoddev.mmdbot.commander.updatenotifiers.forge.ForgeVersion;
52+
import com.mcmoddev.mmdbot.commander.updatenotifiers.forge.ForgeVersionHelper;
5253
import com.mcmoddev.mmdbot.commander.util.EventListeners;
5354
import com.mcmoddev.mmdbot.commander.util.ThreadChannelCreatorEvents;
5455
import com.mcmoddev.mmdbot.commander.util.mc.MCVersions;
5556
import com.mcmoddev.mmdbot.core.bot.Bot;
5657
import com.mcmoddev.mmdbot.core.bot.BotRegistry;
5758
import com.mcmoddev.mmdbot.core.bot.BotType;
5859
import com.mcmoddev.mmdbot.core.bot.RegisterBotType;
60+
import com.mcmoddev.mmdbot.core.commands.CommandUpserter;
5961
import com.mcmoddev.mmdbot.core.commands.component.ComponentListener;
6062
import com.mcmoddev.mmdbot.core.commands.component.ComponentManager;
61-
import com.mcmoddev.mmdbot.core.commands.component.storage.SQLComponentStorage;
63+
import com.mcmoddev.mmdbot.core.commands.component.storage.ComponentStorage;
6264
import com.mcmoddev.mmdbot.core.event.Events;
6365
import com.mcmoddev.mmdbot.core.util.ConfigurateUtils;
6466
import com.mcmoddev.mmdbot.core.util.DotenvLoader;
@@ -67,7 +69,7 @@
6769
import com.mcmoddev.mmdbot.core.util.TaskScheduler;
6870
import com.mcmoddev.mmdbot.core.util.Utils;
6971
import com.mcmoddev.mmdbot.core.util.dictionary.DictionaryUtils;
70-
import com.mcmoddev.mmdbot.core.commands.CommandUpserter;
72+
import com.mcmoddev.mmdbot.core.util.event.DismissListener;
7173
import com.mcmoddev.mmdbot.core.util.event.OneTimeEventListener;
7274
import com.mcmoddev.mmdbot.dashboard.util.BotUserData;
7375
import io.github.cdimascio.dotenv.Dotenv;

src/commander/java/com/mcmoddev/mmdbot/commander/quotes/Quotes.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.nio.charset.StandardCharsets;
4848
import java.nio.file.Files;
4949
import java.nio.file.Path;
50+
import java.nio.file.StandardOpenOption;
5051
import java.time.Instant;
5152
import java.util.ArrayList;
5253
import java.util.Collections;
@@ -189,10 +190,8 @@ private static void syncQuotes() {
189190
if (quotes == null) {
190191
loadQuotes();
191192
}
192-
final File quoteFile = QUOTE_STORAGE.get().toFile();
193193
final var db = VersionedDatabase.inMemory(CURRENT_SCHEMA_VERSION, quotes);
194-
try (OutputStreamWriter writer =
195-
new OutputStreamWriter(new FileOutputStream(quoteFile), StandardCharsets.UTF_8)) {
194+
try (final var writer = Files.newBufferedWriter(QUOTE_STORAGE.get(), StandardCharsets.UTF_8, StandardOpenOption.CREATE)) {
196195
GSON.toJson(db.toJson(GSON), writer);
197196
} catch (Exception exception) {
198197
TheCommander.LOGGER.error("Failed to write quote file...", exception);

src/commander/java/com/mcmoddev/mmdbot/commander/updatenotifiers/forge/ForgeUpdateNotifier.java

Lines changed: 58 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,15 @@
2727
import net.dv8tion.jda.api.entities.MessageChannel;
2828

2929
import java.awt.Color;
30+
import java.io.BufferedReader;
3031
import java.io.IOException;
32+
import java.io.InputStreamReader;
33+
import java.net.URL;
34+
import java.nio.charset.StandardCharsets;
3135
import java.time.Instant;
36+
import java.util.ArrayList;
37+
import java.util.Scanner;
38+
import java.util.stream.Stream;
3239

3340
import static com.mcmoddev.mmdbot.commander.updatenotifiers.UpdateNotifiers.LOGGER;
3441
import static com.mcmoddev.mmdbot.commander.updatenotifiers.UpdateNotifiers.MARKER;
@@ -104,10 +111,16 @@ public void run() {
104111
changed = true;
105112
logMsg.append("Latest, from none to ").append(latest.getLatest());
106113
} else if (!latest.getLatest().equals(lastForgeVersions.getLatest())) {
107-
embed.addField("Latest", String.format("**%s** -> **%s**%n", lastForgeVersions.getLatest(),
108-
latest.getLatest()), true);
109-
embed.setDescription(Utils.makeHyperlink(CHANGELOG, String.format(CHANGELOG_URL_TEMPLATE, mcVersion,
110-
latest.getLatest())));
114+
final var start = lastForgeVersions.getLatest();
115+
final var end = latest.getLatest();
116+
embed.addField("Latest", String.format("**%s** -> **%s**%n", start,
117+
end), true);
118+
embed.setDescription("""
119+
[Changelog](%s):
120+
```
121+
%s
122+
```""".formatted(CHANGELOG_URL_TEMPLATE.formatted(mcVersion, end),
123+
getChangelogBetweenVersions(mcVersion, start, mcVersion, end)));
111124
changed = true;
112125
logMsg.append("Latest, from ").append(lastForgeVersions.getLatest()).append(" to ")
113126
.append(latest.getLatest());
@@ -119,17 +132,24 @@ public void run() {
119132
logMsg.append("; ");
120133
}
121134
if (lastForgeVersions.getRecommended() == null) {
122-
embed.addField("Recommended", String.format("*none* -> **%s**%n", latest.getRecommended()),
135+
final var version = latest.getRecommended();
136+
embed.addField("Recommended", String.format("*none* -> **%s**%n", version),
123137
true);
124138
embed.setDescription(Utils.makeHyperlink(CHANGELOG, String.format(CHANGELOG_URL_TEMPLATE,
125139
mcVersion, latest.getRecommended())));
126140
changed = true;
127141
logMsg.append("Recommended, from none to ").append(latest.getLatest());
128142
} else if (!latest.getRecommended().equals(lastForgeVersions.getRecommended())) {
143+
final var start = lastForgeVersions.getRecommended();
144+
final var end = latest.getRecommended();
129145
embed.addField("Recommended", String.format("**%s** -> **%s**%n",
130-
lastForgeVersions.getRecommended(), latest.getRecommended()), true);
131-
embed.setDescription(Utils.makeHyperlink(CHANGELOG, String.format(CHANGELOG_URL_TEMPLATE,
132-
mcVersion, latest.getRecommended())));
146+
start, end), true);
147+
embed.setDescription("""
148+
[Changelog](%s):
149+
```
150+
%s
151+
```""".formatted(CHANGELOG_URL_TEMPLATE.formatted(mcVersion, end),
152+
getChangelogBetweenVersions(mcVersion, start, mcVersion, end)));
133153
changed = true;
134154
logMsg.append("Recommended, from ").append(lastForgeVersions.getLatest()).append(" to ")
135155
.append(latest.getLatest());
@@ -160,4 +180,34 @@ public void run() {
160180
ex.printStackTrace();
161181
}
162182
}
183+
184+
public static String getChangelogBetweenVersions(final String startMc, final String startForge, final String endMc, final String endForge) throws IOException {
185+
final var startUrl = new URL(CHANGELOG_URL_TEMPLATE.formatted(startMc, startForge));
186+
final var endUrl = new URL(CHANGELOG_URL_TEMPLATE.formatted(endMc, endForge));
187+
188+
final var startMcVersionSplit = startMc.split("\\.");
189+
final var startForgeVersionSplit = startForge.split("\\.");
190+
final var startChangelog = getUrlAsString(startUrl).replace("""
191+
%s.%s.x Changelog
192+
%s.%s
193+
====""".formatted(startMcVersionSplit[0], startMcVersionSplit[1], startForgeVersionSplit[0], startForgeVersionSplit[1]), "");
194+
195+
final var endChangelog = getUrlAsString(endUrl);
196+
var changelog = endChangelog.replace(startChangelog, "");
197+
198+
final var endMcVersionSplit = endMc.split("\\.");
199+
final var endForgeVersionSplit = endForge.split("\\.");
200+
changelog = changelog.replace("""
201+
%s.%s.x Changelog
202+
%s.%s
203+
====""".formatted(endMcVersionSplit[0], endMcVersionSplit[1], endForgeVersionSplit[0], endForgeVersionSplit[1]), "");
204+
205+
return changelog;
206+
}
207+
208+
public static String getUrlAsString(URL u) throws IOException {
209+
try (final var in = u.openStream()) {
210+
return new String(in.readAllBytes(), StandardCharsets.UTF_8);
211+
}
212+
}
163213
}

src/core/java/com/mcmoddev/mmdbot/core/database/VersionedDatabase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
import java.io.FileReader;
2828
import java.io.IOException;
29+
import java.nio.charset.StandardCharsets;
30+
import java.nio.file.Files;
2931
import java.nio.file.Path;
3032

3133
/**
@@ -81,7 +83,7 @@ public static <T> VersionedDatabase<T> fromFile(Gson gson, Path filePath, java.l
8183
* @throws IOException if an exception occurred reading the file
8284
*/
8385
public static <T> VersionedDatabase<T> fromFile(Gson gson, Path filePath, java.lang.reflect.Type dataType, int defaultSchemaVersion, T defaultValue) throws IOException {
84-
try (final var reader = new FileReader(filePath.toFile())) {
86+
try (final var reader = Files.newBufferedReader(filePath, StandardCharsets.UTF_8)) {
8587
final var json = gson.fromJson(reader, JsonObject.class);
8688
if (json == null || !json.has(DATA_TAG)) {
8789
return new VersionedDatabase<>(defaultSchemaVersion, defaultValue);

src/core/java/com/mcmoddev/mmdbot/core/util/event/DismissListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*/
3838
public final class DismissListener extends ListenerAdapter {
3939

40-
public static final Supplier<Button> BUTTON_FACTORY = LazySupplier.of(() -> Button.primary("dismiss", " Dismiss"));
40+
public static final Supplier<Button> BUTTON_FACTORY = LazySupplier.of(() -> Button.secondary("dismiss", "\uD83D\uDEAE Dismiss"));
4141

4242
@Override
4343
public void onButtonInteraction(@javax.annotation.Nonnull final ButtonInteractionEvent event) {

src/test/java/com/mcmoddev/mmdbot/tests/ComponentsTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package com.mcmoddev.mmdbot.tests;
2222

2323
import com.mcmoddev.mmdbot.core.commands.component.Component;
24+
import com.mcmoddev.mmdbot.core.commands.component.storage.ComponentStorage;
2425
import com.mcmoddev.mmdbot.core.commands.component.storage.SQLComponentStorage;
2526
import org.flywaydb.core.Flyway;
2627
import org.jdbi.v3.core.Jdbi;
@@ -36,7 +37,7 @@
3637
import java.util.UUID;
3738

3839
public class ComponentsTest {
39-
static SQLComponentStorage storage;
40+
static ComponentStorage storage;
4041

4142
@Test
4243
void testFeatureIdIsSame() {
@@ -74,7 +75,7 @@ static void setupStorage() throws IOException {
7475
.load();
7576
flyway.migrate();
7677

77-
storage = new SQLComponentStorage(Jdbi.create(dataSource), "components");
78+
storage = ComponentStorage.sql(Jdbi.create(dataSource), "components");
7879
}
7980

8081
}

src/watcher/java/com/mcmoddev/mmdbot/thewatcher/TheWatcher.java

Lines changed: 0 additions & 155 deletions
This file was deleted.

src/watcher/java/com/mcmoddev/mmdbot/thewatcher/package-info.java

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)