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();
}
});
}
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()));
}
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()));
}
}
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);
}
}
}
});
}
}
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);
}
}
Aggregations