Search in sources :

Example 26 with Gym

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

the class CSVGymDataReader method readAll.

public Set<Gym> readAll() {
    String line;
    Set<Gym> gyms = new HashSet<>();
    Set<String> exGyms = readExGymListIfExists(inputStreamEx, resourceName);
    try {
        final InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
        BufferedReader br = new BufferedReader(inputStreamReader);
        while ((line = br.readLine()) != null) {
            String[] rowElements = line.split(GymDataImportTool.separator);
            if (rowElements[0].equalsIgnoreCase("ID")) {
            // This is the header of the file, ignore
            } else {
                try {
                    String id = rowElements[0].trim();
                    String x = rowElements[1].replaceAll("\"", "").trim();
                    String y = rowElements[2].replaceAll("\"", "").trim();
                    String name = rowElements[3].trim();
                    String area = rowElements[4].trim();
                    final boolean isExGym = exGyms.contains(name);
                    Gym gym = new Gym(name, id, x, y, area, isExGym);
                    gyms.add(gym);
                } catch (Throwable t) {
                    LOGGER.warn("Encountered problem for this row: " + line + " - error: " + t.getMessage());
                    throw new RuntimeException(t);
                }
            }
        }
    } catch (IOException e) {
        LOGGER.error("Error while trying to open gym file input stream " + resourceName + ": " + e.getMessage());
    }
    LOGGER.info("Parsed " + gyms.size() + " gyms from \"" + resourceName + "\".");
    return gyms;
}
Also used : Gym(pokeraidbot.domain.gym.Gym) HashSet(java.util.HashSet)

Example 27 with Gym

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

the class GymHuntrRaidEventListener method onEvent.

@Override
public void onEvent(Event event) {
    if (event instanceof GuildMessageReceivedEvent) {
        GuildMessageReceivedEvent guildEvent = (GuildMessageReceivedEvent) event;
        final User messageAuthor = guildEvent.getAuthor();
        try {
            if (isUserGymhuntrBot(messageAuthor) || isUserPokeAlarmBot(messageAuthor)) {
                final String serverName = guildEvent.getGuild().getName().toLowerCase();
                final Config config = serverConfigRepository.getConfigForServer(serverName);
                if (config == null) {
                    LOGGER.warn("Server configuration is null for this guild: " + guildEvent.getGuild().getName());
                    return;
                }
                if (!config.useBotIntegration()) {
                    if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace("Skipping trigger, since bot integration setting is false for server " + guildEvent.getGuild().getName());
                    }
                    return;
                }
                final List<MessageEmbed> embeds = guildEvent.getMessage().getEmbeds();
                if (embeds != null && embeds.size() > 0) {
                    for (MessageEmbed embed : embeds) {
                        final LocalDateTime currentDateTime = clockService.getCurrentDateTime();
                        final String description = embed.getDescription();
                        final String title = embed.getTitle();
                        List<String> newRaidArguments;
                        if (isUserGymhuntrBot(messageAuthor)) {
                            newRaidArguments = gymhuntrArgumentsToCreateRaid(title, description, clockService);
                        } else if (isUserPokeAlarmBot(messageAuthor)) {
                            newRaidArguments = pokeAlarmArgumentsToCreateRaid(title, description, clockService);
                        } else {
                            newRaidArguments = new ArrayList<>();
                        }
                        try {
                            if (newRaidArguments != null && newRaidArguments.size() > 0) {
                                final Iterator<String> iterator = newRaidArguments.iterator();
                                final String gym = iterator.next();
                                final String pokemon = iterator.next();
                                final String time = iterator.next();
                                final Pokemon raidBoss = pokemonRepository.getByName(pokemon);
                                final String region = config.getRegion();
                                final Gym raidGym = gymRepository.findByName(gym, region);
                                final LocalDate currentDate = currentDateTime.toLocalDate();
                                final LocalDateTime endOfRaid = LocalDateTime.of(currentDate, LocalTime.parse(time, Utils.timeParseFormatter));
                                final SelfUser botUser = botService.getBot().getSelfUser();
                                final PokemonRaidInfo raidInfo;
                                raidInfo = strategyService.getRaidInfo(raidBoss);
                                handleRaidFromIntegration(botUser, guildEvent, raidBoss, raidGym, endOfRaid, config, clockService, raidInfo, strategyService);
                            } else {
                                if (LOGGER.isDebugEnabled()) {
                                    LOGGER.debug("No arguments to create raid with for server " + config + ", skipping. Raw command: " + guildEvent.getMessage().getRawContent());
                                }
                            }
                        } catch (Throwable t) {
                            LOGGER.warn("Exception when trying to get arguments for raid creation: " + t.getMessage());
                        }
                    }
                }
            }
        } catch (Throwable t) {
            LOGGER.warn("Exception thrown for event listener: " + t.getMessage());
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Stacktrace: ", t);
            }
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) SelfUser(net.dv8tion.jda.core.entities.SelfUser) User(net.dv8tion.jda.core.entities.User) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) Config(pokeraidbot.infrastructure.jpa.config.Config) PokemonRaidInfo(pokeraidbot.domain.pokemon.PokemonRaidInfo) LocalDate(java.time.LocalDate) Gym(pokeraidbot.domain.gym.Gym) Pokemon(pokeraidbot.domain.pokemon.Pokemon) GuildMessageReceivedEvent(net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent) SelfUser(net.dv8tion.jda.core.entities.SelfUser)

Example 28 with Gym

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

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

the class WhereIsGymCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    String gymName = commandEvent.getArgs();
    final Gym gym = gymRepository.search(commandEvent.getAuthor(), gymName, config.getRegion());
    String staticUrl = Utils.getStaticMapUrl(gym);
    String nonStaticUrl = Utils.getNonStaticMapUrl(gym);
    replyMapBasedOnConfig(config, commandEvent, new EmbedBuilder().setImage(staticUrl).setTitle(gym.getName(), nonStaticUrl).build());
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Gym(pokeraidbot.domain.gym.Gym)

Example 30 with Gym

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

the class NewRaidGroupCommand 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 group 10:00 solna platform"));
    }
    String timeString = args[0];
    LocalTime startAtTime = Utils.parseTime(user, timeString, localeService);
    assertTimeNotInNoRaidTimespan(user, startAtTime, localeService);
    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());
    final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), 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) User(net.dv8tion.jda.core.entities.User) LocalTime(java.time.LocalTime) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym) Raid(pokeraidbot.domain.raid.Raid)

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