Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/org/geysermc/discordbot/GeyserBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public static void main(String[] args) throws IOException {
new AutoModHandler(),
new ExploitHandler(),
new WebhookLinkPreviewHandler(),
new ReadyListener(),
client.build(),
tagClient.build())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.geysermc.discordbot.GeyserBot;
import org.geysermc.discordbot.storage.ServerSettings;
import org.geysermc.discordbot.util.BotColors;
import org.geysermc.discordbot.util.BotEmojis;
import org.kohsuke.github.GHPullRequest;

import javax.annotation.Nonnull;
Expand All @@ -48,6 +49,7 @@

public class PreviewHandler extends ListenerAdapter {
private static final Pattern GH_PR_PATTERN = Pattern.compile("https://github\\.com/GeyserMC/(.+)/pull/(\\d+)");
private static final String DOWNLOAD_LINK_TEMPLATE = "https://download.geysermc.org/v2/projects/geyserpreview/versions/pr.%s/builds/latest/downloads/%s";

@Override
public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
Expand Down Expand Up @@ -82,8 +84,13 @@ public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
return;
}

String title = pullRequest.getTitle();
if (title.length() > 100) {
title = title.substring(0, 97) + "...";
}

previewChannel.createForumPost(
pullRequest.getTitle(),
title,
MessageCreateData.fromEmbeds(new EmbedBuilder()
.setTitle(pullRequest.getTitle())
.setColor(BotColors.SUCCESS.getColor())
Expand All @@ -101,13 +108,48 @@ public void onMessageReceived(@Nonnull MessageReceivedEvent event) {
Button.link(pullRequest.getHtmlUrl() + "/checks", "Download Artifacts")
.withEmoji(Emoji.fromUnicode("\ud83d\udce6"))))
.queue(forumPost -> {
// Make the ActionRows containing all downloads
ActionRow downloadRow1 = ActionRow.of(
Button.link(DOWNLOAD_LINK_TEMPLATE.formatted(pr, "bungeecord"), "Bungeecord")
.withEmoji(BotEmojis.WATERFALL.get()),
Button.link(DOWNLOAD_LINK_TEMPLATE.formatted(pr, "fabric"), "Fabric")
.withEmoji(BotEmojis.FABRIC.get()),
Button.link(DOWNLOAD_LINK_TEMPLATE.formatted(pr, "neoforge"), "NeoForge")
.withEmoji(BotEmojis.NEOFORGE.get()),
Button.link(DOWNLOAD_LINK_TEMPLATE.formatted(pr, "spigot"), "Spigot")
.withEmoji(BotEmojis.PAPER.get()),
Button.link(DOWNLOAD_LINK_TEMPLATE.formatted(pr, "standalone"), "Standalone")
.withEmoji(BotEmojis.GEYSER.get())
);

ActionRow downloadRow2 = ActionRow.of(
Button.link(DOWNLOAD_LINK_TEMPLATE.formatted(pr, "velocity"), "Velocity")
.withEmoji(BotEmojis.VELOCITY.get()),
Button.link(DOWNLOAD_LINK_TEMPLATE.formatted(pr, "viaproxy"), "ViaProxy")
.withEmoji(BotEmojis.VIAPROXY.get())
);

// Reply to the original message with the link to the forum post
event.getMessage().replyEmbeds(new EmbedBuilder()
.setColor(BotColors.SUCCESS.getColor())
.setDescription("The above preview can be discussed in:\n### <#"
+ forumPost.getMessage().getId() + ">")
.setTimestamp(Instant.now())
.build()).queue();
.build())
.addComponents(downloadRow1, downloadRow2)
.queue();

// Send a message containing the download links and then pin it
forumPost.getMessage().replyEmbeds(new EmbedBuilder()
.setColor(BotColors.SUCCESS.getColor())
.setTitle("Downloads")
.setDescription("The download links for this preview can be found below")
.setTimestamp(Instant.now())
.build())
.addComponents(downloadRow1, downloadRow2)
.queue(message ->
forumPost.getThreadChannel().pinMessageById(message.getIdLong()).queue()
);
});

// Remove embeds from the original message
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/org/geysermc/discordbot/listeners/ReadyListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2026 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/GeyserDiscordBot
*/

package org.geysermc.discordbot.listeners;

import net.dv8tion.jda.api.events.session.ReadyEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.geysermc.discordbot.util.BotEmojis;
import org.jetbrains.annotations.NotNull;

public class ReadyListener extends ListenerAdapter {
@Override
public void onReady(@NotNull ReadyEvent event) {
BotEmojis.init(event.getJDA());
}
}
59 changes: 59 additions & 0 deletions src/main/java/org/geysermc/discordbot/util/BotEmojis.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2026 GeyserMC. http://geysermc.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @author GeyserMC
* @link https://github.com/GeyserMC/GeyserDiscordBot
*/

package org.geysermc.discordbot.util;

import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.entities.emoji.ApplicationEmoji;
import net.dv8tion.jda.api.entities.emoji.Emoji;

import java.util.EnumMap;
import java.util.Locale;
import java.util.stream.Collectors;

public enum BotEmojis {
// Platforms
FABRIC,
GEYSER,
NEOFORGE,
PAPER,
VELOCITY,
VIAPROXY,
WATERFALL;

private static final EnumMap<BotEmojis, ApplicationEmoji> EMOJI_MAP = new EnumMap<>(BotEmojis.class);

public static void init(JDA jda) {
jda.retrieveApplicationEmojis().queue(emojis -> {
for (BotEmojis emoji : values()) {
EMOJI_MAP.put(emoji, emojis.stream().filter(e -> e.getName().equals(emoji.name().toLowerCase(Locale.ROOT))).findFirst().get());
}
});
}

public Emoji get() {
return EMOJI_MAP.get(this);
}
}