Search in sources :

Example 1 with Gym

use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.

the class GymDataImportTool method reportDiffBetweenOldAndNewFileIfExists.

private static void reportDiffBetweenOldAndNewFileIfExists(String location) {
    try {
        CSVGymDataReader oldGymDataReader = new CSVGymDataReader("/gyms_" + location + ".csv");
        InputStream exStream = GymDataImportTool.class.getResourceAsStream("/gyms_" + location + ".csv.ex.txt");
        CSVGymDataReader newGymDataReader;
        if (exStream != null) {
            newGymDataReader = new CSVGymDataReader(new FileInputStream("target/" + location + ".csv"), exStream);
        } else {
            newGymDataReader = new CSVGymDataReader(new FileInputStream("target/" + location + ".csv"));
        }
        final Set<Gym> oldGyms = oldGymDataReader.readAll();
        final Set<Gym> newGyms = newGymDataReader.readAll();
        int sameCount = 0;
        LinkedList<String> report = new LinkedList<>();
        LinkedList<String> focusReport = new LinkedList<>();
        for (Gym newGym : newGyms) {
            if (!oldGyms.contains(newGym)) {
                boolean weird = false;
                for (Gym oldGym : oldGyms) {
                    if (oldGym.getX().equals(newGym.getX()) && oldGym.getY().equals(newGym.getY())) {
                        focusReport.add("New name for old gym? Old: " + oldGym + " - New: " + newGym);
                        weird = true;
                    } else if (oldGym.getId().equals(newGym.getId())) {
                        focusReport.add("Reused ID for old gym? Old: " + oldGym + " - New: " + newGym);
                        weird = true;
                    } else if (oldGym.getName().trim().equalsIgnoreCase(newGym.getName().trim())) {
                        focusReport.add("Potential duplicate. Old: " + oldGym + " - New: " + newGym);
                        weird = true;
                    }
                }
                if (!weird) {
                    focusReport.add("New gym: " + newGym);
                }
            } else {
                sameCount++;
            }
        }
        for (Gym oldGym : oldGyms) {
            boolean weird = false;
            if (!newGyms.contains(oldGym)) {
                for (Gym newGym : newGyms) {
                    if (oldGym.getX().equals(newGym.getX()) && oldGym.getY().equals(newGym.getY())) {
                        LOGGER.debug("OLD: New name for old gym? Old: " + oldGym + " - New: " + newGym);
                        weird = true;
                    } else if (oldGym.getId().equals(newGym.getId())) {
                        LOGGER.debug("OLD: Reused ID for old gym? Old: " + oldGym + " - New: " + newGym);
                        weird = true;
                    } else if (oldGym.getName().equalsIgnoreCase(newGym.getName())) {
                        LOGGER.debug("OLD: Potential duplicate. Old: " + oldGym + " - New: " + newGym);
                        weird = true;
                    }
                }
                if (!weird) {
                    report.add("Removed gym: " + oldGym);
                }
            } else {
                report.add("Exists in old and new: " + oldGym);
            }
        }
        for (String r : report) {
            System.out.println(r);
        }
        for (String r : focusReport) {
            System.out.println(r);
        }
        System.out.println("\nREPORT:\n\nOld gyms: " + oldGyms.size() + ", new gyms: " + newGyms.size() + ", diff: " + (newGyms.size() - oldGyms.size()) + ", same in both: " + sameCount);
    } catch (Throwable t) {
        System.out.printf("Could not perform a diff between old gym file and new one: " + t.getMessage());
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Gym(pokeraidbot.domain.gym.Gym) CSVGymDataReader(pokeraidbot.infrastructure.CSVGymDataReader) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList)

Example 2 with Gym

use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.

the class AlterRaidCommand method changePokemon.

// todo: move to service
public static void changePokemon(GymRepository gymRepository, LocaleService localeService, PokemonRepository pokemonRepository, RaidRepository raidRepository, CommandEvent commandEvent, Config config, User user, String userName, String newPokemonName, String... gymArguments) {
    String whatToChangeTo;
    StringBuilder gymNameBuilder;
    String gymName;
    Gym gym;
    Raid raid;
    whatToChangeTo = newPokemonName;
    gymNameBuilder = new StringBuilder();
    for (String arg : gymArguments) {
        gymNameBuilder.append(arg).append(" ");
    }
    gymName = gymNameBuilder.toString().trim();
    gym = gymRepository.search(user, gymName, config.getRegion());
    Raid pokemonRaid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
    final Pokemon pokemon = pokemonRepository.search(whatToChangeTo, user);
    if (pokemonRaid.isExRaid()) {
        throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.EX_NO_CHANGE_POKEMON, localeService.getLocaleForUser(user)));
    }
    // Anybody should be able to report hatched eggs
    if (!pokemonRaid.getPokemon().isEgg()) {
        verifyPermission(localeService, commandEvent, user, pokemonRaid, config);
    }
    if (Utils.isRaidExPokemon(whatToChangeTo)) {
        throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.EX_CANT_CHANGE_RAID_TYPE, localeService.getLocaleForUser(user)));
    }
    raid = raidRepository.changePokemon(pokemonRaid, pokemon, commandEvent.getGuild(), config, user, "!raid change pokemon " + pokemon.getName() + " " + gymName);
    commandEvent.reactSuccess();
    removeOriginMessageIfConfigSaysSo(config, commandEvent);
    LOGGER.info("Changed pokemon for raid: " + raid);
}
Also used : UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym) Raid(pokeraidbot.domain.raid.Raid) Pokemon(pokeraidbot.domain.pokemon.Pokemon)

Example 3 with Gym

use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.

the class AlterRaidCommand method changeWhen.

private void changeWhen(CommandEvent commandEvent, Config config, User user, String[] args) {
    String whatToChangeTo;
    StringBuilder gymNameBuilder;
    String gymName;
    Gym gym;
    LocalTime endsAtTime;
    LocalDateTime endsAt;
    Raid raid;
    whatToChangeTo = args[1].trim().toLowerCase();
    gymNameBuilder = new StringBuilder();
    for (int i = 2; i < args.length; i++) {
        gymNameBuilder.append(args[i]).append(" ");
    }
    gymName = gymNameBuilder.toString().trim();
    gym = gymRepository.search(user, gymName, config.getRegion());
    Raid tempRaid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
    verifyPermission(localeService, commandEvent, user, tempRaid, config);
    endsAtTime = parseTime(user, whatToChangeTo, localeService);
    endsAt = LocalDateTime.of(tempRaid.getEndOfRaid().toLocalDate(), endsAtTime);
    assertTimeNotInNoRaidTimespan(user, endsAtTime, localeService);
    if (!tempRaid.isExRaid()) {
        assertTimeNotMoreThanXHoursFromNow(user, endsAtTime, localeService, 2);
    }
    assertCreateRaidTimeNotBeforeNow(user, endsAt, localeService);
    raid = raidRepository.changeEndOfRaid(tempRaid.getId(), endsAt, commandEvent.getGuild(), config, user, "!raid change when " + printTimeIfSameDay(endsAt) + " " + gym.getName());
    commandEvent.reactSuccess();
    removeOriginMessageIfConfigSaysSo(config, commandEvent);
    LOGGER.info("Changed time for raid: " + raid);
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) Gym(pokeraidbot.domain.gym.Gym) Raid(pokeraidbot.domain.raid.Raid)

Example 4 with Gym

use of pokeraidbot.domain.gym.Gym 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 5 with Gym

use of pokeraidbot.domain.gym.Gym 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)

Aggregations

Gym (pokeraidbot.domain.gym.Gym)37 User (net.dv8tion.jda.core.entities.User)18 Raid (pokeraidbot.domain.raid.Raid)16 LocalDateTime (java.time.LocalDateTime)15 LocalTime (java.time.LocalTime)13 Test (org.junit.Test)12 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)12 Pokemon (pokeraidbot.domain.pokemon.Pokemon)11 Locale (java.util.Locale)8 Config (pokeraidbot.infrastructure.jpa.config.Config)7 SignUp (pokeraidbot.domain.raid.signup.SignUp)6 RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)6 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)5 Guild (net.dv8tion.jda.core.entities.Guild)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)4 PokemonRaidInfo (pokeraidbot.domain.pokemon.PokemonRaidInfo)3 InputStream (java.io.InputStream)2 LocalDate (java.time.LocalDate)2 Set (java.util.Set)2