Search in sources :

Example 1 with ReplyCallbackAction

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()));
}
Also used : SQLException(java.sql.SQLException) Arrays(java.util.Arrays) Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting) Responses(de.lightbolt.meeting.command.Responses) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) Optional(java.util.Optional) SystemsConfig(de.lightbolt.meeting.data.config.SystemsConfig) MeetingRepository(de.lightbolt.meeting.systems.meeting.dao.MeetingRepository) MeetingManager(de.lightbolt.meeting.systems.meeting.MeetingManager) LocaleConfig(de.lightbolt.meeting.utils.localization.LocaleConfig) MeetingSubcommand(de.lightbolt.meeting.systems.meeting.MeetingSubcommand) ReplyCallbackAction(net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction) MeetingManager(de.lightbolt.meeting.systems.meeting.MeetingManager) Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting)

Example 2 with ReplyCallbackAction

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()));
    }
}
Also used : SQLException(java.sql.SQLException) Arrays(java.util.Arrays) Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting) Responses(de.lightbolt.meeting.command.Responses) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) Optional(java.util.Optional) SystemsConfig(de.lightbolt.meeting.data.config.SystemsConfig) MeetingRepository(de.lightbolt.meeting.systems.meeting.dao.MeetingRepository) MeetingManager(de.lightbolt.meeting.systems.meeting.MeetingManager) LocaleConfig(de.lightbolt.meeting.utils.localization.LocaleConfig) MeetingSubcommand(de.lightbolt.meeting.systems.meeting.MeetingSubcommand) ReplyCallbackAction(net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction) MeetingManager(de.lightbolt.meeting.systems.meeting.MeetingManager) Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting)

Example 3 with ReplyCallbackAction

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));
}
Also used : Message(net.dv8tion.jda.api.entities.Message) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) ReplyCallbackAction(net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction) Test(org.junit.jupiter.api.Test)

Example 4 with ReplyCallbackAction

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));
}
Also used : Message(net.dv8tion.jda.api.entities.Message) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) ReplyCallbackAction(net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction) Test(org.junit.jupiter.api.Test)

Example 5 with ReplyCallbackAction

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());
    }
}
Also used : ISlashCommand(net.javadiscord.javabot.command.interfaces.ISlashCommand) Files(java.nio.file.Files) Responses(net.javadiscord.javabot.command.Responses) URISyntaxException(java.net.URISyntaxException) MigrationUtils(net.javadiscord.javabot.data.h2db.MigrationUtils) SlashCommandInteractionEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent) IOException(java.io.IOException) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) ReplyCallbackAction(net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException)

Aggregations

ReplyCallbackAction (net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction)7 SlashCommandInteractionEvent (net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent)5 Message (net.dv8tion.jda.api.entities.Message)4 Test (org.junit.jupiter.api.Test)3 Responses (de.lightbolt.meeting.command.Responses)2 SystemsConfig (de.lightbolt.meeting.data.config.SystemsConfig)2 MeetingManager (de.lightbolt.meeting.systems.meeting.MeetingManager)2 MeetingSubcommand (de.lightbolt.meeting.systems.meeting.MeetingSubcommand)2 MeetingRepository (de.lightbolt.meeting.systems.meeting.dao.MeetingRepository)2 Meeting (de.lightbolt.meeting.systems.meeting.model.Meeting)2 LocaleConfig (de.lightbolt.meeting.utils.localization.LocaleConfig)2 SQLException (java.sql.SQLException)2 Arrays (java.util.Arrays)2 Optional (java.util.Optional)2 DiscordEmbedTag (com.denizenscript.ddiscordbot.objects.DiscordEmbedTag)1 DiscordInteractionTag (com.denizenscript.ddiscordbot.objects.DiscordInteractionTag)1 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)1 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 IOException (java.io.IOException)1