Search in sources :

Example 6 with Meeting

use of de.lightbolt.meeting.systems.meeting.model.Meeting in project LightboltMeeting by LightboltMeeting.

the class DiscardMeetingSubcommand method handleMeetingCommand.

@Override
protected ReplyCallbackAction handleMeetingCommand(SlashCommandInteractionEvent event, LocaleConfig locale, SystemsConfig.MeetingConfig config, MeetingRepository repo) throws SQLException {
    OptionMapping idOption = event.getOption("meeting-id");
    if (idOption == null) {
        return Responses.error(event, locale.getCommand().getMISSING_ARGUMENTS());
    }
    int id = (int) idOption.getAsLong();
    Optional<Meeting> meetingOptional = repo.getById(id);
    if (meetingOptional.isEmpty()) {
        return Responses.error(event, String.format(locale.getMeeting().getCommand().getMEETING_NOT_FOUND(), id));
    }
    Meeting meeting = meetingOptional.get();
    if (!MeetingManager.canEditMeeting(meeting, event.getUser().getIdLong())) {
        return Responses.error(event, locale.getMeeting().getMEETING_NO_PERMISSION());
    }
    MeetingManager manager = new MeetingManager(event.getJDA(), meeting);
    var com = locale.getMeeting().getCommand();
    if (meeting.getStatus() == MeetingStatus.ONGOING) {
        return Responses.error(event, com.getMEETING_DISCARD_FAILED_DESCRIPTION());
    }
    manager.endMeeting();
    return Responses.success(event, com.getCANCEL_MEETING_TITLE(), String.format(com.getCANCEL_MEETING_DESCRIPTION(), id));
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) MeetingManager(de.lightbolt.meeting.systems.meeting.MeetingManager) Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting)

Example 7 with Meeting

use of de.lightbolt.meeting.systems.meeting.model.Meeting 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 8 with Meeting

use of de.lightbolt.meeting.systems.meeting.model.Meeting in project LightboltMeeting by LightboltMeeting.

the class RemoveParticipantSubcommand 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();
    Optional<Meeting> meetingOptional = repo.getById(id);
    if (meetingOptional.isEmpty()) {
        return Responses.error(event, String.format(com.getMEETING_NOT_FOUND(), id));
    }
    var meeting = meetingOptional.get();
    if (!MeetingManager.canEditMeeting(meeting, event.getUser().getIdLong())) {
        return Responses.error(event, locale.getMeeting().getMEETING_NO_PERMISSION());
    }
    var participants = meeting.getParticipants();
    var admins = meeting.getAdmins();
    if (Arrays.stream(participants).anyMatch(x -> x == user.getIdLong())) {
        if (Arrays.stream(admins).anyMatch(x -> x == user.getIdLong())) {
            meeting.setAdmins(ArrayUtils.removeElement(admins, user.getIdLong()));
            repo.update(meeting.getId(), meeting);
        }
        new MeetingManager(event.getJDA(), meeting).removeParticipant(user);
        return Responses.success(event, com.getPARTICIPANTS_REMOVE_SUCCESS_TITLE(), String.format(com.getPARTICIPANTS_REMOVE_SUCCESS_DESCRIPTION(), user.getAsMention(), meeting.getTitle()));
    } else {
        return Responses.error(event, String.format(com.getMEETING_PARTICIPANT_NOT_FOUND(), user.getAsMention()));
    }
}
Also used : MeetingManager(de.lightbolt.meeting.systems.meeting.MeetingManager) Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting)

Example 9 with Meeting

use of de.lightbolt.meeting.systems.meeting.model.Meeting in project LightboltMeeting by LightboltMeeting.

the class MeetingManager method checkActiveMeetings.

/**
 * Checks for missing or unknown Log & Voice channels and creates/deletes them.
 * @param jda The JDA instance
 */
public static void checkActiveMeetings(@NotNull JDA jda) {
    for (var guild : jda.getGuilds()) {
        var config = Bot.config.getSystems().getMeetingConfig();
        DbHelper.doDaoAction(MeetingRepository::new, dao -> {
            List<Meeting> activeMeetings = dao.getActive().stream().filter(p -> p.getGuildId() == guild.getIdLong()).toList();
            for (Meeting m : activeMeetings) {
                MeetingManager manager = new MeetingManager(jda, m);
                Category category = guild.getCategoryById(m.getCategoryId());
                if (category == null) {
                    manager.createMeetingChannels(guild, jda.getUserById(m.getCreatedBy()), m.getLocaleConfig(), config);
                } else {
                    List<Long> channelIds = category.getChannels().stream().map(Channel::getIdLong).toList();
                    if (!channelIds.contains(m.getLogChannelId())) {
                        manager.createLogChannel(category, jda.getUserById(m.getCreatedBy()), m.getLocaleConfig(), config);
                    }
                    if (!channelIds.contains(m.getVoiceChannelId())) {
                        manager.createVoiceChannel(category, config);
                    }
                }
            }
        });
    }
}
Also used : net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) Arrays(java.util.Arrays) JDA(net.dv8tion.jda.api.JDA) LocalizationUtils(de.lightbolt.meeting.utils.localization.LocalizationUtils) Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting) Bot(de.lightbolt.meeting.Bot) Permission(net.dv8tion.jda.api.Permission) RequiredArgsConstructor(lombok.RequiredArgsConstructor) MeetingRepository(de.lightbolt.meeting.systems.meeting.dao.MeetingRepository) ArrayUtils(org.apache.commons.lang3.ArrayUtils) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) DbHelper(de.lightbolt.meeting.data.h2db.DbHelper) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) Button(net.dv8tion.jda.api.interactions.components.buttons.Button) List(java.util.List) SystemsConfig(de.lightbolt.meeting.data.config.SystemsConfig) LocaleConfig(de.lightbolt.meeting.utils.localization.LocaleConfig) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting) MeetingRepository(de.lightbolt.meeting.systems.meeting.dao.MeetingRepository)

Example 10 with Meeting

use of de.lightbolt.meeting.systems.meeting.model.Meeting in project LightboltMeeting by LightboltMeeting.

the class MeetingRepository method getById.

public Optional<Meeting> getById(int id) throws SQLException {
    Meeting meeting = null;
    try (var s = con.prepareStatement("SELECT * FROM meetings WHERE id = ? AND status != 'INACTIVE'", Statement.RETURN_GENERATED_KEYS)) {
        s.setInt(1, id);
        var rs = s.executeQuery();
        if (rs.next()) {
            meeting = this.read(rs);
        }
        rs.close();
    }
    return Optional.ofNullable(meeting);
}
Also used : Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting)

Aggregations

Meeting (de.lightbolt.meeting.systems.meeting.model.Meeting)13 MeetingManager (de.lightbolt.meeting.systems.meeting.MeetingManager)9 MeetingRepository (de.lightbolt.meeting.systems.meeting.dao.MeetingRepository)5 OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)4 SystemsConfig (de.lightbolt.meeting.data.config.SystemsConfig)3 LocaleConfig (de.lightbolt.meeting.utils.localization.LocaleConfig)3 Arrays (java.util.Arrays)3 Responses (de.lightbolt.meeting.command.Responses)2 MeetingSubcommand (de.lightbolt.meeting.systems.meeting.MeetingSubcommand)2 SQLException (java.sql.SQLException)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 Bot (de.lightbolt.meeting.Bot)1 DbHelper (de.lightbolt.meeting.data.h2db.DbHelper)1 LocalizationUtils (de.lightbolt.meeting.utils.localization.LocalizationUtils)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1