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));
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations