Search in sources :

Example 11 with UserMessedUpException

use of pokeraidbot.domain.errors.UserMessedUpException 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 12 with UserMessedUpException

use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.

the class SignUpCommand method executeWithConfig.

@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
    final User user = commandEvent.getAuthor();
    final Locale localeForUser = localeService.getLocaleForUser(user);
    final String[] args = Utils.prepareArguments(commandEvent);
    if (args.length < 3) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid add 1 10:00 solna platform " + "(alt. *+1 10:00 solna platform*)"));
    }
    final String returnMessage = raidRepository.executeSignUpCommand(config, user, localeForUser, args, help);
    replyBasedOnConfigAndRemoveAfter(config, commandEvent, returnMessage, BotServerMain.timeToRemoveFeedbackInSeconds);
}
Also used : Locale(java.util.Locale) User(net.dv8tion.jda.core.entities.User) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException)

Example 13 with UserMessedUpException

use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.

the class UserConfigCommand method setNickForUser.

private UserConfig setNickForUser(Config config, User user, UserConfig userConfig, String value) {
    if (value.length() > 10 || value.length() < 3) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.USER_NICK_INVALID, localeService.getLocaleForUser(user)));
    }
    if (userConfig == null) {
        final UserConfig entity = new UserConfig(user.getId(), null, null, null, config.getLocale());
        entity.setNick(value);
        userConfig = userConfigRepository.save(entity);
    } else {
        userConfig.setNick(value);
        userConfig = userConfigRepository.save(userConfig);
    }
    return userConfig;
}
Also used : UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) UserConfig(pokeraidbot.infrastructure.jpa.config.UserConfig)

Example 14 with UserMessedUpException

use of pokeraidbot.domain.errors.UserMessedUpException 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 15 with UserMessedUpException

use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.

the class StartUpEventListener method attachToOverviewMessageIfExists.

private boolean attachToOverviewMessageIfExists(Guild guild, Config config, String messageId, MessageChannel channel, PokemonRaidStrategyService raidStrategyService) {
    try {
        if (channel.getMessageById(messageId).complete() != null) {
            final Locale locale = config.getLocale();
            final Callable<Boolean> overviewTask = RaidOverviewCommand.getMessageRefreshingTaskToSchedule(null, config.getServer(), messageId, localeService, locale, serverConfigRepository, raidRepository, clockService, channel, executorService, raidStrategyService);
            executorService.submit(overviewTask);
            LOGGER.info("Found overview message for channel " + channel.getName() + " (server " + guild.getName() + "). Attaching to it.");
            return true;
        }
    } catch (UserMessedUpException e) {
        LOGGER.warn("Could not attach to message due to an error: " + e.getMessage());
    } catch (ErrorResponseException e) {
    // We couldn't find the message in this channel or had permission issues, ignore
    } catch (Throwable e) {
    // Ignore any other error and try the other server channels
    }
    return false;
}
Also used : Locale(java.util.Locale) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) ErrorResponseException(net.dv8tion.jda.core.exceptions.ErrorResponseException)

Aggregations

UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)32 Locale (java.util.Locale)13 User (net.dv8tion.jda.core.entities.User)12 Gym (pokeraidbot.domain.gym.Gym)12 Raid (pokeraidbot.domain.raid.Raid)11 LocalDateTime (java.time.LocalDateTime)8 LocalTime (java.time.LocalTime)7 Pokemon (pokeraidbot.domain.pokemon.Pokemon)6 RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)5 EmoticonSignUpMessageListener (pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener)4 RaidEntity (pokeraidbot.infrastructure.jpa.raid.RaidEntity)4 UserConfig (pokeraidbot.infrastructure.jpa.config.UserConfig)3 RaidEntitySignUp (pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp)3 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)2 ErrorResponseException (net.dv8tion.jda.core.exceptions.ErrorResponseException)2 SignUp (pokeraidbot.domain.raid.signup.SignUp)2 LocalDate (java.time.LocalDate)1 DateTimeParseException (java.time.format.DateTimeParseException)1 Random (java.util.Random)1 TimeUnit (java.util.concurrent.TimeUnit)1