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