Search in sources :

Example 1 with MeetingRepository

use of de.lightbolt.meeting.systems.meeting.dao.MeetingRepository in project LightboltMeeting by LightboltMeeting.

the class MeetingReminderJob method execute.

@Override
public void execute(JobExecutionContext context) {
    String[] jobDetail = context.getJobDetail().getKey().getName().split("-");
    DbHelper.doDaoAction(MeetingRepository::new, dao -> {
        Optional<Meeting> meetingOptional = dao.getById(Integer.parseInt(jobDetail[0]));
        if (meetingOptional.isEmpty()) {
            log.warn("Meeting doesn't exist, cannot execute reminder job.");
            return;
        }
        Meeting meeting = meetingOptional.get();
        MeetingManager manager = new MeetingManager(Bot.jda, meeting);
        int reminder = Integer.parseInt(jobDetail[2]);
        manager.getLogChannel().sendMessageFormat(Arrays.stream(meeting.getParticipants()).mapToObj(l -> String.format("<@%s>", l)).collect(Collectors.joining(", "))).setEmbeds(buildReminderEmbed(meeting.getLocaleConfig().getMeeting().getLog(), reminder)).queue();
        if (reminder < STARTING_SOON_THRESHOLD) {
            var config = Bot.config.getSystems().getMeetingConfig();
            manager.getVoiceChannel().getManager().setName(String.format(config.getMeetingVoiceTemplate(), config.getMeetingStartingSoonEmoji(), meeting.getLocaleConfig().getMeeting().getMEETING_STATUS_STARTING_SOON())).queue();
        }
    });
}
Also used : MeetingManager(de.lightbolt.meeting.systems.meeting.MeetingManager) Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting) MeetingRepository(de.lightbolt.meeting.systems.meeting.dao.MeetingRepository)

Example 2 with MeetingRepository

use of de.lightbolt.meeting.systems.meeting.dao.MeetingRepository 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 3 with MeetingRepository

use of de.lightbolt.meeting.systems.meeting.dao.MeetingRepository 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 4 with MeetingRepository

use of de.lightbolt.meeting.systems.meeting.dao.MeetingRepository 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 5 with MeetingRepository

use of de.lightbolt.meeting.systems.meeting.dao.MeetingRepository in project LightboltMeeting by LightboltMeeting.

the class MeetingSubcommand method handleSlashCommandInteraction.

@Override
public ReplyCallbackAction handleSlashCommandInteraction(SlashCommandInteractionEvent event) throws ResponseException {
    try (var con = Bot.dataSource.getConnection()) {
        con.setAutoCommit(true);
        var reply = this.handleMeetingCommand(event, LocalizationUtils.getLocale(Language.fromLocale(event.getUserLocale())), Bot.config.getSystems().getMeetingConfig(), new MeetingRepository(con));
        con.commit();
        return reply;
    } catch (SQLException e) {
        throw ResponseException.error("An error occurred while the bot was trying to execute a Meeting subcommand.", e);
    }
}
Also used : SQLException(java.sql.SQLException) MeetingRepository(de.lightbolt.meeting.systems.meeting.dao.MeetingRepository)

Aggregations

MeetingRepository (de.lightbolt.meeting.systems.meeting.dao.MeetingRepository)6 Meeting (de.lightbolt.meeting.systems.meeting.model.Meeting)5 MeetingManager (de.lightbolt.meeting.systems.meeting.MeetingManager)4 SystemsConfig (de.lightbolt.meeting.data.config.SystemsConfig)3 LocaleConfig (de.lightbolt.meeting.utils.localization.LocaleConfig)3 SQLException (java.sql.SQLException)3 Arrays (java.util.Arrays)3 Responses (de.lightbolt.meeting.command.Responses)2 MeetingSubcommand (de.lightbolt.meeting.systems.meeting.MeetingSubcommand)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 Collections (java.util.Collections)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 RequiredArgsConstructor (lombok.RequiredArgsConstructor)1 Slf4j (lombok.extern.slf4j.Slf4j)1