Search in sources :

Example 16 with UserMessedUpException

use of pokeraidbot.domain.errors.UserMessedUpException 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)

Example 17 with UserMessedUpException

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

the class RaidRepository method newGroupForRaid.

public RaidGroup newGroupForRaid(User user, RaidGroup group, Raid raid, Guild guild, Config config) {
    Validate.notNull(user, "User");
    Validate.notNull(group, "Group");
    Validate.notNull(raid, "Raid");
    Validate.notEmpty(raid.getId(), "Raid ID");
    RaidEntity raidEntity = findEntityByRaidId(raid.getId());
    final boolean added = raidEntity.addGroup(group);
    if (!added) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.GROUP_NOT_ADDED, localeService.getLocaleForUser(user), String.valueOf(raid)));
    }
    return group;
}
Also used : UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 18 with UserMessedUpException

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

the class RaidRepository method removeFromSignUp.

public Raid removeFromSignUp(String raidId, User user, int mystic, int instinct, int valor, int plebs, LocalDateTime startAt) {
    RaidEntity raidEntity = findEntityByRaidId(raidId);
    if (raidEntity == null) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_RAID_AT_GYM, localeService.getLocaleForUser(user)));
    }
    RaidEntitySignUp signUp = raidEntity.getSignUp(user.getName());
    final String startAtTime = Utils.printTime(startAt.toLocalTime());
    if (signUp == null) {
    // Ignore this case, when there is no signup to remove from. Silent ignore.
    } else if (startAtTime.equals(signUp.getEta())) {
        final int sum = signUp.getNumberOfPeople() - mystic - instinct - valor - plebs;
        if (sum <= 0) {
            // Remove signup
            raidEntity.removeSignUp(signUp);
        } else {
            signUp.setNumberOfPeople(sum, localeService, user);
        }
        raidEntity = raidEntityRepository.save(raidEntity);
    } else {
    // Ignore if they're trying to remove signups for a group they're no longer signed up for - we let them untick their emote
    }
    return getRaidInstance(raidEntity);
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 19 with UserMessedUpException

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

the class StartRaidAndCreateGroupCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final String[] args = commandEvent.getArgs().split(" ");
    final Locale locale = localeService.getLocaleForUser(user);
    if (args.length < 2) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid start-group groudon 10:00 solna platform"));
    }
    String pokemonName = args[0].trim();
    Pokemon pokemon = pokemonRepository.search(pokemonName, user);
    String timeString = args[1].trim();
    LocalTime startAtTime = Utils.parseTime(user, timeString, localeService);
    assertTimeNotInNoRaidTimespan(user, startAtTime, localeService);
    StringBuilder gymNameBuilder = new StringBuilder();
    for (int i = 2; i < args.length; i++) {
        gymNameBuilder.append(args[i]).append(" ");
    }
    String gymName = gymNameBuilder.toString().trim();
    final String region = config.getRegion();
    final Gym gym = gymRepository.search(user, gymName, region);
    final Raid raid;
    if (!raidRepository.isActiveOrExRaidAt(gym, region)) {
        final LocalDateTime endOfRaid = LocalDateTime.of(LocalDate.now(), startAtTime.plusMinutes(Utils.RAID_DURATION_IN_MINUTES));
        raid = raidRepository.newRaid(user, new Raid(pokemon, endOfRaid, gym, localeService, region), commandEvent.getGuild(), config, commandEvent.getMessage().getRawContent());
    } else {
        raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, region, user);
    }
    createRaidGroup(commandEvent.getChannel(), commandEvent.getGuild(), config, user, locale, startAtTime, raid.getId(), localeService, raidRepository, botService, serverConfigRepository, pokemonRepository, gymRepository, clockService, executorService, pokemonRaidStrategyService);
    commandEvent.reactSuccess();
    removeOriginMessageIfConfigSaysSo(config, commandEvent);
}
Also used : Locale(java.util.Locale) LocalDateTime(java.time.LocalDateTime) User(net.dv8tion.jda.core.entities.User) LocalTime(java.time.LocalTime) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym) Pokemon(pokeraidbot.domain.pokemon.Pokemon) Raid(pokeraidbot.domain.raid.Raid)

Example 20 with UserMessedUpException

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

the class UserConfigCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config serverConfig) {
    final User user = commandEvent.getAuthor();
    UserConfig userConfig = userConfigRepository.findOne(user.getId());
    final String[] arguments = commandEvent.getArgs().split(" ");
    if (arguments.length > 1 || arguments.length < 1) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.USER_CONFIG_BAD_SYNTAX, localeService.getLocaleForUser(user)));
    }
    if ("show".equalsIgnoreCase(arguments[0])) {
        if (userConfig == null) {
            userConfig = userConfigRepository.save(new UserConfig(user.getId(), null, null, null, serverConfig.getLocale()));
        }
        replyBasedOnConfig(serverConfig, commandEvent, String.valueOf(userConfig));
    } else {
        final String[] paramAndValue = arguments[0].split("=");
        if (paramAndValue.length > 2 || paramAndValue.length < 2) {
            throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.USER_CONFIG_BAD_SYNTAX, localeService.getLocaleForUser(user)));
        }
        String param = paramAndValue[0];
        String value = paramAndValue[1];
        switch(param.toLowerCase()) {
            case "locale":
                final Locale newLocale = setLocaleForUser(user, userConfig, value);
                replyBasedOnConfigAndRemoveAfter(serverConfig, commandEvent, localeService.getMessageFor(LocaleService.LOCALE_SET, localeService.getLocaleForUser(user), newLocale.getLanguage()), BotServerMain.timeToRemoveFeedbackInSeconds);
                break;
            case "nick":
                userConfig = setNickForUser(serverConfig, user, userConfig, value);
                replyBasedOnConfig(serverConfig, commandEvent, String.valueOf(userConfig));
                break;
            default:
                throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.USER_CONFIG_BAD_PARAM, localeService.getLocaleForUser(user), param));
        }
    }
}
Also used : Locale(java.util.Locale) User(net.dv8tion.jda.core.entities.User) 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