Search in sources :

Example 1 with RaidGroup

use of pokeraidbot.infrastructure.jpa.raid.RaidGroup in project pokeraidbot by magnusmickelsson.

the class AlterRaidCommand method changeGroupTime.

private boolean changeGroupTime(CommandEvent commandEvent, Config config, User user, String userName, Raid raid, LocalDateTime newDateTime) {
    boolean groupChanged = false;
    final Set<RaidGroup> groups = raidRepository.getGroups(raid);
    final Set<EmoticonSignUpMessageListener> listenersToCheck = getListenersToCheck(commandEvent, config, user, raid, groups);
    for (EmoticonSignUpMessageListener listener : listenersToCheck) {
        final String raidId = raid.getId();
        final LocalDateTime currentStartAt = listener.getStartAt();
        if (currentStartAt != null && currentStartAt.equals(newDateTime)) {
            LOGGER.info("Group is already at input time.");
            // This group is already at the time to change to
            commandEvent.reactError();
        } else if (currentStartAt != null) {
            LOGGER.info("Changing group time from " + currentStartAt + " to " + newDateTime);
            RaidGroup raidGroup = raidRepository.changeGroup(user, raidId, listener.getUserId(), currentStartAt, newDateTime);
            raidRepository.moveAllSignUpsForTimeToNewTime(raidId, currentStartAt, newDateTime, user);
            listener.setStartAt(newDateTime);
            groupChanged = true;
            replyBasedOnConfigAndRemoveAfter(config, commandEvent, localeService.getMessageFor(LocaleService.MOVED_GROUP, localeService.getLocaleForUser(user), printTimeIfSameDay(currentStartAt), printTimeIfSameDay(newDateTime), raid.getGym().getName()), BotServerMain.timeToRemoveFeedbackInSeconds);
            LOGGER.info("Group time changed. Group: " + raidGroup);
            commandEvent.reactSuccess();
        } else {
            LOGGER.info("Group is about to get cleaned up.");
            commandEvent.reactError();
            // This group is about to get cleaned up since its start time is null
            replyBasedOnConfigAndRemoveAfter(config, commandEvent, localeService.getMessageFor(LocaleService.GROUP_CLEANING_UP, localeService.getLocaleForUser(user)), BotServerMain.timeToRemoveFeedbackInSeconds);
            return true;
        }
    }
    if (!groupChanged) {
        throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid change group 10:00 solna platform"));
    }
    return false;
}
Also used : LocalDateTime(java.time.LocalDateTime) EmoticonSignUpMessageListener(pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup)

Example 2 with RaidGroup

use of pokeraidbot.infrastructure.jpa.raid.RaidGroup in project pokeraidbot by magnusmickelsson.

the class RaidRepository method deleteGroup.

public RaidGroup deleteGroup(String raidId, String groupId) {
    final RaidEntity entity = findEntityByRaidId(raidId);
    if (entity == null) {
        return null;
    }
    final RaidGroup removedGroup = entity.removeGroup(groupId);
    if (removedGroup == null) {
        throw new RuntimeException("No group with ID " + groupId + " for raid " + entity);
    }
    return removedGroup;
}
Also used : RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 3 with RaidGroup

use of pokeraidbot.infrastructure.jpa.raid.RaidGroup in project pokeraidbot by magnusmickelsson.

the class RaidRepository method getGroups.

public Set<RaidGroup> getGroups(Raid raid) {
    RaidEntity entity = findEntityByRaidId(raid.getId());
    final Set<RaidGroup> groups = entity.getGroupsAsSet();
    return groups;
}
Also used : RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 4 with RaidGroup

use of pokeraidbot.infrastructure.jpa.raid.RaidGroup in project pokeraidbot by magnusmickelsson.

the class RaidRepository method changeGroup.

public RaidGroup changeGroup(User user, String raidId, String groupCreatorId, LocalDateTime currentStartAt, LocalDateTime newDateTime) {
    final RaidEntity entityByRaidId = findEntityByRaidId(raidId);
    if (entityByRaidId == null) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_RAID_AT_GYM, localeService.getLocaleForUser(user)));
    }
    RaidGroup group = entityByRaidId.getGroupByCreatorAndStart(groupCreatorId, currentStartAt);
    if (group == null) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_SUCH_GROUP, localeService.getLocaleForUser(user)));
    }
    group.setStartsAt(newDateTime);
    raidEntityRepository.save(entityByRaidId);
    return group;
}
Also used : UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 5 with RaidGroup

use of pokeraidbot.infrastructure.jpa.raid.RaidGroup 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

RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)15 Gym (pokeraidbot.domain.gym.Gym)6 Raid (pokeraidbot.domain.raid.Raid)6 LocalDateTime (java.time.LocalDateTime)5 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)5 RaidEntity (pokeraidbot.infrastructure.jpa.raid.RaidEntity)5 EmoticonSignUpMessageListener (pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener)4 LocalTime (java.time.LocalTime)3 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)3 Pokemon (pokeraidbot.domain.pokemon.Pokemon)3 Locale (java.util.Locale)2 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)2 Guild (net.dv8tion.jda.core.entities.Guild)2 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)2 User (net.dv8tion.jda.core.entities.User)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Config (pokeraidbot.infrastructure.jpa.config.Config)2 LocalDate (java.time.LocalDate)1 TimeUnit (java.util.concurrent.TimeUnit)1