Search in sources :

Example 6 with Gym

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

Example 7 with Gym

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

the class RaidStatusCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    String gymName = commandEvent.getArgs();
    final User user = commandEvent.getAuthor();
    final Gym gym = gymRepository.search(user, gymName, config.getRegion());
    final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
    final Set<SignUp> signUps = raid.getSignUps();
    final int numberOfPeople = raid.getNumberOfPeopleSignedUp();
    final Locale localeForUser = localeService.getLocaleForUser(user);
    EmbedBuilder embedBuilder = new EmbedBuilder();
    embedBuilder.setAuthor(null, null, null);
    final Pokemon pokemon = raid.getPokemon();
    embedBuilder.setTitle(localeService.getMessageFor(LocaleService.RAIDSTATUS, localeForUser, gym.getName() + (gym.isExGym() ? Emotes.STAR + "" : "")), Utils.getNonStaticMapUrl(gym));
    StringBuilder sb = new StringBuilder();
    final String activeText = localeService.getMessageFor(LocaleService.ACTIVE, localeForUser);
    final String startGroupText = localeService.getMessageFor(LocaleService.START_GROUP, localeForUser);
    final String findYourWayText = localeService.getMessageFor(LocaleService.FIND_YOUR_WAY, localeForUser);
    final String raidBossText = localeService.getMessageFor(LocaleService.RAID_BOSS, localeForUser);
    final Set<String> signUpNames = getNamesOfThoseWithSignUps(raid.getSignUps(), true);
    final String allSignUpNames = StringUtils.join(signUpNames, ", ");
    sb.append(raidBossText).append(" **").append(pokemon).append("** - ").append("*!raid vs ").append(pokemon.getName()).append("*\n");
    sb.append("**").append(activeText).append(":** ").append(printTimeIfSameDay(getStartOfRaid(raid.getEndOfRaid(), false))).append("-").append(printTimeIfSameDay(raid.getEndOfRaid())).append("\t**").append(numberOfPeople).append(" ").append(localeService.getMessageFor(LocaleService.SIGNED_UP, localeForUser)).append("**").append(signUps.size() > 0 ? ":\n" + allSignUpNames : "").append("\n").append(startGroupText).append(":\n*!raid group ").append(printTime(raid.getEndOfRaid().toLocalTime().minusMinutes(15))).append(" ").append(gymName).append("*\n\n");
    sb.append(localeService.getMessageFor(LocaleService.CREATED_BY, localeForUser)).append(": ").append(raid.getCreator());
    embedBuilder.setFooter(findYourWayText + localeService.getMessageFor(LocaleService.GOOGLE_MAPS, localeService.getLocaleForUser(user)), Utils.getPokemonIcon(pokemon));
    embedBuilder.setDescription(sb.toString());
    final MessageEmbed messageEmbed = embedBuilder.build();
    replyBasedOnConfig(config, commandEvent, messageEmbed);
}
Also used : Locale(java.util.Locale) SignUp(pokeraidbot.domain.raid.signup.SignUp) User(net.dv8tion.jda.core.entities.User) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) Raid(pokeraidbot.domain.raid.Raid) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Gym(pokeraidbot.domain.gym.Gym) Pokemon(pokeraidbot.domain.pokemon.Pokemon)

Example 8 with Gym

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

the class GymCommands method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent event, Config config) {
    final User user = event.getAuthor();
    final String eventArgs = event.getArgs();
    if (!isUserServerMod(event, config) && !isUserAdministrator(event)) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_PERMISSION, localeService.getLocaleForUser(user)));
    }
    if (eventArgs.startsWith("get ")) {
        String gymName = eventArgs.replaceAll("get\\s{1,3}", "").trim();
        final Gym gym = gymRepository.findByName(gymName, config.getRegion());
        replyBasedOnConfig(config, event, "Found gym: " + gym.toStringDetails());
    } else {
        String[] gymArgs = eventArgs.replaceAll("gym\\s{1,3}", "").trim().split(";");
        if (gymArgs == null || gymArgs.length < 4 || gymArgs.length > 4) {
            replyBasedOnConfig(config, event, "Bad syntax, should be: !raid gym add {gymname};{latitude};{longitude};{exgym true or false");
            return;
        } else {
            final Random random = new Random();
            random.setSeed(System.currentTimeMillis());
            Gym gym = new Gym(gymArgs[0], "" + random.nextInt(99999999), gymArgs[1], gymArgs[2], config.getRegion(), Boolean.valueOf(gymArgs[3]));
            gymRepository.addTemporary(user, gym, config.getRegion());
            replyBasedOnConfig(config, event, "Gym added temporarily: " + gym.toStringDetails());
        }
    }
}
Also used : User(net.dv8tion.jda.core.entities.User) Random(java.util.Random) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym)

Example 9 with Gym

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

the class RemoveSignUpCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final String userName = user.getName();
    final Locale localeForUser = localeService.getLocaleForUser(user);
    String gymName = commandEvent.getArgs();
    final Gym gym = gymRepository.search(user, gymName, config.getRegion());
    final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
    final SignUp removed = raid.remove(user, raidRepository);
    if (removed != null) {
        commandEvent.reactSuccess();
        removeOriginMessageIfConfigSaysSo(config, commandEvent);
    } else {
        final String message = localeService.getMessageFor(LocaleService.NO_SIGNUP_AT_GYM, localeForUser, userName, gym.getName());
        replyErrorBasedOnConfig(config, commandEvent, new UserMessedUpException(user, message));
    }
}
Also used : Locale(java.util.Locale) SignUp(pokeraidbot.domain.raid.signup.SignUp) User(net.dv8tion.jda.core.entities.User) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym) Raid(pokeraidbot.domain.raid.Raid)

Example 10 with Gym

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

the class WhereIsGymInChatCommand 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);
    final MessageEmbed messageEmbed = new EmbedBuilder().setImage(staticUrl).setTitle(gym.getName(), nonStaticUrl).build();
    replyMapInChat(config, commandEvent, messageEmbed);
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) Gym(pokeraidbot.domain.gym.Gym)

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