use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.
the class UserConfigCommand method setLocaleForUser.
private Locale setLocaleForUser(User user, UserConfig userConfig, String value) {
final Locale newLocale = new Locale(value);
if (!LocaleService.isSupportedLocale(newLocale)) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.UNSUPPORTED_LOCALE, localeService.getLocaleForUser(user), value));
}
userConfig.setLocale(newLocale);
userConfigRepository.save(userConfig);
return newLocale;
}
use of pokeraidbot.domain.errors.UserMessedUpException 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);
}
use of pokeraidbot.domain.errors.UserMessedUpException 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);
}
use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.
the class RaidOverviewCommand method executeWithConfig.
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
final User user = commandEvent.getAuthor();
final Locale locale = config.getLocale();
if (!isUserAdministrator(commandEvent) && !isUserServerMod(commandEvent, config)) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_PERMISSION, localeService.getLocaleForUser(user)));
}
String msgId = config.getOverviewMessageId();
final String server = config.getServer();
if (!StringUtils.isEmpty(msgId)) {
final String args = commandEvent.getArgs();
if (!StringUtils.isEmpty(args) && args.equalsIgnoreCase("reset")) {
try {
commandEvent.getChannel().getMessageById(msgId).complete().delete().queue();
} catch (Throwable t) {
// Ignore, just means the message couldn't be cleared/deleted and have to be manually purged
LOGGER.debug("We couldn't find and delete overview for server " + server + ": " + t.getMessage());
}
serverConfigRepository.setOverviewMessageIdForServer(server, null);
LOGGER.info("Cleared overview message for server " + server + ".");
replyBasedOnConfig(config, commandEvent, localeService.getMessageFor(LocaleService.OVERVIEW_CLEARED, locale));
} else {
LOGGER.info("Server overview message ID not empty. Overview already exists for this server.");
replyBasedOnConfig(config, commandEvent, localeService.getMessageFor(LocaleService.OVERVIEW_EXISTS, locale));
}
} else {
final String messageString = getOverviewMessage(config, localeService, raidRepository, clockService, locale, strategyService);
commandEvent.getChannel().sendMessage(messageString).queue(msg -> {
final String messageId = msg.getId();
serverConfigRepository.setOverviewMessageIdForServer(server, messageId);
final Callable<Boolean> refreshEditThreadTask = getMessageRefreshingTaskToSchedule(user, server, messageId, localeService, locale, serverConfigRepository, raidRepository, clockService, commandEvent.getChannel(), executorService, strategyService);
executorService.submit(refreshEditThreadTask);
});
}
}
use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.
the class Utils method parseTime.
public static LocalTime parseTime(User user, String timeString, LocaleService localeService) {
LocalTime endsAtTime;
try {
timeString = preProcessTimeString(timeString);
endsAtTime = LocalTime.parse(timeString, Utils.timeParseFormatter);
} catch (DateTimeParseException | NullPointerException e) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.BAD_DATETIME_FORMAT, localeService.getLocaleForUser(user), "HH:MM", timeString));
}
return endsAtTime;
}
Aggregations