Search in sources :

Example 1 with Raid

use of pokeraidbot.domain.raid.Raid 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 2 with Raid

use of pokeraidbot.domain.raid.Raid 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 3 with Raid

use of pokeraidbot.domain.raid.Raid 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)

Example 4 with Raid

use of pokeraidbot.domain.raid.Raid in project pokeraidbot by magnusmickelsson.

the class NewRaidGroupCommand method getMessageRefreshingTaskToSchedule.

public static Callable<Boolean> getMessageRefreshingTaskToSchedule(MessageChannel messageChannel, Raid raid, EmoticonSignUpMessageListener emoticonSignUpMessageListener, String infoMessageId, Locale locale, RaidRepository raidRepository, LocaleService localeService, ClockService clockService, ExecutorService executorService, BotService botService, TimeUnit delayTimeUnit, int delay, String raidGroupId) {
    Callable<Boolean> refreshEditThreadTask = () -> {
        final String groupId = raidGroupId;
        final Raid currentStateOfRaid = raidRepository.getById(raid.getId());
        final Callable<Boolean> editTask = () -> {
            delayTimeUnit.sleep(delay);
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Thread: " + Thread.currentThread().getId() + " - Updating for group at gym " + currentStateOfRaid.getGym().getName() + ": message ID=" + infoMessageId);
            }
            LocalDateTime start = emoticonSignUpMessageListener.getStartAt();
            final MessageEmbed newContent = getRaidGroupMessageEmbed(start, raid.getId(), localeService, clockService, locale, delayTimeUnit, delay, raidRepository);
            messageChannel.editMessageById(infoMessageId, newContent).queue(m -> {
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Message edit ok for " + infoMessageId);
                }
            }, m -> {
                LOGGER.warn(m.getClass().getName() + " occurred in edit message loop: " + m.getMessage());
                if (Utils.isExceptionOrCauseNetworkIssues(m)) {
                    LOGGER.info("Exception was due to timeout, so trying again soon. Could be temporary.");
                    try {
                        // If we get a timeout, it's probably due to discord having issues.
                        // Try to delay 60 seconds and try again.
                        LOGGER.debug("Since we had a timeout, trying to wait 60 seconds before trying again.");
                        delayTimeUnit.sleep(60000);
                    } catch (InterruptedException e) {
                    }
                } else {
                    LOGGER.info("Exception was not due to timeout, so terminating this group.");
                    emoticonSignUpMessageListener.setStartAt(null);
                    LOGGER.info("Raid group will now be cleaned up for raid: " + raidCleanUpInfo(raid, emoticonSignUpMessageListener));
                    cleanUpRaidGroupAndDeleteSignUpsIfPossible(messageChannel, emoticonSignUpMessageListener.getStartAt(), currentStateOfRaid != null ? currentStateOfRaid.getId() : null, emoticonSignUpMessageListener, raidRepository, botService, groupId);
                }
            });
            return true;
        };
        while (raidIsActiveAndRaidGroupNotExpired(currentStateOfRaid.getEndOfRaid(), emoticonSignUpMessageListener.getStartAt(), clockService)) {
            try {
                executorService.submit(editTask).get();
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Edit task done for now: " + infoMessageId);
                }
            } catch (InterruptedException | ExecutionException e) {
                throw new RuntimeException(e);
            }
        }
        LOGGER.info("Raid group will now be cleaned up for raid: " + raidCleanUpInfo(raid, emoticonSignUpMessageListener));
        cleanUpRaidGroupAndDeleteSignUpsIfPossible(messageChannel, emoticonSignUpMessageListener.getStartAt(), raid != null ? raid.getId() : null, emoticonSignUpMessageListener, raidRepository, botService, groupId);
        return true;
    };
    return refreshEditThreadTask;
}
Also used : LocalDateTime(java.time.LocalDateTime) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) Raid(pokeraidbot.domain.raid.Raid) Callable(java.util.concurrent.Callable)

Example 5 with Raid

use of pokeraidbot.domain.raid.Raid in project pokeraidbot by magnusmickelsson.

the class RaidOverviewCommand method getOverviewMessage.

private static String getOverviewMessage(Config config, LocaleService localeService, RaidRepository raidRepository, ClockService clockService, Locale locale, PokemonRaidStrategyService strategyService) {
    Set<Raid> raids = raidRepository.getAllRaidsForRegion(config.getRegion());
    StringBuilder stringBuilder = new StringBuilder();
    if (raids.size() == 0) {
        stringBuilder.append(localeService.getMessageFor(LocaleService.LIST_NO_RAIDS, locale));
    } else {
        StringBuilder exRaids = new StringBuilder();
        stringBuilder.append("**").append(localeService.getMessageFor(LocaleService.CURRENT_RAIDS, locale));
        stringBuilder.append(":**");
        stringBuilder.append("\n").append(localeService.getMessageFor(LocaleService.RAID_DETAILS, locale)).append("\n");
        Pokemon currentPokemon = null;
        for (Raid raid : raids) {
            final Pokemon raidBoss = raid.getPokemon();
            if (!raid.isExRaid() && (currentPokemon == null || (!currentPokemon.equals(raidBoss)))) {
                currentPokemon = raid.getPokemon();
                final PokemonRaidInfo raidInfo = strategyService.getRaidInfo(currentPokemon);
                stringBuilder.append("\n**").append(currentPokemon.getName()).append("**");
                if (raidInfo != null && raidInfo.getBossTier() > 0) {
                    stringBuilder.append(" (").append(raidInfo.getBossTier()).append(")");
                }
                stringBuilder.append("\n");
            }
            final int numberOfPeople = raid.getNumberOfPeopleSignedUp();
            final Gym raidGym = raid.getGym();
            final Set<RaidGroup> groups = raidRepository.getGroups(raid);
            if (!raid.isExRaid()) {
                if (raidGym.isExGym()) {
                    stringBuilder.append("**").append(raidGym.getName()).append(Emotes.STAR + "**");
                } else {
                    stringBuilder.append("*").append(raidGym.getName()).append("*");
                }
                stringBuilder.append(" ").append(printTimeIfSameDay(getStartOfRaid(raid.getEndOfRaid(), false))).append("-").append(printTime(raid.getEndOfRaid().toLocalTime()));
                if (groups.size() < 1) {
                    stringBuilder.append(" (**").append(numberOfPeople).append("**)");
                } else {
                    stringBuilder.append(raidRepository.listGroupsForRaid(raid, groups));
                }
                stringBuilder.append("\n");
            } else {
                exRaids.append("\n*").append(raidGym.getName());
                exRaids.append("* ").append(localeService.getMessageFor(LocaleService.RAID_BETWEEN, locale, printTimeIfSameDay(getStartOfRaid(raid.getEndOfRaid(), true)), printTime(raid.getEndOfRaid().toLocalTime())));
                if (groups.size() < 1) {
                    exRaids.append(" (**").append(numberOfPeople).append("**)");
                } else {
                    exRaids.append(raidRepository.listGroupsForRaid(raid, groups));
                }
            }
        }
        final String exRaidList = exRaids.toString();
        if (exRaidList.length() > 1) {
            stringBuilder.append("\n**Raid-EX:**").append(exRaidList);
        }
    }
    stringBuilder.append("\n\n").append(localeService.getMessageFor(LocaleService.UPDATED_EVERY_X, locale, LocaleService.asString(TimeUnit.SECONDS, locale), String.valueOf(60))).append(" ").append(localeService.getMessageFor(LocaleService.LAST_UPDATE, locale, printTime(clockService.getCurrentTime())));
    return stringBuilder.toString();
}
Also used : PokemonRaidInfo(pokeraidbot.domain.pokemon.PokemonRaidInfo) Gym(pokeraidbot.domain.gym.Gym) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) Raid(pokeraidbot.domain.raid.Raid) Pokemon(pokeraidbot.domain.pokemon.Pokemon)

Aggregations

Raid (pokeraidbot.domain.raid.Raid)24 Gym (pokeraidbot.domain.gym.Gym)16 LocalDateTime (java.time.LocalDateTime)12 User (net.dv8tion.jda.core.entities.User)12 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)11 Pokemon (pokeraidbot.domain.pokemon.Pokemon)10 Locale (java.util.Locale)9 LocalTime (java.time.LocalTime)7 RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)6 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)5 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)4 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)4 EmoticonSignUpMessageListener (pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener)4 SignUp (pokeraidbot.domain.raid.signup.SignUp)3 LocalDate (java.time.LocalDate)2 TimeUnit (java.util.concurrent.TimeUnit)2 PokemonRaidInfo (pokeraidbot.domain.pokemon.PokemonRaidInfo)2 ConcurrentModificationException (java.util.ConcurrentModificationException)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1