use of de.lightbolt.meeting.utils.localization.LocaleConfig 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.utils.localization.LocaleConfig 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()));
}
}
Aggregations