Refactor appeal message sending to use AppealSender and improve assignment handling with thread creation and button interactions.
This commit is contained in:
parent
65820cf0a4
commit
9311a1ccd6
|
|
@ -12,6 +12,7 @@ import com.alttd.altitudeweb.database.litebans.UserType;
|
||||||
import com.alttd.altitudeweb.database.web_db.forms.Appeal;
|
import com.alttd.altitudeweb.database.web_db.forms.Appeal;
|
||||||
import com.alttd.altitudeweb.database.web_db.forms.AppealMapper;
|
import com.alttd.altitudeweb.database.web_db.forms.AppealMapper;
|
||||||
import com.alttd.altitudeweb.setup.Connection;
|
import com.alttd.altitudeweb.setup.Connection;
|
||||||
|
import com.alttd.webinterface.appeals.AppealSender;
|
||||||
import com.alttd.webinterface.objects.MessageForEmbed;
|
import com.alttd.webinterface.objects.MessageForEmbed;
|
||||||
import com.alttd.webinterface.send_message.DiscordSender;
|
import com.alttd.webinterface.send_message.DiscordSender;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -120,7 +121,7 @@ public class AppealDiscord {
|
||||||
Instant timestamp = appeal.createdAt() != null ? appeal.createdAt() : Instant.now();
|
Instant timestamp = appeal.createdAt() != null ? appeal.createdAt() : Instant.now();
|
||||||
MessageForEmbed newAppealSubmitted = new MessageForEmbed(
|
MessageForEmbed newAppealSubmitted = new MessageForEmbed(
|
||||||
"New Appeal Submitted", description, fields, null, timestamp, null);
|
"New Appeal Submitted", description, fields, null, timestamp, null);
|
||||||
DiscordSender.getInstance().sendEmbedWithThreadToChannels(channelIds, newAppealSubmitted, "Appeal");
|
AppealSender.getInstance().sendAppeal(channelIds, newAppealSubmitted, optionalAssignedTo.orElse(0L));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assignAppealTo(UUID appealId, Long assignedTo) {
|
private void assignAppealTo(UUID appealId, Long assignedTo) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,61 @@
|
||||||
|
package com.alttd.webinterface.appeals;
|
||||||
|
|
||||||
|
import com.alttd.webinterface.objects.MessageForEmbed;
|
||||||
|
import com.alttd.webinterface.send_message.DiscordSender;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.dv8tion.jda.api.components.actionrow.ActionRow;
|
||||||
|
import net.dv8tion.jda.api.components.buttons.Button;
|
||||||
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class AppealSender {
|
||||||
|
|
||||||
|
private static final AppealSender INSTANCE = new AppealSender();
|
||||||
|
|
||||||
|
public static AppealSender getInstance() {
|
||||||
|
return INSTANCE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendAppeal(List<Long> channelIds, MessageForEmbed messageForEmbed, long assignedTo) {
|
||||||
|
DiscordSender.getInstance()
|
||||||
|
.sendEmbedToChannels(channelIds, messageForEmbed)
|
||||||
|
.whenCompleteAsync((result, error) -> {
|
||||||
|
if (error != null) {
|
||||||
|
log.error("Failed sending embed to channels", error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Message> list = result.stream()
|
||||||
|
.filter(Optional::isPresent)
|
||||||
|
.map(Optional::get)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
|
||||||
|
list.forEach(message -> {
|
||||||
|
message.createThreadChannel("Appeal")
|
||||||
|
.queue(channel -> {
|
||||||
|
if (assignedTo == 0L) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String assignedUserMessage = "<@" + assignedTo + "> you have a new appeal!";
|
||||||
|
channel.sendMessage(assignedUserMessage).queue();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
addButtons(list);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addButtons(List<Message> messages) {
|
||||||
|
Button reminderAccepted = Button.primary("reminder_accepted", "Accepted");
|
||||||
|
Button reminderInProgress = Button.secondary("reminder_in_progress", "In Progress");
|
||||||
|
Button reminderDenied = Button.danger("reminder_denied", "Denied");
|
||||||
|
messages.forEach(message -> {
|
||||||
|
message.editMessageComponents(ActionRow.of(reminderAccepted, reminderInProgress, reminderDenied)).queue();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user