Search in sources :

Example 16 with Raid

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

the class NewRaidGroupCommand method createRaidGroup.

public static void createRaidGroup(MessageChannel channel, Guild guild, Config config, User user, Locale locale, LocalTime startAtTime, String raidId, LocaleService localeService, RaidRepository raidRepository, BotService botService, ServerConfigRepository serverConfigRepository, PokemonRepository pokemonRepository, GymRepository gymRepository, ClockService clockService, ExecutorService executorService, PokemonRaidStrategyService pokemonRaidStrategyService) {
    assertAllParametersNotNullOrEmpty(channel, config, user, locale, startAtTime, raidId, localeService, raidRepository, botService, serverConfigRepository, pokemonRepository, gymRepository, clockService, executorService);
    Raid raid = raidRepository.getById(raidId);
    final LocalDate raidDate = raid.getEndOfRaid().toLocalDate();
    final LocalDateTime raidStart = Utils.getStartOfRaid(raid.getEndOfRaid(), raid.isExRaid());
    LocalDateTime startAt = LocalDateTime.of(raidDate, startAtTime);
    checkValidInput(user, locale, startAtTime, localeService, raidRepository, raid, raidStart, startAt);
    final EmoticonSignUpMessageListener emoticonSignUpMessageListener = new EmoticonSignUpMessageListener(botService, localeService, serverConfigRepository, raidRepository, pokemonRepository, gymRepository, raid.getId(), startAt, user);
    TimeUnit delayTimeUnit = raid.isExRaid() ? TimeUnit.MINUTES : TimeUnit.SECONDS;
    int delay = raid.isExRaid() ? 1 : 15;
    final MessageEmbed messageEmbed = getRaidGroupMessageEmbed(startAt, raid.getId(), localeService, clockService, locale, delayTimeUnit, delay, raidRepository);
    channel.sendMessage(messageEmbed).queue(embed -> {
        final String messageId = embed.getId();
        emoticonSignUpMessageListener.setInfoMessageId(messageId);
        emoticonSignUpMessageListener.setEmoteMessageId(messageId);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Thread: " + Thread.currentThread().getId() + " - Adding event listener and emotes for emote message with ID: " + messageId);
        }
        final MessageChannel embedChannel = embed.getChannel();
        RaidGroup group = new RaidGroup(config.getServer(), embedChannel.getName(), messageId, messageId, user.getId(), startAt);
        group = raidRepository.newGroupForRaid(user, group, raid, guild, config);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Created group in channel " + channel.getName() + " for emote message with ID: " + messageId + " - " + group);
        }
        // Add number icons for signups
        embedChannel.addReactionById(messageId, Emotes.ONE).queue();
        embedChannel.addReactionById(messageId, Emotes.TWO).queue();
        embedChannel.addReactionById(messageId, Emotes.THREE).queue();
        embedChannel.addReactionById(messageId, Emotes.FOUR).queue();
        embedChannel.addReactionById(messageId, Emotes.FIVE).queue();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Eventlistener and emotes added for emote message with ID: " + messageId);
        }
        if (config.isPinGroups()) {
            embedChannel.pinMessageById(embed.getId()).queueAfter(50, TimeUnit.MILLISECONDS);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Pinning info message for raid group. ID is: " + embed.getId());
            }
        }
        final Callable<Boolean> refreshEditThreadTask = getMessageRefreshingTaskToSchedule(channel, raid, emoticonSignUpMessageListener, messageId, locale, raidRepository, localeService, clockService, executorService, botService, delayTimeUnit, delay, group.getId());
        executorService.submit(refreshEditThreadTask);
    });
}
Also used : LocalDateTime(java.time.LocalDateTime) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) EmoticonSignUpMessageListener(pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener) TimeUnit(java.util.concurrent.TimeUnit) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) Raid(pokeraidbot.domain.raid.Raid) LocalDate(java.time.LocalDate)

Example 17 with Raid

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

the class NewRaidGroupCommand method cleanUpRaidGroupAndDeleteSignUpsIfPossible.

public static void cleanUpRaidGroupAndDeleteSignUpsIfPossible(MessageChannel messageChannel, LocalDateTime startAt, String raidId, EmoticonSignUpMessageListener emoticonSignUpMessageListener, RaidRepository raidRepository, BotService botService, String groupId) {
    Raid raid = null;
    try {
        if (startAt != null && raidId != null) {
            // Clean up all signups that should have done their raid now, if there still is a time
            // (Could be set to null due to an error, in that case keep signups in database)
            raid = raidRepository.removeAllSignUpsAt(raidId, startAt);
        }
    } catch (Throwable t) {
        // Do nothing, just log
        LOGGER.warn("Exception occurred when removing signups: " + t + "-" + t.getMessage());
        if (t instanceof ConcurrentModificationException) {
            LOGGER.warn("This is probably due to raid being removed while cleaning up signups, which is normal.");
        }
    } finally {
        final String raidDescription = raid == null ? "null" : raid.toString();
        cleanUpGroupMessageAndEntity(messageChannel, raidId, emoticonSignUpMessageListener, raidRepository, botService, groupId, raidDescription);
    }
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) Raid(pokeraidbot.domain.raid.Raid)

Example 18 with Raid

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

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

the class PotentialExRaidListCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final Locale locale = localeService.getLocaleForUser(user);
    Set<Raid> raids = raidRepository.getAllRaidsForRegion(config.getRegion());
    StringBuilder stringBuilder = new StringBuilder();
    // todo: i18n
    stringBuilder.append("Potentiella exgym som inte har en kommande EX-raid:\n\n");
    // 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");
    Set<String> exGymNames = new HashSet<>();
    for (Raid raid : raids) {
        if (raid.isExRaid()) {
            exGymNames.add(raid.getGym().getName());
        }
    }
    final Set<String> exGyms = gymRepository.getExGyms(config.getRegion());
    final Collection<String> leftOverGyms = CollectionUtils.subtract(exGyms, exGymNames);
    for (String gym : leftOverGyms) {
        stringBuilder.append(gym).append("\n");
    }
    replyBasedOnConfig(config, commandEvent, stringBuilder.toString());
}
Also used : User(net.dv8tion.jda.core.entities.User) Raid(pokeraidbot.domain.raid.Raid)

Example 20 with Raid

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

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