Search in sources :

Example 31 with Gym

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

the class NewRaidGroupCommand method getRaidGroupMessageEmbed.

private static MessageEmbed getRaidGroupMessageEmbed(LocalDateTime startAt, String raidId, LocaleService localeService, ClockService clockService, Locale locale, TimeUnit delayTimeUnit, int delay, RaidRepository raidRepository) {
    Raid currentStateOfRaid = raidRepository.getById(raidId);
    final Gym gym = currentStateOfRaid.getGym();
    final Pokemon pokemon = currentStateOfRaid.getPokemon();
    MessageEmbed messageEmbed;
    EmbedBuilder embedBuilder = new EmbedBuilder();
    final String headline = localeService.getMessageFor(LocaleService.GROUP_HEADLINE, locale, currentStateOfRaid.getPokemon().getName(), gym.getName() + (gym.isExGym() ? Emotes.STAR : ""));
    final String getHereText = localeService.getMessageFor(LocaleService.GETTING_HERE, locale);
    embedBuilder.setTitle(getHereText + " " + gym.getName(), Utils.getNonStaticMapUrl(gym));
    final LocalDateTime endOfRaid = currentStateOfRaid.getEndOfRaid();
    embedBuilder.setAuthor(headline + " " + Utils.printTime(Utils.getStartOfRaid(endOfRaid, currentStateOfRaid.isExRaid()).toLocalTime()) + "-" + Utils.printTime(endOfRaid.toLocalTime()), null, Utils.getPokemonIcon(pokemon));
    final Set<SignUp> signUpsAt = currentStateOfRaid.getSignUpsAt(startAt.toLocalTime());
    final Set<String> signUpNames = getNamesOfThoseWithSignUps(signUpsAt, false);
    final String allSignUpNames = signUpNames.size() > 0 ? StringUtils.join(signUpNames, ", ") : "-";
    final int numberOfPeopleArrivingAt = signUpsAt.stream().mapToInt(SignUp::getHowManyPeople).sum();
    final String numberOfSignupsText = localeService.getMessageFor(LocaleService.SIGNED_UP, locale);
    final String totalSignUpsText = numberOfSignupsText + ": " + numberOfPeopleArrivingAt;
    final String thoseWhoAreComingText = localeService.getMessageFor(LocaleService.WHO_ARE_COMING, locale) + ":";
    embedBuilder.clearFields();
    final String handleSignUpText = localeService.getMessageFor(LocaleService.HANDLE_SIGNUP, locale);
    final Set<RaidGroup> groups = raidRepository.getGroups(currentStateOfRaid);
    final String descriptionAppendixText;
    if (groups.size() > 1) {
        descriptionAppendixText = raidRepository.listGroupsForRaid(currentStateOfRaid, groups);
    } else {
        descriptionAppendixText = "- " + handleSignUpText;
    }
    embedBuilder.setDescription("**Start: " + printTimeIfSameDay(startAt) + "** " + descriptionAppendixText);
    embedBuilder.addField(totalSignUpsText + ". " + thoseWhoAreComingText, allSignUpNames, true);
    final String updatedMessage = localeService.getMessageFor(LocaleService.UPDATED_EVERY_X, locale, LocaleService.asString(delayTimeUnit, locale), String.valueOf(delay)) + " " + localeService.getMessageFor(LocaleService.LAST_UPDATE, locale, printTime(clockService.getCurrentTime())) + ".";
    embedBuilder.setFooter(updatedMessage, null);
    messageEmbed = embedBuilder.build();
    return messageEmbed;
}
Also used : LocalDateTime(java.time.LocalDateTime) SignUp(pokeraidbot.domain.raid.signup.SignUp) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) Raid(pokeraidbot.domain.raid.Raid) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Gym(pokeraidbot.domain.gym.Gym) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) Pokemon(pokeraidbot.domain.pokemon.Pokemon)

Example 32 with Gym

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

the class NewRaidStartsAtCommand 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 start ho-oh 10:00 solna platform"));
    }
    String pokemonName = args[0];
    final Pokemon pokemon = pokemonRepository.search(pokemonName, user);
    String timeString = args[1];
    LocalTime endsAtTime = Utils.parseTime(user, timeString, localeService).plusMinutes(Utils.RAID_DURATION_IN_MINUTES);
    LocalDateTime endsAt = LocalDateTime.of(LocalDate.now(), endsAtTime);
    assertTimeNotInNoRaidTimespan(user, endsAtTime, localeService);
    assertTimeNotMoreThanXHoursFromNow(user, endsAtTime, localeService, 2);
    assertCreateRaidTimeNotBeforeNow(user, endsAt, localeService);
    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 = new Raid(pokemon, endsAt, gym, localeService, config.getRegion());
    raidRepository.newRaid(user, raid, commandEvent.getGuild(), config, "!raid start " + raid.getPokemon().getName() + " " + getStartOfRaid(raid.getEndOfRaid(), raid.isExRaid()) + " " + raid.getGym().getName());
    final Locale locale = localeService.getLocaleForUser(user);
    final String message = localeService.getMessageFor(LocaleService.NEW_RAID_CREATED, locale, raid.toString(locale));
    replyBasedOnConfigAndRemoveAfter(config, commandEvent, message, BotServerMain.timeToRemoveFeedbackInSeconds);
}
Also used : LocalDateTime(java.time.LocalDateTime) 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) Pokemon(pokeraidbot.domain.pokemon.Pokemon) Raid(pokeraidbot.domain.raid.Raid)

Example 33 with Gym

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

the class RaidListCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final String args = commandEvent.getArgs();
    final Locale locale = localeService.getLocaleForUser(user);
    Set<Raid> raids;
    if (args != null && args.length() > 0) {
        raids = raidRepository.getRaidsInRegionForPokemon(config.getRegion(), pokemonRepository.search(args, user));
    } else {
        raids = raidRepository.getAllRaidsForRegion(config.getRegion());
    }
    if (raids.size() == 0) {
        EmbedBuilder embedBuilder = new EmbedBuilder();
        embedBuilder.setTitle(null);
        embedBuilder.setAuthor(null, null, null);
        embedBuilder.setDescription(localeService.getMessageFor(LocaleService.LIST_NO_RAIDS, locale));
        commandEvent.reply(embedBuilder.build());
    } else {
        StringBuilder stringBuilder = new StringBuilder();
        StringBuilder exRaids = new StringBuilder();
        stringBuilder.append("**").append(localeService.getMessageFor(LocaleService.CURRENT_RAIDS, locale));
        if (args != null && args.length() > 0) {
            stringBuilder.append(" (").append(args).append(")");
        }
        stringBuilder.append(":**");
        stringBuilder.append("\n").append(localeService.getMessageFor(LocaleService.RAID_DETAILS, localeService.getLocaleForUser(user))).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();
                stringBuilder.append("\n**").append(currentPokemon.getName()).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);
        }
        replyBasedOnConfig(config, commandEvent, stringBuilder.toString());
    }
}
Also used : Locale(java.util.Locale) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) User(net.dv8tion.jda.core.entities.User) Gym(pokeraidbot.domain.gym.Gym) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) Raid(pokeraidbot.domain.raid.Raid) Pokemon(pokeraidbot.domain.pokemon.Pokemon)

Example 34 with Gym

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

the class AlterRaidCommand method deleteRaidAndGroups.

private void deleteRaidAndGroups(CommandEvent commandEvent, Config config, User user, String userName, String[] args) {
    StringBuilder gymNameBuilder;
    String gymName;
    Gym gym;
    gymNameBuilder = new StringBuilder();
    for (int i = 1; i < args.length; i++) {
        gymNameBuilder.append(args[i]).append(" ");
    }
    gymName = gymNameBuilder.toString().trim();
    gym = gymRepository.search(user, gymName, config.getRegion());
    Raid deleteRaid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
    verifyPermission(localeService, commandEvent, user, deleteRaid, config);
    final boolean userIsNotAdministrator = !isUserAdministrator(commandEvent);
    final boolean userIsNotMod = !isUserServerMod(commandEvent, config);
    if ((userIsNotAdministrator && userIsNotMod) && deleteRaid.getSignUps().size() > 0) {
        throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.ONLY_ADMINS_REMOVE_RAID, localeService.getLocaleForUser(user)));
    }
    final Set<RaidGroup> groups = raidRepository.getGroups(deleteRaid);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Deleting " + groups.size() + " groups associated with raid " + deleteRaid + "... ");
    }
    final int numberOfGroups = groups.size();
    for (RaidGroup group : groups) {
        final EmoticonSignUpMessageListener listener = getListenerForGroup(deleteRaid, group);
        if (listener != null) {
            final MessageChannel channel = getChannel(commandEvent.getGuild(), group.getChannel());
            if (channel != null) {
                NewRaidGroupCommand.cleanUpRaidGroupAndDeleteSignUpsIfPossible(channel, group.getStartsAt(), deleteRaid.getId(), listener, raidRepository, botService, group.getId());
            } else {
                LOGGER.debug("Could not find channel " + group.getChannel() + " in guild " + commandEvent.getGuild().getName());
            }
        }
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Groups deleted for raid " + deleteRaid);
    }
    if (raidRepository.delete(deleteRaid)) {
        commandEvent.reactSuccess();
        removeOriginMessageIfConfigSaysSo(config, commandEvent);
        LOGGER.info("Deleted raid (and " + numberOfGroups + " related groups): " + deleteRaid);
    } else {
        throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.RAID_NOT_EXISTS, localeService.getLocaleForUser(user)));
    }
}
Also used : MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) EmoticonSignUpMessageListener(pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) Raid(pokeraidbot.domain.raid.Raid)

Example 35 with Gym

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

the class AlterRaidCommand method changeOrDeleteGroup.

private void changeOrDeleteGroup(CommandEvent commandEvent, Config config, User user, String userName, String[] args) {
    String whatToChangeTo;
    String gymName;
    Gym gym;
    Raid raid;
    whatToChangeTo = args[1].trim().toLowerCase();
    String originalTime = preProcessTimeString(args[2].trim());
    LocalTime existingGroupTimeIfAvailable = null;
    try {
        existingGroupTimeIfAvailable = Utils.parseTime(user, originalTime, localeService);
    } catch (UserMessedUpException e) {
    // Input was not a time
    }
    gymName = getGymName(args, existingGroupTimeIfAvailable);
    gym = gymRepository.search(user, gymName, config.getRegion());
    raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
    if (whatToChangeTo.equals("remove")) {
        final Set<RaidGroup> groups = raidRepository.getGroups(raid);
        final Set<EmoticonSignUpMessageListener> listenersToCheck = getListenersToCheck(commandEvent, config, user, raid, groups);
        EmoticonSignUpMessageListener listener = listenersToCheck.iterator().next();
        verifyIsModOrHasGroupForRaid(commandEvent, user, raid, config);
        RaidGroup theGroupToDelete = getGroupToDelete(user, existingGroupTimeIfAvailable, groups, raid);
        assertPermissionToManageThisGroup(user, theGroupToDelete, commandEvent, config);
        NewRaidGroupCommand.cleanUpGroupMessageAndEntity(commandEvent.getChannel(), raid.getId(), listener, raidRepository, botService, theGroupToDelete.getId(), raid.toString());
        final String message = localeService.getMessageFor(LocaleService.GROUP_DELETED, localeService.getLocaleForUser(user));
        replyBasedOnConfig(config, commandEvent, message);
    } else {
        LocalTime newTime = parseTime(user, whatToChangeTo, localeService);
        LocalDateTime newDateTime = LocalDateTime.of(raid.getEndOfRaid().toLocalDate(), newTime);
        checkIfInputIsValidAndUserHasRights(commandEvent, config, user, raid, newDateTime);
        if (changeGroupTime(commandEvent, config, user, userName, raid, newDateTime))
            return;
    }
    removeOriginMessageIfConfigSaysSo(config, commandEvent);
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) EmoticonSignUpMessageListener(pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) 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