From b451a3828203eb54915a6b7f3629088d4790c6ff Mon Sep 17 00:00:00 2001 From: test Date: Tue, 25 Jun 2024 17:04:57 +1000 Subject: [PATCH 1/6] Add search and read mail slash --- .../discord/commands/account/CheckMail.java | 25 ++-- .../manager/v2/impl/pw/CommandManager2.java | 2 + .../v2/impl/pw/commands/IACommands.java | 132 +++++++++++++++++- .../commands/manager/v2/impl/pw/refs/CM.java | 62 ++++++++ .../discord/util/task/mail/ReadMailTask.java | 100 +++++++++++++ .../util/task/mail/SearchMailTask.java | 18 +-- 6 files changed, 310 insertions(+), 29 deletions(-) create mode 100644 src/main/java/link/locutus/discord/util/task/mail/ReadMailTask.java diff --git a/src/main/java/link/locutus/discord/commands/account/CheckMail.java b/src/main/java/link/locutus/discord/commands/account/CheckMail.java index 18f0094d..450b62c3 100644 --- a/src/main/java/link/locutus/discord/commands/account/CheckMail.java +++ b/src/main/java/link/locutus/discord/commands/account/CheckMail.java @@ -51,21 +51,13 @@ public String onCommand(Guild guild, IMessageIO channel, User author, DBNation m channel.sendMessage("Please wait..."); GuildDB db = Locutus.imp().getGuildDB(guild); - SpreadSheet sheet = SpreadSheet.create(db, SheetKey.MAIL_RESPONSES_SHEET); - - List header = new ArrayList<>(Arrays.asList( - "nation", - "alliance", - "mail-id", - "subject", - "response" - )); - sheet.setHeader(header); boolean checkUnread = Boolean.parseBoolean(args.get(1)); boolean checkRead = Boolean.parseBoolean(args.get(2)); boolean readContent = Boolean.parseBoolean(args.get(3)); + boolean group = flags.contains('g'); + boolean count = flags.contains('c'); Map>> results = new LinkedHashMap<>(); @@ -77,8 +69,17 @@ public String onCommand(Guild guild, IMessageIO channel, User author, DBNation m }); task.call(); - boolean group = flags.contains('g'); - boolean count = flags.contains('g'); + SpreadSheet sheet = SpreadSheet.create(db, SheetKey.MAIL_RESPONSES_SHEET); + + List header = new ArrayList<>(Arrays.asList( + "nation", + "alliance", + "mail-id", + "subject", + "response" + )); + + sheet.setHeader(header); List row = new ArrayList<>(); for (Map.Entry>> entry : results.entrySet()) { diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/CommandManager2.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/CommandManager2.java index e0028c76..241b527a 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/CommandManager2.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/CommandManager2.java @@ -380,6 +380,8 @@ public CommandManager2 registerDefaults() { this.commands.registerMethod(new BankCommands(), List.of("escrow"), "escrowSheetCmd", "view_sheet"); this.commands.registerMethod(new IACommands(), List.of("nation", "list"), "viewBans", "bans"); + this.commands.registerMethod(new IACommands(), List.of("mail"), "readMail", "read"); + this.commands.registerMethod(new IACommands(), List.of("mail"), "searchMail", "search"); this.commands.registerMethod(new AdminCommands(), List.of("admin", "sync"), "importLinkedBans", "multi_bans"); diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java index c1bb9021..390fb209 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java @@ -48,6 +48,9 @@ import link.locutus.discord.util.sheet.SpreadSheet; import link.locutus.discord.util.task.MailRespondTask; import link.locutus.discord.util.task.ia.IACheckup; +import link.locutus.discord.util.task.mail.Mail; +import link.locutus.discord.util.task.mail.ReadMailTask; +import link.locutus.discord.util.task.mail.SearchMailTask; import link.locutus.discord.web.jooby.handler.CommandResult; import com.google.gson.JsonObject; import link.locutus.discord.apiv1.enums.Rank; @@ -1212,12 +1215,131 @@ public String reply(@Me GuildDB db, @Me DBNation me, @Me User author, @Me IMessa return "Mail: " + result; } -// @Command(desc = "Read a message for an id") -// @RolePermission(Roles.MAIL) -// @IsAlliance -// public String viewMail(@Me ) + @Command(desc = "Read and display an in-game message for an id from a nation's account\n" + + "The nation must be your own or in the same alliance\n" + + "Login details via `{prefix}credentials login`\n") + @RolePermission(Roles.MAIL) + @IsAlliance + public String readMail(@Me DBNation me, @Me GuildDB db, int message_id, @Default DBNation account) throws Exception { + if (account == null) account = me; + if (me.getId() != account.getId()) { + if (!db.isAllianceId(account.getAlliance_id())) return "Nation is not a member of the alliance"; + } + Auth auth = account.getAuth(true); + + List msgs = new ReadMailTask(auth, message_id).call(); + if (msgs.isEmpty()) { + return "No messages found for " + account.getMarkdownUrl() + " with id `" + message_id + "`. Ensure the `account` is correct and the message is not more than 30 days old"; + } + StringBuilder response = new StringBuilder(); + for (ReadMailTask.MailMessage msg : msgs) { + response.append("**__" + PW.getMarkdownUrl(msg.getNationId(), false) + "__**" + DiscordUtil.timestamp(msg.getDate(), null) + "\n"); + response.append(msg.getContent()).append("\n\n"); + } + return response.toString(); + } + + // + @Command(desc = "Show ingame mail and optionally the responses\n" + + "Results are in a spreadsheet\n" + + "A search term can be specified to only show messages containing that in the subject line\n" + + "By default only unread messages are checked") + @IsAlliance + public String searchMail(@Me GuildDB db, @Me IMessageIO io, + @Me DBNation me, + @Arg("The account to check the mail of\n" + + "Defaults to your own nation") + @Default DBNation account, + @Arg("The term to search for\n" + + "Defaults to show all messages") + @Switch("q") String search_for, + @Arg("Don't search unread messages\n" + + "Defaults to false") + @Switch("u") boolean skip_unread, + @Switch("r") boolean check_read, + @Switch("c") boolean read_content, + @Arg("If responses are grouped by nation") + @Switch("g") boolean group_by_nation, + @Arg("If responses are counted") + @Switch("n") boolean count_replies + ) throws Exception { + if (account == null) account = me; + if (me.getId() != account.getId()) { + if (!db.isAllianceId(account.getAlliance_id())) return "Nation is not a member of the alliance"; + } + Auth auth = account.getAuth(true); + + if (skip_unread) { + check_read = true; + } + Map>> results = new LinkedHashMap<>(); + SearchMailTask task = new SearchMailTask(auth, search_for, !skip_unread, check_read, read_content, (mail, strings) -> { + DBNation nation = Locutus.imp().getNationDB().getNation(mail.nationId); + if (nation != null) { + results.computeIfAbsent(nation, f -> new LinkedHashMap<>()).put(mail, strings); + } + }); + task.call(); + + SpreadSheet sheet = SpreadSheet.create(db, SheetKey.MAIL_RESPONSES_SHEET); - // todo add mail search SearchMailTask + List header = new ArrayList<>(Arrays.asList( + "nation", + "alliance", + "mail-id", + "subject", + "response" + )); + + sheet.setHeader(header); + + List row = new ArrayList<>(); + for (Map.Entry>> entry : results.entrySet()) { + row.clear(); + DBNation nation = entry.getKey(); + + int countVal = 0; + for (Map.Entry> mailListEntry : entry.getValue().entrySet()) { + if (!group_by_nation) row.clear(); + + Mail mail = mailListEntry.getKey(); + List strings = mailListEntry.getValue(); + + if (row.isEmpty()) { + int allianceId = nation != null ? nation.getAlliance_id() : 0; + row.add(MarkupUtil.sheetUrl(PW.getName(mail.nationId, false), PW.getUrl(mail.nationId, false))); + row.add(MarkupUtil.sheetUrl(PW.getName(allianceId, true), PW.getUrl(allianceId, true))); + row.add(mail.id + ""); + row.add(mail.subject); + } + + if (count_replies) { + strings.removeIf(f -> f.equalsIgnoreCase("false")); + if (group_by_nation) { + countVal += strings.size(); + } else { + row.add(strings.size()); + } + } else { + row.addAll(strings); + } + + if (!group_by_nation) sheet.addRow(row); + } + if (group_by_nation) { + if (count_replies) { + row.add(countVal); + } + sheet.addRow(row); + } + } + + sheet.updateClearCurrentTab(); + sheet.updateWrite(); + + sheet.attach(io.create(), "mail", null, false, 0).send(); + return null; + } @Command(desc = "Generate a list of nations and their expected raid loot\n" + "e.g. `{prefix}sheets_milcom lootvaluesheet #cities<10,#position>1,#active_m<2880,someAlliance`") diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/refs/CM.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/refs/CM.java index 9fae563a..2cd2b4c8 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/refs/CM.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/refs/CM.java @@ -3264,6 +3264,24 @@ public button labels(String value) { } } + public static class rename{ + @AutoRegister(clazz=link.locutus.discord.commands.manager.v2.impl.pw.commands.EmbedCommands.class,method="renameButton") + public static class button extends CommandRef { + public static final button cmd = new button(); + public button message(String value) { + return set("message", value); + } + + public button label(String value) { + return set("label", value); + } + + public button rename_to(String value) { + return set("rename_to", value); + } + + } + } public static class template{ @AutoRegister(clazz=link.locutus.discord.commands.manager.v2.impl.pw.commands.EmbedCommands.class,method="allyEnemySheets") public static class ally_enemy_sheets extends CommandRef { @@ -4805,6 +4823,18 @@ public command skipMail(String value) { return set("skipMail", value); } + } + @AutoRegister(clazz=link.locutus.discord.commands.manager.v2.impl.pw.commands.IACommands.class,method="readMail") + public static class read extends CommandRef { + public static final read cmd = new read(); + public read messageId(String value) { + return set("messageId", value); + } + + public read account(String value) { + return set("account", value); + } + } @AutoRegister(clazz=link.locutus.discord.commands.manager.v2.impl.pw.commands.AdminCommands.class,method="testRecruitMessage") public static class recruit extends CommandRef { @@ -4830,6 +4860,38 @@ public reply sender(String value) { return set("sender", value); } + } + @AutoRegister(clazz=link.locutus.discord.commands.manager.v2.impl.pw.commands.IACommands.class,method="searchMail") + public static class search extends CommandRef { + public static final search cmd = new search(); + public search account(String value) { + return set("account", value); + } + + public search search_for(String value) { + return set("search_for", value); + } + + public search skip_unread(String value) { + return set("skip_unread", value); + } + + public search check_read(String value) { + return set("check_read", value); + } + + public search read_content(String value) { + return set("read_content", value); + } + + public search group_by_nation(String value) { + return set("group_by_nation", value); + } + + public search count_replies(String value) { + return set("count_replies", value); + } + } @AutoRegister(clazz=link.locutus.discord.commands.manager.v2.impl.pw.commands.IACommands.class,method="mail") public static class send extends CommandRef { diff --git a/src/main/java/link/locutus/discord/util/task/mail/ReadMailTask.java b/src/main/java/link/locutus/discord/util/task/mail/ReadMailTask.java new file mode 100644 index 00000000..a574c2fb --- /dev/null +++ b/src/main/java/link/locutus/discord/util/task/mail/ReadMailTask.java @@ -0,0 +1,100 @@ +package link.locutus.discord.util.task.mail; + +import link.locutus.discord.config.Settings; +import link.locutus.discord.util.MarkupUtil; +import link.locutus.discord.util.PW; +import link.locutus.discord.util.io.PagePriority; +import link.locutus.discord.util.offshore.Auth; +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + +public class ReadMailTask implements Callable> { + private final Auth auth; + private final int id; + + public ReadMailTask(Auth auth, int id) { + this.auth = auth; + this.id = id; + } + + /** + * Returns a list of messages in the mail with true being for received and false being sent + * @return + * @throws Exception + */ + @Override + public List call() throws Exception { + return PW.withLogin(() -> { + String url = Settings.INSTANCE.PNW_URL() + "/inbox/message/id=" + id; + Document msgDom = Jsoup.parse(auth.readStringFromURL(PagePriority.MAIL_READ, url, Collections.emptyMap())); + Elements messages = msgDom.select(".red-msg, .blue-msg"); + + List messagesColor = new ArrayList<>(); + + for (Element message : messages) { + messagesColor.add(new MailMessage(message)); + } + + return messagesColor; + }, auth); + } + + public static class MailMessage { + private final String content; + private final boolean isReceived; + private final long date; + private final int nationId; + + public MailMessage(Element message) { + + + this.isReceived = message.hasClass("red-msg"); + Element secondChild = message.child(1); + // html to markdown + this.content = MarkupUtil.htmlToMarkdown(message.text()); + + // first child has header, get it and then parse it to get the date, nationId + // the nationId is from the first a link within the child (not a direct descendent, use a selector to get the first) + // the date string is the only text not in a span tag, parse it, it's in the form `06/20/2024 Thursday 9:48 am` + // i assume the day name e.g. `Thursday` can be ignored and just the month/day/year and time is needed + Element header = secondChild.child(0); + // get the nation id + Element nationLink = header.selectFirst("a"); + String nationIdStr = nationLink.attr("href").split("=")[1]; + this.nationId = Integer.parseInt(nationIdStr); + String dateStr = header.textNodes().get(0).text().trim(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd/yyyy EEEE h:mm a"); + LocalDateTime dateTime = LocalDateTime.parse(dateStr, formatter); + Instant instant = dateTime.atZone(ZoneOffset.UTC).toInstant(); + this.date = instant.toEpochMilli(); + } + + public String getContent() { + return content; + } + + public boolean isReceived() { + return isReceived; + } + + public long getDate() { + return date; + } + + public int getNationId() { + return nationId; + } + } +} diff --git a/src/main/java/link/locutus/discord/util/task/mail/SearchMailTask.java b/src/main/java/link/locutus/discord/util/task/mail/SearchMailTask.java index 0b78383a..2b8ca893 100644 --- a/src/main/java/link/locutus/discord/util/task/mail/SearchMailTask.java +++ b/src/main/java/link/locutus/discord/util/task/mail/SearchMailTask.java @@ -14,10 +14,7 @@ import org.jsoup.select.Elements; import java.net.URLEncoder; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; +import java.util.*; import java.util.concurrent.Callable; import java.util.function.BiConsumer; import java.util.function.Predicate; @@ -117,14 +114,11 @@ public List call() throws Exception { List messagesStr = new ArrayList<>(); if (readContent) { - Document msgDom = Jsoup.parse(auth.readStringFromURL(PagePriority.MAIL_READ, url, Collections.emptyMap())); - Elements messages = msgDom.select(".red-msg"); - - for (Element message : messages) { - message.child(0).remove(); - String firstMsg = message.text(); - String msgMarkdown = MarkupUtil.htmlToMarkdown(firstMsg); - messagesStr.add(msgMarkdown); + List replies = new ReadMailTask(auth, msgId).call(); + for (ReadMailTask.MailMessage reply : replies) { + if (reply.isReceived()) { + messagesStr.add(reply.getContent()); + } } } else { messagesStr.add("" + recRead); From 8b0b5e1c434cf0c304388baf6dd8ee3d259af19d Mon Sep 17 00:00:00 2001 From: test Date: Tue, 25 Jun 2024 17:13:14 +1000 Subject: [PATCH 2/6] Dismiss --- src/main/java/link/locutus/discord/Locutus.java | 4 ++++ .../commands/manager/v2/command/IMessageBuilder.java | 5 +++++ .../manager/v2/impl/pw/commands/EmbedCommands.java | 12 ++++++------ .../manager/v2/impl/pw/commands/IACommands.java | 3 +-- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/link/locutus/discord/Locutus.java b/src/main/java/link/locutus/discord/Locutus.java index db630097..c93cfc4d 100644 --- a/src/main/java/link/locutus/discord/Locutus.java +++ b/src/main/java/link/locutus/discord/Locutus.java @@ -1144,6 +1144,10 @@ public void onButtonInteraction(@NotNull ButtonInteractionEvent event) { Button button = event.getButton(); System.out.println("Button press " + button.getId() + " | " + button.getLabel()); + if (button.getId().equalsIgnoreCase(" ") && message != null) { + RateLimitUtil.queue(message.delete()); + return; + } if (message.getAuthor().getIdLong() != Settings.INSTANCE.APPLICATION_ID) { System.out.println("Author not application"); diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/command/IMessageBuilder.java b/src/main/java/link/locutus/discord/commands/manager/v2/command/IMessageBuilder.java index 07cde9ce..2dbd0dbb 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/command/IMessageBuilder.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/command/IMessageBuilder.java @@ -356,6 +356,11 @@ default IMessageBuilder cancelButton() { return commandButton(CommandBehavior.DELETE_MESSAGE, " ", "Cancel"); } + @CheckReturnValue + default IMessageBuilder cancelButton(String label) { + return commandButton(CommandBehavior.DELETE_MESSAGE, " ", label); + } + @CheckReturnValue default IMessageBuilder file(String name, String data) { return file(name, data.getBytes(StandardCharsets.UTF_8)); diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java index d652dc0e..27e969a2 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java @@ -99,7 +99,7 @@ public String title(@Me User user, @Me IMessageIO io, @Me Guild guild, Message d message.clearEmbeds(); message.embed(builder.build()); message.send(); - io.create().embed("Set Title", "Done! See: " + discMessage.getJumpUrl()).cancelButton().send(); + io.create().embed("Set Title", "Done! See: " + discMessage.getJumpUrl()).cancelButton("Dismiss").send(); return null; } @@ -118,7 +118,7 @@ public String description(@Me User user, @Me IMessageIO io, @Me Guild guild, Mes message.clearEmbeds(); message.embed(builder.build()); message.send(); - io.create().embed("Set Description", "Done! See: " + discMessage.getJumpUrl()).cancelButton().send(); + io.create().embed("Set Description", "Done! See: " + discMessage.getJumpUrl()).cancelButton("Dismiss").send(); return null; } @@ -157,7 +157,7 @@ public String renameButton(@Me User user, @Me IMessageIO io, @Me Guild guild, @M } msg.send(); io.create().embed("Deleted Button", "Done! Renamed button `" + label + "` to " + rename_to + "\n" + - "Remove it using: " + CM.embed.remove.button.cmd.toSlashMention()).cancelButton().send(); + "Remove it using: " + CM.embed.remove.button.cmd.toSlashMention()).cancelButton("Dismiss").send(); return null; } @@ -194,7 +194,7 @@ public String removeButton(@Me User user, @Me IMessageIO io, @Me Guild guild, Me } RateLimitUtil.queue(message.editMessageComponents(rows)); - io.create().embed("Deleted Button", "Done! Deleted " + labels.size() + " buttons").cancelButton().send(); + io.create().embed("Deleted Button", "Done! Deleted " + labels.size() + " buttons").cancelButton("Dismiss").send(); return null; } @@ -235,7 +235,7 @@ public String addButtonRaw(@Me User user, @Me IMessageIO io, @Me JSONObject cmdJ .send(); io.create().embed("Added Button", "Added button `" + label + "` to " + message.getJumpUrl() + "\n" + "Remove it using: " + CM.embed.remove.button.cmd.toSlashMention() + "\n" + - "Rename using TODO CM REF").cancelButton().send();// + CM.embed.rename.button.cmd.toSlashMention(); + "Rename using TODO CM REF").cancelButton("Dismiss").send();// + CM.embed.rename.button.cmd.toSlashMention(); return null; } @@ -327,7 +327,7 @@ public String addModal(@Me User user, @Me IMessageIO io, @Me Guild guild, Messag new DiscordMessageBuilder(message.getChannel(), message) .modal(behavior, channelId, command, full, label) .send(); - io.create().embed("Added Modal", "Added modal button `" + label + "` to " + message.getJumpUrl()).cancelButton().send(); + io.create().embed("Added Modal", "Added modal button `" + label + "` to " + message.getJumpUrl()).cancelButton("Dismiss").send(); return null; } diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java index 390fb209..7c09f8e4 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/IACommands.java @@ -1217,7 +1217,7 @@ public String reply(@Me GuildDB db, @Me DBNation me, @Me User author, @Me IMessa @Command(desc = "Read and display an in-game message for an id from a nation's account\n" + "The nation must be your own or in the same alliance\n" + - "Login details via `{prefix}credentials login`\n") + "Login details via `{prefix}credentials login`") @RolePermission(Roles.MAIL) @IsAlliance public String readMail(@Me DBNation me, @Me GuildDB db, int message_id, @Default DBNation account) throws Exception { @@ -1239,7 +1239,6 @@ public String readMail(@Me DBNation me, @Me GuildDB db, int message_id, @Default return response.toString(); } - // @Command(desc = "Show ingame mail and optionally the responses\n" + "Results are in a spreadsheet\n" + "A search term can be specified to only show messages containing that in the subject line\n" + From e932cdd13fb05b710ed3e91b8f2e478c8a889f80 Mon Sep 17 00:00:00 2001 From: test Date: Wed, 26 Jun 2024 10:55:43 +1000 Subject: [PATCH 3/6] Mail read --- .../v2/impl/discord/DiscordMessageBuilder.java | 2 +- .../manager/v2/impl/pw/commands/EmbedCommands.java | 12 ++++++++++-- .../locutus/discord/util/update/MailListener.java | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/discord/DiscordMessageBuilder.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/discord/DiscordMessageBuilder.java index 7a2ce734..c8f17938 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/discord/DiscordMessageBuilder.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/discord/DiscordMessageBuilder.java @@ -307,7 +307,7 @@ public IMessageBuilder commandButton(String command, String message) { command = id + ""; remapLongCommands.put(command, cmdLong); } - if (message.equalsIgnoreCase("cancel")) { + if (message.equalsIgnoreCase("cancel") || message.equalsIgnoreCase("dismiss")) { buttons.add(Button.danger(command, message)); } else { buttons.add(Button.primary(command, message)); diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java index 27e969a2..80dad924 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java @@ -152,8 +152,16 @@ public String renameButton(@Me User user, @Me IMessageIO io, @Me Guild guild, @M DiscordMessageBuilder msg = new DiscordMessageBuilder(message.getChannel(), message); msg.clearButtons(); - for (Map.Entry entry : reactions.entrySet()) { - msg.commandButton(entry.getValue(), entry.getKey()); + + if (reactions != null) { + for (Map.Entry entry : reactions.entrySet()) { + msg.commandButton(entry.getValue(), entry.getKey()); + } + } + for (Button button : message.getButtons()) { + if (!button.getId().equalsIgnoreCase(button.getLabel())) { + msg.commandButton(button.getId(), button.getLabel()); + } } msg.send(); io.create().embed("Deleted Button", "Done! Renamed button `" + label + "` to " + rename_to + "\n" + diff --git a/src/main/java/link/locutus/discord/util/update/MailListener.java b/src/main/java/link/locutus/discord/util/update/MailListener.java index 69ea0b9b..e1691ef5 100644 --- a/src/main/java/link/locutus/discord/util/update/MailListener.java +++ b/src/main/java/link/locutus/discord/util/update/MailListener.java @@ -91,6 +91,8 @@ public void onMailReceived(MailReceivedEvent event) throws IOException { DBNation receiver = Locutus.imp().getNationDB().getNationByLeader(event.getMail().leader); CM.mail.reply mailCmd = CM.mail.reply.cmd.receiver(receiver.getId() + "").url(event.getUrl()).message("").sender(event.getAuth().getNationId() + ""); builder.modal(CommandBehavior.DELETE_PRESSED_BUTTON, mailCmd, "\uD83D\uDCE7 Reply"); + + builder.commandButton(CM.mail.read.cmd.messageId(event.getMail().id + "").account(receiver.getId() + ""), "Read"); builder.send(); processCommands(Locutus.imp().getGuildDB(guild), guild, outputBuilder, event); From fe959f3e40e53f8f09fa43450be3daeabf063de5 Mon Sep 17 00:00:00 2001 From: test Date: Wed, 26 Jun 2024 11:02:22 +1000 Subject: [PATCH 4/6] Update EmbedCommands.java --- .../commands/manager/v2/impl/pw/commands/EmbedCommands.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java index 80dad924..19fedb74 100644 --- a/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java +++ b/src/main/java/link/locutus/discord/commands/manager/v2/impl/pw/commands/EmbedCommands.java @@ -155,16 +155,16 @@ public String renameButton(@Me User user, @Me IMessageIO io, @Me Guild guild, @M if (reactions != null) { for (Map.Entry entry : reactions.entrySet()) { - msg.commandButton(entry.getValue(), entry.getKey()); + msg.commandButton(entry.getValue(), entry.getKey().equalsIgnoreCase(label) ? rename_to : entry.getKey()); } } for (Button button : message.getButtons()) { if (!button.getId().equalsIgnoreCase(button.getLabel())) { - msg.commandButton(button.getId(), button.getLabel()); + msg.commandButton(button.getId(), button.getLabel().equalsIgnoreCase(label) ? rename_to : button.getLabel()); } } msg.send(); - io.create().embed("Deleted Button", "Done! Renamed button `" + label + "` to " + rename_to + "\n" + + io.create().embed("Renamed Button", "Done! Renamed button `" + label + "` to " + rename_to + "\n" + "Remove it using: " + CM.embed.remove.button.cmd.toSlashMention()).cancelButton("Dismiss").send(); return null; } From a0e24529369b7d82678aeaa83cf2946e512385ae Mon Sep 17 00:00:00 2001 From: test Date: Wed, 26 Jun 2024 11:18:09 +1000 Subject: [PATCH 5/6] Update Locutus.java --- src/main/java/link/locutus/discord/Locutus.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/link/locutus/discord/Locutus.java b/src/main/java/link/locutus/discord/Locutus.java index c93cfc4d..3926a88a 100644 --- a/src/main/java/link/locutus/discord/Locutus.java +++ b/src/main/java/link/locutus/discord/Locutus.java @@ -1144,7 +1144,8 @@ public void onButtonInteraction(@NotNull ButtonInteractionEvent event) { Button button = event.getButton(); System.out.println("Button press " + button.getId() + " | " + button.getLabel()); - if (button.getId().equalsIgnoreCase(" ") && message != null) { + + if (button.getId().equalsIgnoreCase("")) { RateLimitUtil.queue(message.delete()); return; } From c0f420206def5494f0b57998fe3d95559d39035a Mon Sep 17 00:00:00 2001 From: test Date: Wed, 26 Jun 2024 11:42:33 +1000 Subject: [PATCH 6/6] Update Locutus.java --- src/main/java/link/locutus/discord/Locutus.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/link/locutus/discord/Locutus.java b/src/main/java/link/locutus/discord/Locutus.java index 3926a88a..f8ea1ff2 100644 --- a/src/main/java/link/locutus/discord/Locutus.java +++ b/src/main/java/link/locutus/discord/Locutus.java @@ -1140,7 +1140,6 @@ public void onModalInteraction(@NotNull ModalInteractionEvent event) { public void onButtonInteraction(@NotNull ButtonInteractionEvent event) { try { Message message = event.getMessage(); - // Only process locutus buttons Button button = event.getButton(); System.out.println("Button press " + button.getId() + " | " + button.getLabel());