Skip to content

Commit

Permalink
Ensure dynamic button labels don't go past 80 characters (Discord limit)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vauff committed Sep 5, 2022
1 parent 79b0028 commit fbda6ac
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,5 @@
<version>4.7.1</version>
</dependency>
</dependencies>
<version>r50</version>
<version>r51</version>
</project>
2 changes: 1 addition & 1 deletion src/com/vauff/maunzdiscord/commands/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private void runSelection(DeferrableInteractionEvent event, User user, int page)
for (Document doc : services)
{
Document serverDoc = Main.mongoDatabase.getCollection("servers").find(eq("_id", doc.getObjectId("serverID"))).first();
servers.add(Button.primary(doc.getObjectId("_id").toString(), serverDoc.getString("name")));
servers.add(Button.primary(doc.getObjectId("_id").toString(), StringUtils.substring(serverDoc.getString("name"), 0, 80)));
}

buildPage(event, servers, "Select Server", 8, 2, page, 0, false, null, "");
Expand Down
8 changes: 4 additions & 4 deletions src/com/vauff/maunzdiscord/commands/Notify.java
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,16 @@ else if (interaction.getOption("toggle").isPresent())

if (mapSuggestion.equals(""))
{
buttons.add(Button.success("confirm-" + mapArg, "Add " + mapArg));
buttons.add(Button.success("confirm-" + mapArg, StringUtils.substring("Add " + mapArg, 0, 80)));
buttons.add(Button.danger("cancel-notify", "Cancel"));

Util.editReply(event, "The map **" + mapArg.replace("_", "\\_") + "** is not in my maps database, are you sure you'd like to add it?", ActionRow.of(buttons));
waitForButtonPress(event.getReply().block().getId(), user.getId());
}
else
{
buttons.add(Button.primary("confirm-" + mapSuggestion, mapSuggestion));
buttons.add(Button.primary("confirm-" + mapArg, mapArg));
buttons.add(Button.primary("confirm-" + mapSuggestion, StringUtils.substring(mapSuggestion, 0, 80)));
buttons.add(Button.primary("confirm-" + mapArg, StringUtils.substring(mapArg, 0, 80)));

Util.editReply(event, "The map **" + mapArg.replace("_", "\\_") + "** is not in my maps database (did you maybe mean **" + mapSuggestion.replace("_", "\\_") + "** instead?), please select which map you would like to choose", ActionRow.of(buttons));
waitForButtonPress(event.getReply().block().getId(), user.getId());
Expand All @@ -356,7 +356,7 @@ private void runSelection(DeferrableInteractionEvent event, User user, int page)
for (Document doc : services)
{
Document serverDoc = Main.mongoDatabase.getCollection("servers").find(eq("_id", doc.getObjectId("serverID"))).first();
servers.add(Button.primary(doc.getObjectId("_id").toString(), serverDoc.getString("name")));
servers.add(Button.primary(doc.getObjectId("_id").toString(), StringUtils.substring(serverDoc.getString("name"), 0, 80)));
}

buildPage(event, servers, "Select Server", 8, 2, page, 0, false, null, SELECTION_BTN_SUFFIX);
Expand Down
3 changes: 2 additions & 1 deletion src/com/vauff/maunzdiscord/commands/Players.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import discord4j.core.object.entity.channel.PrivateChannel;
import discord4j.discordjson.json.ApplicationCommandRequest;
import discord4j.rest.http.client.ClientException;
import org.apache.commons.lang3.StringUtils;
import org.bson.Document;

import java.util.ArrayList;
Expand Down Expand Up @@ -158,7 +159,7 @@ private void runSelection(DeferrableInteractionEvent event, User user, int page)
for (Document doc : services)
{
Document serverDoc = Main.mongoDatabase.getCollection("servers").find(eq("_id", doc.getObjectId("serverID"))).first();
servers.add(Button.primary(doc.getObjectId("_id").toString(), serverDoc.getString("name")));
servers.add(Button.primary(doc.getObjectId("_id").toString(), StringUtils.substring(serverDoc.getString("name"), 0, 80)));
}

buildPage(event, servers, "Select Server", 8, 2, page, 0, false, null, "");
Expand Down
2 changes: 1 addition & 1 deletion src/com/vauff/maunzdiscord/core/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Main
{
public static GatewayDiscordClient gateway;
public static MongoDatabase mongoDatabase;
public static String version = "r50";
public static String version = "r51";
public static Config cfg;

/**
Expand Down
12 changes: 5 additions & 7 deletions src/com/vauff/maunzdiscord/core/Util.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.vauff.maunzdiscord.core;

import discord4j.core.event.domain.interaction.DeferrableInteractionEvent;
import discord4j.core.object.Embed;
import discord4j.core.object.component.LayoutComponent;
import discord4j.core.object.entity.Guild;
import discord4j.core.object.entity.Message;
Expand All @@ -26,7 +25,6 @@
import java.io.File;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
import java.util.Random;
Expand Down Expand Up @@ -128,9 +126,9 @@ public static void editReply(DeferrableInteractionEvent event, String message, I
/**
* Edits a reply to an interaction
*
* @param event The event that should have its reply edited
* @param message String content of the reply
* @param embeds Embeds the reply should contain
* @param event The event that should have its reply edited
* @param message String content of the reply
* @param embeds Embeds the reply should contain
* @return The message object
*/
public static void editReply(DeferrableInteractionEvent event, String message, EmbedCreateSpec... embeds)
Expand All @@ -141,8 +139,8 @@ public static void editReply(DeferrableInteractionEvent event, String message, E
/**
* Edits a reply to an interaction
*
* @param event The event that should have its reply edited
* @param message String content of the reply
* @param event The event that should have its reply edited
* @param message String content of the reply
* @param components LayoutComponents the reply should contain
* @return The message object
*/
Expand Down

0 comments on commit fbda6ac

Please sign in to comment.