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