Fixed buttons not removing after clicking them
Added hour option Fixed reminder not working without description Fixed using snowflake instead of timestamp for relative time
This commit is contained in:
+12
-1
@@ -1,10 +1,15 @@
|
||||
package com.alttd.buttonManager.buttons.remindMeConfirm;
|
||||
|
||||
import com.alttd.buttonManager.DiscordButton;
|
||||
import com.alttd.database.queries.QueriesReminders.Reminder;
|
||||
import com.alttd.util.Util;
|
||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ButtonRemindMeCancel extends DiscordButton {
|
||||
@Override
|
||||
public String getButtonId() {
|
||||
@@ -13,9 +18,15 @@ public class ButtonRemindMeCancel extends DiscordButton {
|
||||
|
||||
@Override
|
||||
public void execute(ButtonInteractionEvent event) {
|
||||
ButtonRemindMeConfirm.removeReminder(event.getUser().getIdLong());
|
||||
HookAndReminder hookAndReminder = ButtonRemindMeConfirm.removeReminder(event.getUser().getIdLong());
|
||||
if (hookAndReminder == null) {
|
||||
event.replyEmbeds(Util.genericErrorEmbed("Error", "Your reminder was already cancelled!"))
|
||||
.setEphemeral(true).queue();
|
||||
return;
|
||||
}
|
||||
event.replyEmbeds(Util.genericSuccessEmbed("Success", "Cancelled your reminder!"))
|
||||
.setEphemeral(true).queue();
|
||||
hookAndReminder.interactionHook().editOriginalComponents(List.of()).queue();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+10
-7
@@ -6,20 +6,22 @@ import com.alttd.database.queries.QueriesReminders.Reminder;
|
||||
import com.alttd.reminders.ReminderScheduler;
|
||||
import com.alttd.util.Util;
|
||||
import net.dv8tion.jda.api.events.interaction.component.ButtonInteractionEvent;
|
||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||
import net.dv8tion.jda.api.interactions.components.buttons.Button;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ButtonRemindMeConfirm extends DiscordButton {
|
||||
|
||||
private static final HashMap<Long, Reminder> unconfirmedReminders = new HashMap<>();
|
||||
private static final HashMap<Long, HookAndReminder> unconfirmedReminders = new HashMap<>();
|
||||
|
||||
public static synchronized void putReminder(long id, Reminder reminder) {
|
||||
unconfirmedReminders.put(id, reminder);
|
||||
public static synchronized void putReminder(long id, InteractionHook defer, Reminder reminder) {
|
||||
unconfirmedReminders.put(id, new HookAndReminder(reminder, defer));
|
||||
}
|
||||
|
||||
public static synchronized Reminder removeReminder(long id) {
|
||||
return unconfirmedReminders.get(id);
|
||||
public static synchronized HookAndReminder removeReminder(long id) {
|
||||
return unconfirmedReminders.remove(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -29,12 +31,13 @@ public class ButtonRemindMeConfirm extends DiscordButton {
|
||||
|
||||
@Override
|
||||
public void execute(ButtonInteractionEvent event) {
|
||||
Reminder reminder = removeReminder(event.getUser().getIdLong());
|
||||
HookAndReminder hookAndReminder = removeReminder(event.getUser().getIdLong());
|
||||
|
||||
if (storeReminder(reminder, event)) {
|
||||
if (storeReminder(hookAndReminder.reminder(), event)) {
|
||||
event.replyEmbeds(Util.genericSuccessEmbed("Success", "Your reminder was successfully created!"))
|
||||
.setEphemeral(true).queue();
|
||||
}
|
||||
hookAndReminder.interactionHook().editOriginalComponents(List.of()).queue();
|
||||
}
|
||||
|
||||
private boolean storeReminder(Reminder reminder, ButtonInteractionEvent event) {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.alttd.buttonManager.buttons.remindMeConfirm;
|
||||
|
||||
import com.alttd.database.queries.QueriesReminders.Reminder;
|
||||
import net.dv8tion.jda.api.interactions.InteractionHook;
|
||||
|
||||
record HookAndReminder(Reminder reminder, InteractionHook interactionHook) {
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user