mirror of
https://github.com/Sheldan/Sissi.git
synced 2026-01-26 19:21:43 +00:00
[SIS-xxx] adding ability to select multiple decisions for meetup notify
making meetup notify slash command only
This commit is contained in:
@@ -23,6 +23,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEve
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
@@ -49,19 +50,6 @@ public class NotifyMeetupParticipants extends AbstractConditionableCommand {
|
|||||||
private static final String NOTIFY_MEETUP_PARTICIPANTS_COMMAND = "notifyMeetupParticipants";
|
private static final String NOTIFY_MEETUP_PARTICIPANTS_COMMAND = "notifyMeetupParticipants";
|
||||||
private static final String NOTIFY_MEETUP_PARTICIPANTS_RESPONSE = "notifyMeetupParticipants_response";
|
private static final String NOTIFY_MEETUP_PARTICIPANTS_RESPONSE = "notifyMeetupParticipants_response";
|
||||||
|
|
||||||
@Override
|
|
||||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
|
||||||
List<Object> parameters = commandContext.getParameters().getParameters();
|
|
||||||
Long meetupId = (Long) parameters.get(0);
|
|
||||||
Meetup meetup = meetupManagementServiceBean.getMeetup(meetupId, commandContext.getGuild().getIdLong());
|
|
||||||
if(!meetup.getOrganizer().getUserReference().getId().equals(commandContext.getAuthor().getIdLong())) {
|
|
||||||
throw new NotMeetupOrganizerException();
|
|
||||||
}
|
|
||||||
String notificationMessage = (String) parameters.get(1);
|
|
||||||
return meetupServiceBean.notifyMeetupParticipants(meetup, notificationMessage, null)
|
|
||||||
.thenApply(unused -> CommandResult.fromSuccess());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
public CompletableFuture<CommandResult> executeSlash(SlashCommandInteractionEvent event) {
|
||||||
Long meetupId = slashCommandParameterService.getCommandOption(MEETUP_ID_PARAMETER, event, Integer.class).longValue();
|
Long meetupId = slashCommandParameterService.getCommandOption(MEETUP_ID_PARAMETER, event, Integer.class).longValue();
|
||||||
@@ -69,12 +57,15 @@ public class NotifyMeetupParticipants extends AbstractConditionableCommand {
|
|||||||
if(!meetup.getOrganizer().getUserReference().getId().equals(event.getMember().getIdLong())) {
|
if(!meetup.getOrganizer().getUserReference().getId().equals(event.getMember().getIdLong())) {
|
||||||
throw new NotMeetupOrganizerException();
|
throw new NotMeetupOrganizerException();
|
||||||
}
|
}
|
||||||
MeetupDecision toNotify = null;
|
List<MeetupDecision> decisionsToNotify = new ArrayList<>();
|
||||||
if(slashCommandParameterService.hasCommandOption(NOTIFICATION_MEETUP_DECISION, event)) {
|
for (int i = 0; i < MeetupDecision.values().length; i++) {
|
||||||
toNotify = MeetupDecision.valueOf(slashCommandParameterService.getCommandOption(NOTIFICATION_MEETUP_DECISION, event, String.class));
|
if(slashCommandParameterService.hasCommandOption(NOTIFICATION_MEETUP_DECISION + "_" + i, event)) {
|
||||||
|
String choice = slashCommandParameterService.getCommandOption(NOTIFICATION_MEETUP_DECISION + "_" + i, event, String.class);
|
||||||
|
decisionsToNotify.add(MeetupDecision.valueOf(choice));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
String notificationMessage = slashCommandParameterService.getCommandOption(NOTIFICATION_MESSAGE_PARAMETER, event, String.class);
|
String notificationMessage = slashCommandParameterService.getCommandOption(NOTIFICATION_MESSAGE_PARAMETER, event, String.class);
|
||||||
return meetupServiceBean.notifyMeetupParticipants(meetup, notificationMessage, toNotify)
|
return meetupServiceBean.notifyMeetupParticipants(meetup, notificationMessage, decisionsToNotify)
|
||||||
.thenCompose(unused -> interactionService.replyEmbed(NOTIFY_MEETUP_PARTICIPANTS_RESPONSE, event))
|
.thenCompose(unused -> interactionService.replyEmbed(NOTIFY_MEETUP_PARTICIPANTS_RESPONSE, event))
|
||||||
.thenApply(unused -> CommandResult.fromSuccess());
|
.thenApply(unused -> CommandResult.fromSuccess());
|
||||||
}
|
}
|
||||||
@@ -106,6 +97,8 @@ public class NotifyMeetupParticipants extends AbstractConditionableCommand {
|
|||||||
.templated(true)
|
.templated(true)
|
||||||
.name(NOTIFICATION_MEETUP_DECISION)
|
.name(NOTIFICATION_MEETUP_DECISION)
|
||||||
.type(String.class)
|
.type(String.class)
|
||||||
|
.listSize(MeetupDecision.values().length)
|
||||||
|
.isListParam(true)
|
||||||
.optional(true)
|
.optional(true)
|
||||||
.choices(meetupDecisions)
|
.choices(meetupDecisions)
|
||||||
.slashCommandOnly(true)
|
.slashCommandOnly(true)
|
||||||
@@ -131,6 +124,7 @@ public class NotifyMeetupParticipants extends AbstractConditionableCommand {
|
|||||||
.templated(true)
|
.templated(true)
|
||||||
.slashCommandConfig(slashCommandConfig)
|
.slashCommandConfig(slashCommandConfig)
|
||||||
.async(true)
|
.async(true)
|
||||||
|
.slashCommandOnly(true)
|
||||||
.supportsEmbedException(true)
|
.supportsEmbedException(true)
|
||||||
.causesReaction(true)
|
.causesReaction(true)
|
||||||
.parameters(parameters)
|
.parameters(parameters)
|
||||||
|
|||||||
@@ -293,8 +293,8 @@ public class MeetupServiceBean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletableFuture<Void> notifyMeetupParticipants(Meetup meetup, String message, MeetupDecision toNotify) {
|
public CompletableFuture<Void> notifyMeetupParticipants(Meetup meetup, String message, List<MeetupDecision> toNotify) {
|
||||||
List<MeetupDecision> decisionsToBeNotified = toNotify == null ? Arrays.asList(MeetupDecision.MAYBE, MeetupDecision.YES) : Arrays.asList(toNotify);
|
List<MeetupDecision> decisionsToBeNotified = toNotify == null || toNotify.isEmpty() ? Arrays.asList(MeetupDecision.MAYBE, MeetupDecision.YES) : toNotify;
|
||||||
List<MemberDisplay> participants = meetup
|
List<MemberDisplay> participants = meetup
|
||||||
.getParticipants()
|
.getParticipants()
|
||||||
.stream()
|
.stream()
|
||||||
|
|||||||
Reference in New Issue
Block a user