Search in sources :

Example 6 with PokemonRaidInfo

use of pokeraidbot.domain.pokemon.PokemonRaidInfo 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 7 with PokemonRaidInfo

use of pokeraidbot.domain.pokemon.PokemonRaidInfo in project pokeraidbot by magnusmickelsson.

the class EggHatchedCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final String userName = user.getName();
    final String[] args = commandEvent.getArgs().split(" ");
    if (args.length < 2) {
        throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid hatch Ho-Oh solna platform"));
    }
    String pokemonName = args[0].trim().toLowerCase();
    final String[] gymArguments = ArrayUtils.removeAll(args, 0);
    String gymName = StringUtils.join(gymArguments, " ");
    final String region = config.getRegion();
    final Gym gym = gymRepository.search(user, gymName, region);
    final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, region, user);
    final Pokemon pokemon = pokemonRepository.search(pokemonName, user);
    final PokemonRaidInfo existingRaidInfo = raidStrategyService.getRaidInfo(raid.getPokemon());
    final int newBossTier = raidStrategyService.getRaidInfo(pokemon).getBossTier();
    if (!raid.getPokemon().isEgg()) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.EGG_ALREADY_HATCHED, localeService.getLocaleForUser(user), raid.getPokemon().toString()));
    }
    if (pokemon.isEgg() || newBossTier != existingRaidInfo.getBossTier()) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.EGG_WRONG_TIER, localeService.getLocaleForUser(user)));
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Trying to hatch raid " + raid + " into " + pokemonName);
    }
    AlterRaidCommand.changePokemon(gymRepository, localeService, pokemonRepository, raidRepository, commandEvent, config, user, userName, pokemonName, gymArguments);
}
Also used : User(net.dv8tion.jda.core.entities.User) PokemonRaidInfo(pokeraidbot.domain.pokemon.PokemonRaidInfo) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym) Raid(pokeraidbot.domain.raid.Raid) Pokemon(pokeraidbot.domain.pokemon.Pokemon)

Aggregations

PokemonRaidInfo (pokeraidbot.domain.pokemon.PokemonRaidInfo)7 Pokemon (pokeraidbot.domain.pokemon.Pokemon)4 Gym (pokeraidbot.domain.gym.Gym)3 User (net.dv8tion.jda.core.entities.User)2 Test (org.junit.Test)2 Raid (pokeraidbot.domain.raid.Raid)2 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)1 SelfUser (net.dv8tion.jda.core.entities.SelfUser)1 GuildMessageReceivedEvent (net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent)1 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)1 Config (pokeraidbot.infrastructure.jpa.config.Config)1 RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)1