use of pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener in project pokeraidbot by magnusmickelsson.
the class AlterRaidCommand method deleteRaidAndGroups.
private void deleteRaidAndGroups(CommandEvent commandEvent, Config config, User user, String userName, String[] args) {
StringBuilder gymNameBuilder;
String gymName;
Gym gym;
gymNameBuilder = new StringBuilder();
for (int i = 1; i < args.length; i++) {
gymNameBuilder.append(args[i]).append(" ");
}
gymName = gymNameBuilder.toString().trim();
gym = gymRepository.search(user, gymName, config.getRegion());
Raid deleteRaid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
verifyPermission(localeService, commandEvent, user, deleteRaid, config);
final boolean userIsNotAdministrator = !isUserAdministrator(commandEvent);
final boolean userIsNotMod = !isUserServerMod(commandEvent, config);
if ((userIsNotAdministrator && userIsNotMod) && deleteRaid.getSignUps().size() > 0) {
throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.ONLY_ADMINS_REMOVE_RAID, localeService.getLocaleForUser(user)));
}
final Set<RaidGroup> groups = raidRepository.getGroups(deleteRaid);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Deleting " + groups.size() + " groups associated with raid " + deleteRaid + "... ");
}
final int numberOfGroups = groups.size();
for (RaidGroup group : groups) {
final EmoticonSignUpMessageListener listener = getListenerForGroup(deleteRaid, group);
if (listener != null) {
final MessageChannel channel = getChannel(commandEvent.getGuild(), group.getChannel());
if (channel != null) {
NewRaidGroupCommand.cleanUpRaidGroupAndDeleteSignUpsIfPossible(channel, group.getStartsAt(), deleteRaid.getId(), listener, raidRepository, botService, group.getId());
} else {
LOGGER.debug("Could not find channel " + group.getChannel() + " in guild " + commandEvent.getGuild().getName());
}
}
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Groups deleted for raid " + deleteRaid);
}
if (raidRepository.delete(deleteRaid)) {
commandEvent.reactSuccess();
removeOriginMessageIfConfigSaysSo(config, commandEvent);
LOGGER.info("Deleted raid (and " + numberOfGroups + " related groups): " + deleteRaid);
} else {
throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.RAID_NOT_EXISTS, localeService.getLocaleForUser(user)));
}
}
use of pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener in project pokeraidbot by magnusmickelsson.
the class AlterRaidCommand method getListenersAdminCanChange.
private Set<EmoticonSignUpMessageListener> getListenersAdminCanChange(CommandEvent commandEvent, Config config, Raid raid) {
Set<EmoticonSignUpMessageListener> listenersToCheck = new HashSet<>();
for (Object o : botService.getBot().getRegisteredListeners()) {
if (o instanceof EmoticonSignUpMessageListener) {
EmoticonSignUpMessageListener listener = (EmoticonSignUpMessageListener) o;
final String raidId = raid.getId();
final boolean isCorrectRaid = raidId.equals(listener.getRaidId());
if (isCorrectRaid && (isUserAdministrator(commandEvent) || isUserServerMod(commandEvent, config))) {
listenersToCheck.add(listener);
}
}
}
return listenersToCheck;
}
use of pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener in project pokeraidbot by magnusmickelsson.
the class AlterRaidCommand method changeOrDeleteGroup.
private void changeOrDeleteGroup(CommandEvent commandEvent, Config config, User user, String userName, String[] args) {
String whatToChangeTo;
String gymName;
Gym gym;
Raid raid;
whatToChangeTo = args[1].trim().toLowerCase();
String originalTime = preProcessTimeString(args[2].trim());
LocalTime existingGroupTimeIfAvailable = null;
try {
existingGroupTimeIfAvailable = Utils.parseTime(user, originalTime, localeService);
} catch (UserMessedUpException e) {
// Input was not a time
}
gymName = getGymName(args, existingGroupTimeIfAvailable);
gym = gymRepository.search(user, gymName, config.getRegion());
raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
if (whatToChangeTo.equals("remove")) {
final Set<RaidGroup> groups = raidRepository.getGroups(raid);
final Set<EmoticonSignUpMessageListener> listenersToCheck = getListenersToCheck(commandEvent, config, user, raid, groups);
EmoticonSignUpMessageListener listener = listenersToCheck.iterator().next();
verifyIsModOrHasGroupForRaid(commandEvent, user, raid, config);
RaidGroup theGroupToDelete = getGroupToDelete(user, existingGroupTimeIfAvailable, groups, raid);
assertPermissionToManageThisGroup(user, theGroupToDelete, commandEvent, config);
NewRaidGroupCommand.cleanUpGroupMessageAndEntity(commandEvent.getChannel(), raid.getId(), listener, raidRepository, botService, theGroupToDelete.getId(), raid.toString());
final String message = localeService.getMessageFor(LocaleService.GROUP_DELETED, localeService.getLocaleForUser(user));
replyBasedOnConfig(config, commandEvent, message);
} else {
LocalTime newTime = parseTime(user, whatToChangeTo, localeService);
LocalDateTime newDateTime = LocalDateTime.of(raid.getEndOfRaid().toLocalDate(), newTime);
checkIfInputIsValidAndUserHasRights(commandEvent, config, user, raid, newDateTime);
if (changeGroupTime(commandEvent, config, user, userName, raid, newDateTime))
return;
}
removeOriginMessageIfConfigSaysSo(config, commandEvent);
}
Aggregations