use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.
the class RaidRepository method changeGroup.
public RaidGroup changeGroup(User user, String raidId, String groupCreatorId, LocalDateTime currentStartAt, LocalDateTime newDateTime) {
final RaidEntity entityByRaidId = findEntityByRaidId(raidId);
if (entityByRaidId == null) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_RAID_AT_GYM, localeService.getLocaleForUser(user)));
}
RaidGroup group = entityByRaidId.getGroupByCreatorAndStart(groupCreatorId, currentStartAt);
if (group == null) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_SUCH_GROUP, localeService.getLocaleForUser(user)));
}
group.setStartsAt(newDateTime);
raidEntityRepository.save(entityByRaidId);
return group;
}
use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.
the class RaidRepository method moveAllSignUpsForTimeToNewTime.
public void moveAllSignUpsForTimeToNewTime(String raidId, LocalDateTime currentStartAt, LocalDateTime newDateTime, User user) {
Validate.notNull(raidId, "Raid ID cannot be null");
Validate.notNull(currentStartAt, "Current start time cannot be null");
Validate.notNull(newDateTime, "New start time cannot be null");
Validate.notNull(user, "User cannot be null");
RaidEntity entity = raidEntityRepository.findOne(raidId);
if (entity != null) {
for (RaidEntitySignUp signUp : entity.getSignUpsAsSet()) {
if (signUp.getArrivalTime().equals(currentStartAt.toLocalTime())) {
signUp.setEta(Utils.printTime(newDateTime.toLocalTime()));
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Changed ETA for signup: " + signUp);
}
}
}
raidEntityRepository.save(entity);
} else {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_RAID_AT_GYM, localeService.getLocaleForUser(user)));
}
}
use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.
the class NewRaidExCommand 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 ex mewtwo 2017-11-11 10:00 solna platform"));
}
String pokemonName = args[0];
final Pokemon pokemon = pokemonRepository.search(pokemonName, user);
final Locale locale = localeService.getLocaleForUser(user);
if (!Utils.isRaidExPokemon(pokemon.getName())) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NOT_EX_RAID, locale, pokemonName));
}
String dateString = args[1];
String timeString = args[2];
LocalTime endsAtTime = Utils.parseTime(user, timeString, localeService);
LocalDate endsAtDate = Utils.parseDate(user, dateString, localeService);
LocalDateTime endsAt = LocalDateTime.of(endsAtDate, endsAtTime);
assertTimeNotInNoRaidTimespan(user, endsAtTime, localeService);
if (endsAtDate.isAfter(LocalDate.now().plusDays(20))) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.EX_DATE_LIMITS, locale));
}
assertCreateRaidTimeNotBeforeNow(user, endsAt, localeService);
StringBuilder gymNameBuilder = new StringBuilder();
for (int i = 3; 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());
if (!raid.isExRaid()) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NOT_EX_RAID, locale, pokemonName));
}
raidRepository.newRaid(user, raid, commandEvent.getGuild(), config, "!raid ex " + raid.getPokemon().getName() + " " + printTimeIfSameDay(raid.getEndOfRaid()) + " " + gym.getName());
replyBasedOnConfig(config, commandEvent, localeService.getMessageFor(LocaleService.NEW_RAID_CREATED, locale, raid.toString(locale)));
}
use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.
the class GymCommands method executeWithConfig.
@Override
protected void executeWithConfig(CommandEvent event, Config config) {
final User user = event.getAuthor();
final String eventArgs = event.getArgs();
if (!isUserServerMod(event, config) && !isUserAdministrator(event)) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_PERMISSION, localeService.getLocaleForUser(user)));
}
if (eventArgs.startsWith("get ")) {
String gymName = eventArgs.replaceAll("get\\s{1,3}", "").trim();
final Gym gym = gymRepository.findByName(gymName, config.getRegion());
replyBasedOnConfig(config, event, "Found gym: " + gym.toStringDetails());
} else {
String[] gymArgs = eventArgs.replaceAll("gym\\s{1,3}", "").trim().split(";");
if (gymArgs == null || gymArgs.length < 4 || gymArgs.length > 4) {
replyBasedOnConfig(config, event, "Bad syntax, should be: !raid gym add {gymname};{latitude};{longitude};{exgym true or false");
return;
} else {
final Random random = new Random();
random.setSeed(System.currentTimeMillis());
Gym gym = new Gym(gymArgs[0], "" + random.nextInt(99999999), gymArgs[1], gymArgs[2], config.getRegion(), Boolean.valueOf(gymArgs[3]));
gymRepository.addTemporary(user, gym, config.getRegion());
replyBasedOnConfig(config, event, "Gym added temporarily: " + gym.toStringDetails());
}
}
}
use of pokeraidbot.domain.errors.UserMessedUpException in project pokeraidbot by magnusmickelsson.
the class TrackingService method addToDbAndCollection.
private void addToDbAndCollection(PokemonTrackingTarget trackingTarget, User user, Config config) {
UserConfig userConfig = userConfigRepository.findOne(user.getId());
if (userConfig != null) {
if (userConfig.hasFreeTrackingSpot()) {
userConfig.setNextTrackingSpot(trackingTarget.getPokemon());
} else {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.TRACKING_NONE_FREE, localeService.getLocaleForUser(user)));
}
} else {
// Per default, let user have the same locale as the server
userConfig = new UserConfig(user.getId(), trackingTarget.getPokemon(), null, null, config.getLocale());
}
userConfigRepository.save(userConfig);
trackingTargets.add(trackingTarget);
}
Aggregations