Search in sources :

Example 1 with WrongNumberOfArgumentsException

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

the class RaidRepository method executeSignUpCommand.

public String executeSignUpCommand(Config config, User user, Locale localeForUser, String[] args, String help) {
    String people = args[0];
    String userName = user.getName();
    if (args.length < 3 || args.length > 10) {
        throw new WrongNumberOfArgumentsException(user, localeService, 3, args.length, help);
    }
    Integer numberOfPeople = Utils.assertNotTooManyOrNoNumber(user, localeService, people);
    String timeString = args[1];
    StringBuilder gymNameBuilder = new StringBuilder();
    for (int i = 2; 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 = getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
    LocalTime eta = Utils.parseTime(user, timeString, localeService);
    LocalDateTime realEta = LocalDateTime.of(raid.getEndOfRaid().toLocalDate(), eta);
    assertEtaNotAfterRaidEnd(user, raid, realEta, localeService);
    assertSignupTimeNotBeforeRaidStartAndNow(user, realEta, raid.getEndOfRaid(), localeService, raid.isExRaid());
    raid.signUp(user, numberOfPeople, eta, this);
    final String currentSignupText = localeService.getMessageFor(LocaleService.CURRENT_SIGNUPS, localeForUser);
    final Set<SignUp> signUps = raid.getSignUps();
    Set<String> signUpNames = Utils.getNamesOfThoseWithSignUps(signUps, true);
    final String allSignUpNames = StringUtils.join(signUpNames, ", ");
    final String signUpText = raid.getSignUps().size() > 1 ? currentSignupText + "\n" + allSignUpNames : "";
    return localeService.getMessageFor(LocaleService.SIGNUPS, localeForUser, userName, gym.getName(), signUpText);
}
Also used : LocalDateTime(java.time.LocalDateTime) RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) SignUp(pokeraidbot.domain.raid.signup.SignUp) WrongNumberOfArgumentsException(pokeraidbot.domain.errors.WrongNumberOfArgumentsException) LocalTime(java.time.LocalTime) Gym(pokeraidbot.domain.gym.Gym)

Example 2 with WrongNumberOfArgumentsException

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

the class RaidRepository method executeUnsignCommand.

public String executeUnsignCommand(Config config, User user, Locale localeForUser, String[] args, String help) {
    String people = args[0];
    String userName = user.getName();
    if (args.length < 2 || args.length > 10) {
        throw new WrongNumberOfArgumentsException(user, localeService, 2, args.length, help);
    }
    Integer numberOfPeople = Utils.assertNotTooManyOrNoNumber(user, localeService, people);
    StringBuilder gymNameBuilder = new StringBuilder();
    for (int i = 1; i < args.length; i++) {
        gymNameBuilder.append(args[i]).append(" ");
    }
    String gymName = gymNameBuilder.toString().trim();
    final Gym gym = gymRepository.search(user, gymName, config.getRegion());
    Raid raid = getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
    final RaidEntitySignUp signUp = findEntityByRaidId(raid.getId()).getSignUp(user.getName());
    if (signUp == null) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_SIGNUP_AT_GYM, localeForUser, user.getName(), gym.getName()));
    }
    raid = removeFromSignUp(raid.getId(), user, 0, 0, 0, numberOfPeople, LocalDateTime.of(raid.getEndOfRaid().toLocalDate(), signUp.getArrivalTime()));
    final String currentSignupText = localeService.getMessageFor(LocaleService.CURRENT_SIGNUPS, localeForUser);
    final Set<SignUp> signUps = raid.getSignUps();
    Set<String> signUpNames = Utils.getNamesOfThoseWithSignUps(signUps, true);
    final String allSignUpNames = StringUtils.join(signUpNames, ", ");
    final String signUpText = raid.getSignUps().size() > 1 ? currentSignupText + "\n" + allSignUpNames : "";
    return localeService.getMessageFor(LocaleService.UNSIGN, localeForUser, userName, gym.getName(), signUpText);
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) SignUp(pokeraidbot.domain.raid.signup.SignUp) WrongNumberOfArgumentsException(pokeraidbot.domain.errors.WrongNumberOfArgumentsException) RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym)

Aggregations

WrongNumberOfArgumentsException (pokeraidbot.domain.errors.WrongNumberOfArgumentsException)2 Gym (pokeraidbot.domain.gym.Gym)2 SignUp (pokeraidbot.domain.raid.signup.SignUp)2 RaidEntitySignUp (pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp)2 LocalDateTime (java.time.LocalDateTime)1 LocalTime (java.time.LocalTime)1 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)1