use of net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction in project LightboltMeeting by LightboltMeeting.
the class AddAdminSubcommand method handleMeetingCommand.
@Override
protected ReplyCallbackAction handleMeetingCommand(SlashCommandInteractionEvent event, LocaleConfig locale, SystemsConfig.MeetingConfig config, MeetingRepository repo) throws SQLException {
var idOption = event.getOption("meeting-id");
var userOption = event.getOption("user");
if (userOption == null || idOption == null) {
return Responses.error(event, locale.getCommand().getMISSING_ARGUMENTS());
}
var id = (int) idOption.getAsLong();
var user = userOption.getAsUser();
var com = locale.getMeeting().getCommand();
var meetings = repo.getByUserId(event.getUser().getIdLong());
Optional<Meeting> meetingOptional = meetings.stream().filter(m -> m.getId() == id).findFirst();
if (meetingOptional.isEmpty()) {
return Responses.error(event, String.format(com.getMEETING_NOT_FOUND(), id));
}
var meeting = meetingOptional.get();
var participants = meeting.getParticipants();
var admins = meeting.getAdmins();
if (!Arrays.stream(participants).anyMatch(x -> x == user.getIdLong())) {
return Responses.error(event, String.format(com.getMEETING_ADMIN_NOT_A_PARTICIPANT(), user.getAsMention()));
}
if (Arrays.stream(admins).anyMatch(x -> x == user.getIdLong())) {
return Responses.error(event, String.format(com.getMEETING_ADMIN_ALREADY_ADDED(), user.getAsMention()));
}
new MeetingManager(event.getJDA(), meeting).addAdmin(user);
return Responses.success(event, com.getADMINS_ADD_SUCCESS_TITLE(), String.format(com.getADMINS_ADD_SUCCESS_DESCRIPTION(), user.getAsMention(), meeting.getTitle()));
}
use of net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction in project LightboltMeeting by LightboltMeeting.
the class RemoveAdminSubcommand method handleMeetingCommand.
@Override
protected ReplyCallbackAction handleMeetingCommand(SlashCommandInteractionEvent event, LocaleConfig locale, SystemsConfig.MeetingConfig config, MeetingRepository repo) throws SQLException {
var idOption = event.getOption("meeting-id");
var userOption = event.getOption("user");
if (userOption == null || idOption == null) {
return Responses.error(event, locale.getCommand().getMISSING_ARGUMENTS());
}
var id = (int) idOption.getAsLong();
var user = userOption.getAsUser();
var com = locale.getMeeting().getCommand();
var meetings = repo.getByUserId(event.getUser().getIdLong());
Optional<Meeting> meetingOptional = meetings.stream().filter(m -> m.getId() == id).findFirst();
if (meetingOptional.isEmpty()) {
return Responses.error(event, String.format(com.getMEETING_NOT_FOUND(), id));
}
var meeting = meetingOptional.get();
var admins = meeting.getAdmins();
if (Arrays.stream(admins).anyMatch(x -> x == user.getIdLong())) {
new MeetingManager(event.getJDA(), meeting).removeAdmin(user);
return Responses.success(event, com.getADMINS_REMOVE_SUCCESS_TITLE(), String.format(com.getADMINS_REMOVE_SUCCESS_DESCRIPTION(), user.getAsMention(), meeting.getTitle()));
} else {
return Responses.error(event, String.format(com.getMEETING_ADMIN_NOT_FOUND(), user.getAsMention()));
}
}
use of net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction in project Ninbot by Nincodedo.
the class SlashCommandEventMessageExecutorTest method executeFiveMessageAction.
@Test
void executeFiveMessageAction() {
SlashCommandInteractionEvent slashCommandEvent = Mockito.mock(SlashCommandInteractionEvent.class);
ReplyCallbackAction replyAction = Mockito.mock(ReplyCallbackAction.class);
when(slashCommandEvent.reply(any(Message.class))).thenReturn(replyAction);
messageExecutor = new SlashCommandEventMessageExecutor(slashCommandEvent);
messageExecutor.addMessageResponse("wow");
messageExecutor.addMessageResponse("wooow");
messageExecutor.addMessageResponse("wooooow");
messageExecutor.addMessageResponse("wooow");
messageExecutor.addMessageResponse("wow");
messageExecutor.executeActions();
verify(slashCommandEvent, times(5)).reply(any(Message.class));
}
use of net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction in project Ninbot by Nincodedo.
the class SlashCommandEventMessageExecutorTest method executeOneMessageAction.
@Test
void executeOneMessageAction() {
SlashCommandInteractionEvent slashCommandEvent = Mockito.mock(SlashCommandInteractionEvent.class);
ReplyCallbackAction replyAction = Mockito.mock(ReplyCallbackAction.class);
when(slashCommandEvent.reply(any(Message.class))).thenReturn(replyAction);
messageExecutor = new SlashCommandEventMessageExecutor(slashCommandEvent);
messageExecutor.addMessageResponse("wow");
messageExecutor.executeActions();
verify(slashCommandEvent, times(1)).reply(any(Message.class));
}
use of net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction in project JavaBot by Java-Discord.
the class MigrationsListSubcommand method handleSlashCommandInteraction.
@Override
public ReplyCallbackAction handleSlashCommandInteraction(SlashCommandInteractionEvent event) {
try (var s = Files.list(MigrationUtils.getMigrationsDirectory())) {
EmbedBuilder embedBuilder = new EmbedBuilder().setTitle("List of Runnable Migrations");
var paths = s.filter(path -> path.getFileName().toString().endsWith(".sql")).toList();
if (paths.isEmpty()) {
embedBuilder.setDescription("There are no migrations to run. Please add them to the `/migrations/` resource directory.");
return event.replyEmbeds(embedBuilder.build());
}
paths.forEach(path -> {
StringBuilder sb = new StringBuilder(150);
sb.append("```sql\n");
try {
String sql = Files.readString(path);
sb.append(sql, 0, Math.min(sql.length(), 100));
if (sql.length() > 100)
sb.append("...");
} catch (IOException e) {
e.printStackTrace();
sb.append("Error: Could not read SQL: ").append(e.getMessage());
}
sb.append("\n```");
embedBuilder.addField(path.getFileName().toString(), sb.toString(), false);
});
return event.replyEmbeds(embedBuilder.build());
} catch (IOException | URISyntaxException e) {
return Responses.error(event, e.getMessage());
}
}
Aggregations