Search in sources :

Example 11 with Raid

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

the class StartUpEventListener method attachToGroupMessage.

private boolean attachToGroupMessage(Guild guild, Config config, RaidGroup raidGroup) {
    MessageChannel channel = null;
    try {
        final List<TextChannel> textChannels = guild.getTextChannels();
        for (TextChannel textChannel : textChannels) {
            if (textChannel.getName().equalsIgnoreCase(raidGroup.getChannel())) {
                channel = textChannel;
                break;
            }
        }
        final Locale locale = config.getLocale();
        Raid raid = raidRepository.getById(raidGroup.getRaidId());
        final EmoticonSignUpMessageListener emoticonSignUpMessageListener = new EmoticonSignUpMessageListener(botService, localeService, serverConfigRepository, raidRepository, pokemonRepository, gymRepository, raid.getId(), raidGroup.getStartsAt(), raidGroup.getCreatorId());
        emoticonSignUpMessageListener.setEmoteMessageId(raidGroup.getEmoteMessageId());
        emoticonSignUpMessageListener.setInfoMessageId(raidGroup.getInfoMessageId());
        final int delayTime = raid.isExRaid() ? 1 : 15;
        final TimeUnit delayTimeUnit = raid.isExRaid() ? TimeUnit.MINUTES : TimeUnit.SECONDS;
        final Callable<Boolean> groupEditTask = NewRaidGroupCommand.getMessageRefreshingTaskToSchedule(channel, raid, emoticonSignUpMessageListener, raidGroup.getInfoMessageId(), locale, raidRepository, localeService, clockService, executorService, botService, delayTimeUnit, delayTime, raidGroup.getId());
        executorService.submit(groupEditTask);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Found group message for raid " + raid + " in channel " + (channel == null ? "N/A" : channel.getName()) + " (server " + guild.getName() + "). Attaching to it.");
        }
        return true;
    } catch (UserMessedUpException e) {
        if (channel != null)
            channel.sendMessage(e.getMessage()).queue(m -> {
                m.delete().queueAfter(BotServerMain.timeToRemoveFeedbackInSeconds, TimeUnit.SECONDS);
            });
    } catch (ErrorResponseException e) {
        // We couldn't find the message in this channel or had permission issues, ignore
        LOGGER.info("Caught exception during startup: " + e.getMessage());
        LOGGER.warn("Cleaning up raidgroup...");
        cleanUpRaidGroup(raidGroup);
        LOGGER.debug("Stacktrace:", e);
    } catch (Throwable e) {
        LOGGER.warn("Cleaning up raidgroup due to exception: " + e.getMessage());
        cleanUpRaidGroup(raidGroup);
    }
    return false;
}
Also used : Locale(java.util.Locale) Raid(pokeraidbot.domain.raid.Raid) TextChannel(net.dv8tion.jda.core.entities.TextChannel) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) EmoticonSignUpMessageListener(pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener) TimeUnit(java.util.concurrent.TimeUnit) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) ErrorResponseException(net.dv8tion.jda.core.exceptions.ErrorResponseException)

Example 12 with Raid

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

the class UtilsTest method timeInRaidspan.

@Test
public void timeInRaidspan() throws Exception {
    User user = mock(User.class);
    when(user.getName()).thenReturn("User");
    LocalDateTime localDateTime = LocalDateTime.now();
    LocalDateTime same = localDateTime;
    LocalDateTime before = localDateTime.minusMinutes(1);
    LocalDateTime after = localDateTime.plusMinutes(1);
    LocalDateTime end = localDateTime.plusMinutes(Utils.RAID_DURATION_IN_MINUTES);
    LocalDateTime sameAsEnd = end;
    LocalDateTime beforeEnd = end.minusMinutes(1);
    LocalDateTime afterEnd = end.plusMinutes(1);
    final LocaleService localeService = mock(LocaleService.class);
    when(localeService.getMessageFor(any(), any(), any())).thenReturn("Mupp");
    Raid raid = new Raid(pokemonRepository.getByName("Tyranitar"), end, new Gym("Test", "id", "10", "10", null), localeService, "Test");
    checkWhetherAssertFails(user, same, localeService, raid, false);
    checkWhetherAssertFails(user, after, localeService, raid, false);
    checkWhetherAssertFails(user, before, localeService, raid, true);
    checkWhetherAssertFails(user, sameAsEnd, localeService, raid, false);
    checkWhetherAssertFails(user, afterEnd, localeService, raid, true);
    checkWhetherAssertFails(user, beforeEnd, localeService, raid, false);
}
Also used : LocalDateTime(java.time.LocalDateTime) User(net.dv8tion.jda.core.entities.User) LocaleService(pokeraidbot.domain.config.LocaleService) Gym(pokeraidbot.domain.gym.Gym) Raid(pokeraidbot.domain.raid.Raid) Test(org.junit.Test)

Example 13 with Raid

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

the class StartRaidAndCreateGroupCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final String[] args = commandEvent.getArgs().split(" ");
    final Locale locale = localeService.getLocaleForUser(user);
    if (args.length < 2) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid start-group groudon 10:00 solna platform"));
    }
    String pokemonName = args[0].trim();
    Pokemon pokemon = pokemonRepository.search(pokemonName, user);
    String timeString = args[1].trim();
    LocalTime startAtTime = Utils.parseTime(user, timeString, localeService);
    assertTimeNotInNoRaidTimespan(user, startAtTime, localeService);
    StringBuilder gymNameBuilder = new StringBuilder();
    for (int i = 2; i < args.length; i++) {
        gymNameBuilder.append(args[i]).append(" ");
    }
    String gymName = gymNameBuilder.toString().trim();
    final String region = config.getRegion();
    final Gym gym = gymRepository.search(user, gymName, region);
    final Raid raid;
    if (!raidRepository.isActiveOrExRaidAt(gym, region)) {
        final LocalDateTime endOfRaid = LocalDateTime.of(LocalDate.now(), startAtTime.plusMinutes(Utils.RAID_DURATION_IN_MINUTES));
        raid = raidRepository.newRaid(user, new Raid(pokemon, endOfRaid, gym, localeService, region), commandEvent.getGuild(), config, commandEvent.getMessage().getRawContent());
    } else {
        raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, region, user);
    }
    createRaidGroup(commandEvent.getChannel(), commandEvent.getGuild(), config, user, locale, startAtTime, raid.getId(), localeService, raidRepository, botService, serverConfigRepository, pokemonRepository, gymRepository, clockService, executorService, pokemonRaidStrategyService);
    commandEvent.reactSuccess();
    removeOriginMessageIfConfigSaysSo(config, commandEvent);
}
Also used : Locale(java.util.Locale) LocalDateTime(java.time.LocalDateTime) 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 14 with Raid

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

the class NewRaidGroupCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final String[] args = commandEvent.getArgs().split(" ");
    final Locale locale = localeService.getLocaleForUser(user);
    if (args.length < 2) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid group 10:00 solna platform"));
    }
    String timeString = args[0];
    LocalTime startAtTime = Utils.parseTime(user, timeString, localeService);
    assertTimeNotInNoRaidTimespan(user, startAtTime, localeService);
    StringBuilder gymNameBuilder = new StringBuilder();
    for (int i = 1; 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 = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
    createRaidGroup(commandEvent.getChannel(), commandEvent.getGuild(), config, user, locale, startAtTime, raid.getId(), localeService, raidRepository, botService, serverConfigRepository, pokemonRepository, gymRepository, clockService, executorService, pokemonRaidStrategyService);
    commandEvent.reactSuccess();
    removeOriginMessageIfConfigSaysSo(config, commandEvent);
}
Also used : 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) Raid(pokeraidbot.domain.raid.Raid)

Example 15 with Raid

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

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