Search in sources :

Example 1 with LocaleConfig

use of de.lightbolt.meeting.utils.localization.LocaleConfig 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 LocaleConfig

use of de.lightbolt.meeting.utils.localization.LocaleConfig 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)

Aggregations

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 SlashCommandInteractionEvent (net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent)2 ReplyCallbackAction (net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction)2