Skip to content

Commit ad076f4

Browse files
committed
Improve dismission
1 parent 34ea2d1 commit ad076f4

32 files changed

Lines changed: 261 additions & 191 deletions

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,21 @@
2626
import com.mcmoddev.mmdbot.commander.annotation.RegisterSlashCommand;
2727
import com.mcmoddev.mmdbot.commander.cfwebhooks.CFProjects;
2828
import com.mcmoddev.mmdbot.commander.cfwebhooks.CurseForgeManager;
29-
import com.mcmoddev.mmdbot.commander.commands.CustomPingsCommand;
30-
import com.mcmoddev.mmdbot.commander.commands.DictionaryCommand;
3129
import com.mcmoddev.mmdbot.commander.commands.EvaluateCommand;
3230
import com.mcmoddev.mmdbot.commander.commands.GistCommand;
33-
import com.mcmoddev.mmdbot.commander.commands.HelpCommand;
34-
import com.mcmoddev.mmdbot.commander.commands.QuoteCommand;
3531
import com.mcmoddev.mmdbot.commander.commands.RemindCommand;
36-
import com.mcmoddev.mmdbot.commander.commands.RoleSelectCommand;
37-
import com.mcmoddev.mmdbot.commander.commands.RolesCommand;
3832
import com.mcmoddev.mmdbot.commander.commands.curseforge.CurseForgeCommand;
3933
import com.mcmoddev.mmdbot.commander.commands.menu.message.AddQuoteContextMenu;
4034
import com.mcmoddev.mmdbot.commander.commands.menu.message.GistContextMenu;
4135
import com.mcmoddev.mmdbot.commander.commands.menu.user.UserInfoContextMenu;
4236
import com.mcmoddev.mmdbot.commander.commands.tricks.AddTrickCommand;
4337
import com.mcmoddev.mmdbot.commander.commands.tricks.EditTrickCommand;
44-
import com.mcmoddev.mmdbot.commander.commands.tricks.ListTricksCommand;
4538
import com.mcmoddev.mmdbot.commander.commands.tricks.RunTrickCommand;
4639
import com.mcmoddev.mmdbot.commander.config.Configuration;
4740
import com.mcmoddev.mmdbot.commander.custompings.CustomPings;
4841
import com.mcmoddev.mmdbot.commander.custompings.CustomPingsListener;
49-
import com.mcmoddev.mmdbot.commander.eventlistener.DismissListener;
42+
import com.mcmoddev.mmdbot.core.commands.component.storage.ComponentStorage;
43+
import com.mcmoddev.mmdbot.core.util.event.DismissListener;
5044
import com.mcmoddev.mmdbot.commander.eventlistener.ReferencingListener;
5145
import com.mcmoddev.mmdbot.commander.eventlistener.ThreadListener;
5246
import com.mcmoddev.mmdbot.commander.migrate.QuotesMigrator;
@@ -64,7 +58,7 @@
6458
import com.mcmoddev.mmdbot.core.bot.RegisterBotType;
6559
import com.mcmoddev.mmdbot.core.commands.component.ComponentListener;
6660
import com.mcmoddev.mmdbot.core.commands.component.ComponentManager;
67-
import com.mcmoddev.mmdbot.core.commands.component.ComponentStorage;
61+
import com.mcmoddev.mmdbot.core.commands.component.storage.SQLComponentStorage;
6862
import com.mcmoddev.mmdbot.core.event.Events;
6963
import com.mcmoddev.mmdbot.core.util.ConfigurateUtils;
7064
import com.mcmoddev.mmdbot.core.util.DotenvLoader;
@@ -312,7 +306,7 @@ public void start() {
312306

313307
// Setup components
314308
{
315-
final var storage = new ComponentStorage(jdbi, "components");
309+
final var storage = ComponentStorage.sql(jdbi, "components");
316310
componentManager = new ComponentManager(storage, DEFERRED_COMPONENT_LISTENERS);
317311
EventListeners.COMMANDS_LISTENER.addListener(componentManager);
318312
}

src/commander/java/com/mcmoddev/mmdbot/commander/commands/CustomPingsCommand.java

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,24 @@
2020
*/
2121
package com.mcmoddev.mmdbot.commander.commands;
2222

23-
import com.jagrosh.jdautilities.command.CooldownScope;
2423
import com.jagrosh.jdautilities.command.SlashCommand;
2524
import com.jagrosh.jdautilities.command.SlashCommandEvent;
2625
import com.mcmoddev.mmdbot.commander.TheCommander;
2726
import com.mcmoddev.mmdbot.commander.annotation.RegisterSlashCommand;
2827
import com.mcmoddev.mmdbot.commander.custompings.CustomPing;
2928
import com.mcmoddev.mmdbot.commander.custompings.CustomPings;
30-
import com.mcmoddev.mmdbot.commander.eventlistener.DismissListener;
31-
import com.mcmoddev.mmdbot.commander.reminders.Reminder;
32-
import com.mcmoddev.mmdbot.commander.reminders.Reminders;
33-
import com.mcmoddev.mmdbot.commander.reminders.SnoozingListener;
34-
import com.mcmoddev.mmdbot.commander.util.TheCommanderUtilities;
29+
import com.mcmoddev.mmdbot.core.util.event.DismissListener;
3530
import com.mcmoddev.mmdbot.core.commands.component.Component;
3631
import com.mcmoddev.mmdbot.core.util.builder.SlashCommandBuilder;
3732
import com.mcmoddev.mmdbot.core.util.command.PaginatedCommand;
3833
import net.dv8tion.jda.api.EmbedBuilder;
39-
import net.dv8tion.jda.api.entities.ChannelType;
40-
import net.dv8tion.jda.api.entities.Emoji;
41-
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
42-
import net.dv8tion.jda.api.hooks.ListenerAdapter;
4334
import net.dv8tion.jda.api.interactions.callbacks.IReplyCallback;
4435
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
4536
import net.dv8tion.jda.api.interactions.commands.OptionType;
4637
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
47-
import net.dv8tion.jda.api.interactions.components.ItemComponent;
48-
import net.dv8tion.jda.api.interactions.components.buttons.Button;
49-
import net.dv8tion.jda.api.utils.TimeFormat;
50-
import org.jetbrains.annotations.NotNull;
51-
52-
import java.time.Duration;
53-
import java.time.Instant;
54-
import java.time.format.DateTimeFormatter;
55-
import java.time.format.DateTimeFormatterBuilder;
56-
import java.time.format.DateTimeParseException;
57-
import java.time.temporal.ChronoField;
58-
import java.time.temporal.ChronoUnit;
59-
import java.util.ArrayList;
38+
6039
import java.util.List;
61-
import java.util.function.LongSupplier;
40+
import java.util.Objects;
6241
import java.util.regex.Pattern;
6342
import java.util.regex.PatternSyntaxException;
6443

@@ -113,6 +92,7 @@ private ListCmd() {
11392
this.name = "list";
11493
this.help = "Lists all your custom pings.";
11594
guildOnly = true;
95+
dismissibleMessage = true;
11696
}
11797

11898
@Override
@@ -121,12 +101,12 @@ protected void execute(final SlashCommandEvent event) {
121101

122102
// Args:
123103
// guildId, userId
124-
createPaginatedMessage(
104+
sendPaginatedMessage(
125105
event,
126-
CustomPings.getPingsForUser(event.getGuild().getIdLong(), event.getUser().getIdLong()).size(),
106+
CustomPings.getPingsForUser(Objects.requireNonNull(event.getGuild()).getIdLong(), event.getUser().getIdLong()).size(),
127107
event.getGuild().getId(),
128108
event.getUser().getId()
129-
).addActionRow(DismissListener.createDismissButton(event.getUser())).queue();
109+
);
130110
}
131111

132112
@Override

src/commander/java/com/mcmoddev/mmdbot/commander/commands/DictionaryCommand.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import com.jagrosh.jdautilities.command.SlashCommandEvent;
2424
import com.mcmoddev.mmdbot.commander.TheCommander;
2525
import com.mcmoddev.mmdbot.commander.annotation.RegisterSlashCommand;
26-
import com.mcmoddev.mmdbot.commander.eventlistener.DismissListener;
26+
import com.mcmoddev.mmdbot.core.util.event.DismissListener;
2727
import com.mcmoddev.mmdbot.core.commands.component.Component;
2828
import com.mcmoddev.mmdbot.core.util.Utils;
2929
import com.mcmoddev.mmdbot.core.util.command.PaginatedCommand;
@@ -50,6 +50,7 @@ public DictionaryCommand() {
5050
help = "Looks up a word";
5151
options = List.of(new OptionData(OptionType.STRING, "word", "The word to lookup").setRequired(true));
5252
guildOnly = false;
53+
dismissibleMessage = true;
5354
}
5455

5556
@Override
@@ -61,9 +62,7 @@ protected void execute(final SlashCommandEvent event) {
6162
final var word = event.getOption("word", "", OptionMapping::getAsString).split(" ")[0];
6263
try {
6364
final var definition = DictionaryUtils.getDefinition(word);
64-
createPaginatedMessage(event, definition.definitions().size(), word)
65-
.addActionRow(DismissListener.createDismissButton(event.getUser().getIdLong()))
66-
.queue();
65+
sendPaginatedMessage(event, definition.definitions().size(), word);
6766
} catch (DictionaryUtils.DictionaryException e) {
6867
if (e.getErrorCode() == 404) {
6968
event.deferReply().setContent("Unknown word: " + word).queue();

src/commander/java/com/mcmoddev/mmdbot/commander/commands/EvaluateCommand.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.jagrosh.jdautilities.command.SlashCommandEvent;
2626
import com.mcmoddev.mmdbot.commander.TheCommander;
2727
import com.mcmoddev.mmdbot.commander.annotation.RegisterSlashCommand;
28-
import com.mcmoddev.mmdbot.commander.eventlistener.DismissListener;
28+
import com.mcmoddev.mmdbot.core.util.event.DismissListener;
2929
import com.mcmoddev.mmdbot.commander.tricks.TrickContext;
3030
import com.mcmoddev.mmdbot.commander.tricks.Tricks;
3131
import com.mcmoddev.mmdbot.commander.util.script.ScriptingContext;
@@ -47,7 +47,6 @@
4747
import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent;
4848
import net.dv8tion.jda.api.hooks.ListenerAdapter;
4949
import net.dv8tion.jda.api.interactions.InteractionHook;
50-
import net.dv8tion.jda.api.interactions.commands.OptionMapping;
5150
import net.dv8tion.jda.api.interactions.commands.OptionType;
5251
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
5352
import net.dv8tion.jda.api.interactions.components.Modal;
@@ -64,7 +63,6 @@
6463
import java.util.Objects;
6564
import java.util.Set;
6665
import java.util.concurrent.ExecutionException;
67-
import java.util.concurrent.Executor;
6866
import java.util.concurrent.ExecutorService;
6967
import java.util.concurrent.Executors;
7068
import java.util.concurrent.ThreadPoolExecutor;

src/commander/java/com/mcmoddev/mmdbot/commander/commands/HelpCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ private HelpCommand() {
6565
guildOnly = false;
6666
options = List.of(new OptionData(OptionType.STRING, "command", "A command to get detailed information on").setRequired(false));
6767
arguments = "[command]";
68+
dismissibleMessage = true;
6869
}
6970

7071
@Override

src/commander/java/com/mcmoddev/mmdbot/commander/commands/QuoteCommand.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424
import com.jagrosh.jdautilities.command.SlashCommandEvent;
2525
import com.mcmoddev.mmdbot.commander.TheCommander;
2626
import com.mcmoddev.mmdbot.commander.annotation.RegisterSlashCommand;
27-
import com.mcmoddev.mmdbot.commander.eventlistener.DismissListener;
27+
import com.mcmoddev.mmdbot.core.util.event.DismissListener;
2828
import com.mcmoddev.mmdbot.commander.quotes.NullQuote;
2929
import com.mcmoddev.mmdbot.commander.quotes.Quote;
3030
import com.mcmoddev.mmdbot.commander.quotes.Quotes;
3131
import com.mcmoddev.mmdbot.commander.quotes.StringQuote;
3232
import com.mcmoddev.mmdbot.commander.quotes.UserReference;
33-
import com.mcmoddev.mmdbot.commander.tricks.Tricks;
3433
import com.mcmoddev.mmdbot.core.commands.component.Component;
3534
import com.mcmoddev.mmdbot.core.util.command.PaginatedCommand;
3635
import io.github.matyrobbrt.eventdispatcher.LazySupplier;
@@ -42,7 +41,6 @@
4241

4342
import java.awt.Color;
4443
import java.time.Instant;
45-
import java.util.ArrayList;
4644
import java.util.Collections;
4745
import java.util.List;
4846
import java.util.Random;
@@ -314,6 +312,7 @@ private ListQuotes() {
314312
options = List.of(
315313
new OptionData(OptionType.INTEGER, "page", "The index of the page to display. 1 if not specified.")
316314
);
315+
dismissibleMessage = true;
317316
}
318317

319318
@Override
@@ -331,8 +330,7 @@ protected void execute(final SlashCommandEvent event) {
331330
.formatted(pgIndex, getPagesNumber(maximum))).queue();
332331
return;
333332
}
334-
createPaginatedMessage(event, startingIndex, maximum, event.getGuild().getId())
335-
.addActionRows(ActionRow.of(DismissListener.createDismissButton(event))).queue();
333+
sendPaginatedMessage(event, startingIndex, maximum, event.getGuild().getId());
336334
}
337335

338336
@Override

src/commander/java/com/mcmoddev/mmdbot/commander/commands/RemindCommand.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@
2020
*/
2121
package com.mcmoddev.mmdbot.commander.commands;
2222

23-
import com.ibm.icu.impl.duration.DurationFormatter;
24-
import com.ibm.icu.impl.duration.DurationFormatterFactory;
25-
import com.ibm.icu.text.DurationFormat;
2623
import com.jagrosh.jdautilities.command.CooldownScope;
2724
import com.jagrosh.jdautilities.command.SlashCommand;
2825
import com.jagrosh.jdautilities.command.SlashCommandEvent;
2926
import com.mcmoddev.mmdbot.commander.TheCommander;
3027
import com.mcmoddev.mmdbot.commander.annotation.RegisterSlashCommand;
31-
import com.mcmoddev.mmdbot.commander.eventlistener.DismissListener;
28+
import com.mcmoddev.mmdbot.core.util.event.DismissListener;
3229
import com.mcmoddev.mmdbot.commander.reminders.Reminder;
3330
import com.mcmoddev.mmdbot.commander.reminders.Reminders;
3431
import com.mcmoddev.mmdbot.commander.reminders.SnoozingListener;

src/commander/java/com/mcmoddev/mmdbot/commander/commands/RoleSelectCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import com.jagrosh.jdautilities.command.SlashCommandEvent;
2525
import com.mcmoddev.mmdbot.commander.TheCommander;
2626
import com.mcmoddev.mmdbot.commander.annotation.RegisterSlashCommand;
27-
import com.mcmoddev.mmdbot.core.commands.component.ButtonInteractionContext;
27+
import com.mcmoddev.mmdbot.core.commands.component.context.ButtonInteractionContext;
2828
import com.mcmoddev.mmdbot.core.commands.component.Component;
2929
import com.mcmoddev.mmdbot.core.commands.component.ComponentListener;
30-
import com.mcmoddev.mmdbot.core.commands.component.ModalInteractionContext;
31-
import com.mcmoddev.mmdbot.core.commands.component.SelectMenuInteractionContext;
30+
import com.mcmoddev.mmdbot.core.commands.component.context.ModalInteractionContext;
31+
import com.mcmoddev.mmdbot.core.commands.component.context.SelectMenuInteractionContext;
3232
import lombok.NonNull;
3333
import net.dv8tion.jda.api.EmbedBuilder;
3434
import net.dv8tion.jda.api.MessageBuilder;
@@ -120,7 +120,7 @@ private static void addMenuOptions(@NonNull final Interaction interaction,
120120

121121
final var roles = guildRoles.subList(guildRoles.indexOf(highestBotRole) + 1, guildRoles.size());
122122

123-
if (null != minValues) {
123+
if (minValues != null) {
124124
menu.setMinValues(minValues);
125125
}
126126

src/commander/java/com/mcmoddev/mmdbot/commander/commands/RolesCommand.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private RolesCommand() {
4343
guildOnly = true;
4444

4545
category = new Category("Info");
46+
dismissibleMessage = true;
4647
}
4748

4849
/**

src/commander/java/com/mcmoddev/mmdbot/commander/commands/ServerCommands.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@
2323
import com.jagrosh.jdautilities.command.SlashCommand;
2424
import com.mcmoddev.mmdbot.commander.TheCommander;
2525
import com.mcmoddev.mmdbot.commander.annotation.RegisterSlashCommand;
26-
import com.mcmoddev.mmdbot.commander.eventlistener.DismissListener;
26+
import com.mcmoddev.mmdbot.core.util.event.DismissListener;
2727
import com.mcmoddev.mmdbot.commander.util.TheCommanderUtilities;
28-
import com.mcmoddev.mmdbot.core.util.Utils;
2928
import com.mcmoddev.mmdbot.core.util.builder.SlashCommandBuilder;
3029
import lombok.experimental.UtilityClass;
3130
import net.dv8tion.jda.api.EmbedBuilder;
@@ -35,12 +34,7 @@
3534
import net.dv8tion.jda.api.utils.TimeFormat;
3635

3736
import java.awt.Color;
38-
import java.text.DateFormat;
39-
import java.text.SimpleDateFormat;
4037
import java.time.Instant;
41-
import java.time.OffsetDateTime;
42-
import java.time.ZoneOffset;
43-
import java.util.Locale;
4438
import java.util.Objects;
4539

4640
/**

0 commit comments

Comments
 (0)