Search in sources :

Example 26 with UserMessedUpException

use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.

the class Utils method assertSignupTimeNotBeforeRaidStartAndNow.

public static void assertSignupTimeNotBeforeRaidStartAndNow(User user, LocalDateTime dateAndTime, LocalDateTime endOfRaid, LocaleService localeService, boolean isExRaid) {
    final LocalDateTime startOfRaid = getStartOfRaid(endOfRaid, isExRaid);
    final LocalDateTime now = clockService.getCurrentDateTime();
    assertSignupTimeNotBeforeRaidStart(user, dateAndTime, endOfRaid, localeService, isExRaid);
    if (dateAndTime.isBefore(now)) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.SIGN_BEFORE_NOW, localeService.getLocaleForUser(user), printTimeIfSameDay(dateAndTime), printTimeIfSameDay(now)));
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException)

Example 27 with UserMessedUpException

use of pokeraidbot.domain.errors.UserMessedUpException 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)));
    }
}
Also used : MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) EmoticonSignUpMessageListener(pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) Raid(pokeraidbot.domain.raid.Raid)

Example 28 with UserMessedUpException

use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.

the class AlterRaidCommand method getGroupToDelete.

private RaidGroup getGroupToDelete(User user, LocalTime existingGroupTimeIfAvailable, Set<RaidGroup> groups, Raid raid) {
    RaidGroup theGroupToDelete = null;
    final Locale localeForUser = localeService.getLocaleForUser(user);
    if (groups.size() > 1 && (existingGroupTimeIfAvailable == null)) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.MANY_GROUPS_FOR_RAID, localeForUser, raid.toString(localeForUser)));
    } else if (groups.size() == 1) {
        theGroupToDelete = groups.iterator().next();
    } else {
        for (RaidGroup g : groups) {
            if (g.getStartsAt().toLocalTime().equals(existingGroupTimeIfAvailable)) {
                theGroupToDelete = g;
                break;
            }
        }
    }
    if (theGroupToDelete == null) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_SUCH_GROUP, localeForUser));
    }
    return theGroupToDelete;
}
Also used : Locale(java.util.Locale) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup)

Example 29 with UserMessedUpException

use of pokeraidbot.domain.errors.UserMessedUpException 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);
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) EmoticonSignUpMessageListener(pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) Raid(pokeraidbot.domain.raid.Raid)

Example 30 with UserMessedUpException

use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.

the class AlterRaidCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final String userName = user.getName();
    final String[] args = commandEvent.getArgs().split(" ");
    String whatToChange = args[0].trim().toLowerCase();
    switch(whatToChange) {
        case "when":
            changeWhen(commandEvent, config, user, args);
            break;
        case "pokemon":
            if (args.length < 2) {
                throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid change {when/pokemon/remove/group} {params}"));
            }
            changePokemon(gymRepository, localeService, pokemonRepository, raidRepository, commandEvent, config, user, userName, args[1].trim().toLowerCase(), ArrayUtils.removeAll(args, 0, 1));
            break;
        case "remove":
            deleteRaidAndGroups(commandEvent, config, user, userName, args);
            break;
        case "group":
            changeOrDeleteGroup(commandEvent, config, user, userName, args);
            break;
        default:
            throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid change {when/pokemon/remove/group} {params}"));
    }
}
Also used : User(net.dv8tion.jda.core.entities.User) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException)

Aggregations

UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)32 Locale (java.util.Locale)13 User (net.dv8tion.jda.core.entities.User)12 Gym (pokeraidbot.domain.gym.Gym)12 Raid (pokeraidbot.domain.raid.Raid)11 LocalDateTime (java.time.LocalDateTime)8 LocalTime (java.time.LocalTime)7 Pokemon (pokeraidbot.domain.pokemon.Pokemon)6 RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)5 EmoticonSignUpMessageListener (pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener)4 RaidEntity (pokeraidbot.infrastructure.jpa.raid.RaidEntity)4 UserConfig (pokeraidbot.infrastructure.jpa.config.UserConfig)3 RaidEntitySignUp (pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp)3 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)2 ErrorResponseException (net.dv8tion.jda.core.exceptions.ErrorResponseException)2 SignUp (pokeraidbot.domain.raid.signup.SignUp)2 LocalDate (java.time.LocalDate)1 DateTimeParseException (java.time.format.DateTimeParseException)1 Random (java.util.Random)1 TimeUnit (java.util.concurrent.TimeUnit)1