Search in sources :

Example 6 with UserMessedUpException

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

the class RaidRepository method changeGroup.

public RaidGroup changeGroup(User user, String raidId, String groupCreatorId, LocalDateTime currentStartAt, LocalDateTime newDateTime) {
    final RaidEntity entityByRaidId = findEntityByRaidId(raidId);
    if (entityByRaidId == null) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_RAID_AT_GYM, localeService.getLocaleForUser(user)));
    }
    RaidGroup group = entityByRaidId.getGroupByCreatorAndStart(groupCreatorId, currentStartAt);
    if (group == null) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_SUCH_GROUP, localeService.getLocaleForUser(user)));
    }
    group.setStartsAt(newDateTime);
    raidEntityRepository.save(entityByRaidId);
    return group;
}
Also used : UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 7 with UserMessedUpException

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

the class RaidRepository method moveAllSignUpsForTimeToNewTime.

public void moveAllSignUpsForTimeToNewTime(String raidId, LocalDateTime currentStartAt, LocalDateTime newDateTime, User user) {
    Validate.notNull(raidId, "Raid ID cannot be null");
    Validate.notNull(currentStartAt, "Current start time cannot be null");
    Validate.notNull(newDateTime, "New start time cannot be null");
    Validate.notNull(user, "User cannot be null");
    RaidEntity entity = raidEntityRepository.findOne(raidId);
    if (entity != null) {
        for (RaidEntitySignUp signUp : entity.getSignUpsAsSet()) {
            if (signUp.getArrivalTime().equals(currentStartAt.toLocalTime())) {
                signUp.setEta(Utils.printTime(newDateTime.toLocalTime()));
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Changed ETA for signup: " + signUp);
                }
            }
        }
        raidEntityRepository.save(entity);
    } else {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_RAID_AT_GYM, localeService.getLocaleForUser(user)));
    }
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 8 with UserMessedUpException

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

the class NewRaidExCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final String[] args = commandEvent.getArgs().replaceAll("\\s{1,3}", " ").split(" ");
    if (args.length < 3) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid ex mewtwo 2017-11-11 10:00 solna platform"));
    }
    String pokemonName = args[0];
    final Pokemon pokemon = pokemonRepository.search(pokemonName, user);
    final Locale locale = localeService.getLocaleForUser(user);
    if (!Utils.isRaidExPokemon(pokemon.getName())) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NOT_EX_RAID, locale, pokemonName));
    }
    String dateString = args[1];
    String timeString = args[2];
    LocalTime endsAtTime = Utils.parseTime(user, timeString, localeService);
    LocalDate endsAtDate = Utils.parseDate(user, dateString, localeService);
    LocalDateTime endsAt = LocalDateTime.of(endsAtDate, endsAtTime);
    assertTimeNotInNoRaidTimespan(user, endsAtTime, localeService);
    if (endsAtDate.isAfter(LocalDate.now().plusDays(20))) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.EX_DATE_LIMITS, locale));
    }
    assertCreateRaidTimeNotBeforeNow(user, endsAt, localeService);
    StringBuilder gymNameBuilder = new StringBuilder();
    for (int i = 3; i < args.length; i++) {
        gymNameBuilder.append(args[i]).append(" ");
    }
    String gymName = gymNameBuilder.toString().trim();
    final Gym gym = gymRepository.search(user, gymName, config.getRegion());
    final Raid raid = new Raid(pokemon, endsAt, gym, localeService, config.getRegion());
    if (!raid.isExRaid()) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NOT_EX_RAID, locale, pokemonName));
    }
    raidRepository.newRaid(user, raid, commandEvent.getGuild(), config, "!raid ex " + raid.getPokemon().getName() + " " + printTimeIfSameDay(raid.getEndOfRaid()) + " " + gym.getName());
    replyBasedOnConfig(config, commandEvent, localeService.getMessageFor(LocaleService.NEW_RAID_CREATED, locale, raid.toString(locale)));
}
Also used : Locale(java.util.Locale) LocalDateTime(java.time.LocalDateTime) User(net.dv8tion.jda.core.entities.User) LocalTime(java.time.LocalTime) Raid(pokeraidbot.domain.raid.Raid) LocalDate(java.time.LocalDate) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym) Pokemon(pokeraidbot.domain.pokemon.Pokemon)

Example 9 with UserMessedUpException

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

the class GymCommands method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent event, Config config) {
    final User user = event.getAuthor();
    final String eventArgs = event.getArgs();
    if (!isUserServerMod(event, config) && !isUserAdministrator(event)) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_PERMISSION, localeService.getLocaleForUser(user)));
    }
    if (eventArgs.startsWith("get ")) {
        String gymName = eventArgs.replaceAll("get\\s{1,3}", "").trim();
        final Gym gym = gymRepository.findByName(gymName, config.getRegion());
        replyBasedOnConfig(config, event, "Found gym: " + gym.toStringDetails());
    } else {
        String[] gymArgs = eventArgs.replaceAll("gym\\s{1,3}", "").trim().split(";");
        if (gymArgs == null || gymArgs.length < 4 || gymArgs.length > 4) {
            replyBasedOnConfig(config, event, "Bad syntax, should be: !raid gym add {gymname};{latitude};{longitude};{exgym true or false");
            return;
        } else {
            final Random random = new Random();
            random.setSeed(System.currentTimeMillis());
            Gym gym = new Gym(gymArgs[0], "" + random.nextInt(99999999), gymArgs[1], gymArgs[2], config.getRegion(), Boolean.valueOf(gymArgs[3]));
            gymRepository.addTemporary(user, gym, config.getRegion());
            replyBasedOnConfig(config, event, "Gym added temporarily: " + gym.toStringDetails());
        }
    }
}
Also used : User(net.dv8tion.jda.core.entities.User) Random(java.util.Random) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym)

Example 10 with UserMessedUpException

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

the class TrackingService method addToDbAndCollection.

private void addToDbAndCollection(PokemonTrackingTarget trackingTarget, User user, Config config) {
    UserConfig userConfig = userConfigRepository.findOne(user.getId());
    if (userConfig != null) {
        if (userConfig.hasFreeTrackingSpot()) {
            userConfig.setNextTrackingSpot(trackingTarget.getPokemon());
        } else {
            throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.TRACKING_NONE_FREE, localeService.getLocaleForUser(user)));
        }
    } else {
        // Per default, let user have the same locale as the server
        userConfig = new UserConfig(user.getId(), trackingTarget.getPokemon(), null, null, config.getLocale());
    }
    userConfigRepository.save(userConfig);
    trackingTargets.add(trackingTarget);
}
Also used : UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) UserConfig(pokeraidbot.infrastructure.jpa.config.UserConfig)

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