Search in sources :

Example 1 with MeetingManager

use of de.lightbolt.meeting.systems.meeting.MeetingManager 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 MeetingManager

use of de.lightbolt.meeting.systems.meeting.MeetingManager in project LightboltMeeting by LightboltMeeting.

the class EndMeetingSubcommand 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_END_FAILED_DESCRIPTION());
    }
    manager.endMeeting();
    return Responses.success(event, com.getMEETING_END_SUCCESS_TITLE(), String.format(com.getMEETING_END_SUCCESS_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 3 with MeetingManager

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

use of de.lightbolt.meeting.systems.meeting.MeetingManager in project LightboltMeeting by LightboltMeeting.

the class AddParticipantSubcommand method handleMeetingCommand.

@Override
protected ReplyCallbackAction handleMeetingCommand(SlashCommandInteractionEvent event, LocaleConfig locale, SystemsConfig.MeetingConfig config, MeetingRepository repo) throws SQLException {
    var idOption = event.getOption("meeting-id");
    if (idOption == null) {
        return Responses.error(event, locale.getCommand().getMISSING_ARGUMENTS());
    }
    List<User> users = new ArrayList<>();
    for (int i = 1; i < MEMBER_OPTIONS + 1; i++) {
        var userOption = event.getOption("user-" + i);
        if (userOption == null)
            continue;
        users.add(userOption.getAsUser());
    }
    var id = (int) idOption.getAsLong();
    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());
    }
    long[] participants = meeting.getParticipants();
    for (User user : users) {
        if (Arrays.stream(participants).anyMatch(x -> x == user.getIdLong())) {
            return Responses.error(event, String.format(com.getMEETING_PARTICIPANT_ALREADY_ADDED(), user.getAsMention()));
        }
    }
    MeetingManager manager = new MeetingManager(event.getJDA(), meeting);
    manager.addParticipants(users.stream().mapToLong(User::getIdLong).toArray());
    return Responses.success(event, com.getPARTICIPANTS_ADD_SUCCESS_TITLE(), String.format(com.getPARTICIPANTS_ADD_SUCCESS_DESCRIPTION(), users.stream().map(User::getAsMention).collect(Collectors.joining(", ")), meeting.getTitle()));
}
Also used : MeetingManager(de.lightbolt.meeting.systems.meeting.MeetingManager) User(net.dv8tion.jda.api.entities.User) Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting) ArrayList(java.util.ArrayList)

Example 5 with MeetingManager

use of de.lightbolt.meeting.systems.meeting.MeetingManager 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)

Aggregations

MeetingManager (de.lightbolt.meeting.systems.meeting.MeetingManager)9 Meeting (de.lightbolt.meeting.systems.meeting.model.Meeting)9 MeetingRepository (de.lightbolt.meeting.systems.meeting.dao.MeetingRepository)4 OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)3 Responses (de.lightbolt.meeting.command.Responses)2 SystemsConfig (de.lightbolt.meeting.data.config.SystemsConfig)2 MeetingSubcommand (de.lightbolt.meeting.systems.meeting.MeetingSubcommand)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 ArrayList (java.util.ArrayList)1 User (net.dv8tion.jda.api.entities.User)1