use of pokeraidbot.domain.raid.signup.SignUp in project pokeraidbot by magnusmickelsson.
the class Utils method getNamesOfThoseWithSignUps.
public static Set<String> getNamesOfThoseWithSignUps(Set<SignUp> signUpsAt, boolean includeEta) {
final Set<String> signUpNames;
signUpNames = new LinkedHashSet<>();
for (SignUp signUp : signUpsAt) {
if (signUp.getHowManyPeople() > 0) {
String text = signUp.getUserName() + " (**" + signUp.getHowManyPeople();
if (includeEta) {
text = text + ", ETA " + printTime(signUp.getArrivalTime());
}
text = text + "**)";
signUpNames.add(text);
}
}
return signUpNames;
}
use of pokeraidbot.domain.raid.signup.SignUp in project pokeraidbot by magnusmickelsson.
the class RaidRepository method executeSignUpCommand.
public String executeSignUpCommand(Config config, User user, Locale localeForUser, String[] args, String help) {
String people = args[0];
String userName = user.getName();
if (args.length < 3 || args.length > 10) {
throw new WrongNumberOfArgumentsException(user, localeService, 3, args.length, help);
}
Integer numberOfPeople = Utils.assertNotTooManyOrNoNumber(user, localeService, people);
String timeString = args[1];
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 = getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
LocalTime eta = Utils.parseTime(user, timeString, localeService);
LocalDateTime realEta = LocalDateTime.of(raid.getEndOfRaid().toLocalDate(), eta);
assertEtaNotAfterRaidEnd(user, raid, realEta, localeService);
assertSignupTimeNotBeforeRaidStartAndNow(user, realEta, raid.getEndOfRaid(), localeService, raid.isExRaid());
raid.signUp(user, numberOfPeople, eta, this);
final String currentSignupText = localeService.getMessageFor(LocaleService.CURRENT_SIGNUPS, localeForUser);
final Set<SignUp> signUps = raid.getSignUps();
Set<String> signUpNames = Utils.getNamesOfThoseWithSignUps(signUps, true);
final String allSignUpNames = StringUtils.join(signUpNames, ", ");
final String signUpText = raid.getSignUps().size() > 1 ? currentSignupText + "\n" + allSignUpNames : "";
return localeService.getMessageFor(LocaleService.SIGNUPS, localeForUser, userName, gym.getName(), signUpText);
}
use of pokeraidbot.domain.raid.signup.SignUp in project pokeraidbot by magnusmickelsson.
the class RaidRepository method getRaidInstance.
private Raid getRaidInstance(RaidEntity raidEntity) {
Validate.notNull(raidEntity);
final String region = raidEntity.getRegion();
final Raid raid = new Raid(pokemonRepository.getByName(raidEntity.getPokemon()), raidEntity.getEndOfRaid(), gymRepository.findByName(raidEntity.getGym(), region), localeService, region);
raid.setCreator(raidEntity.getCreator());
raid.setId(raidEntity.getId());
Map<String, SignUp> signUps = new ConcurrentHashMap<>();
for (RaidEntitySignUp signUp : raidEntity.getSignUpsAsSet()) {
signUps.put(signUp.getResponsible(), new SignUp(signUp.getResponsible(), signUp.getNumberOfPeople(), LocalTime.parse(signUp.getEta(), Utils.timeParseFormatter)));
}
raid.setSignUps(signUps);
return raid;
}
use of pokeraidbot.domain.raid.signup.SignUp in project pokeraidbot by magnusmickelsson.
the class RaidStatusCommand method executeWithConfig.
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
String gymName = commandEvent.getArgs();
final User user = commandEvent.getAuthor();
final Gym gym = gymRepository.search(user, gymName, config.getRegion());
final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
final Set<SignUp> signUps = raid.getSignUps();
final int numberOfPeople = raid.getNumberOfPeopleSignedUp();
final Locale localeForUser = localeService.getLocaleForUser(user);
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setAuthor(null, null, null);
final Pokemon pokemon = raid.getPokemon();
embedBuilder.setTitle(localeService.getMessageFor(LocaleService.RAIDSTATUS, localeForUser, gym.getName() + (gym.isExGym() ? Emotes.STAR + "" : "")), Utils.getNonStaticMapUrl(gym));
StringBuilder sb = new StringBuilder();
final String activeText = localeService.getMessageFor(LocaleService.ACTIVE, localeForUser);
final String startGroupText = localeService.getMessageFor(LocaleService.START_GROUP, localeForUser);
final String findYourWayText = localeService.getMessageFor(LocaleService.FIND_YOUR_WAY, localeForUser);
final String raidBossText = localeService.getMessageFor(LocaleService.RAID_BOSS, localeForUser);
final Set<String> signUpNames = getNamesOfThoseWithSignUps(raid.getSignUps(), true);
final String allSignUpNames = StringUtils.join(signUpNames, ", ");
sb.append(raidBossText).append(" **").append(pokemon).append("** - ").append("*!raid vs ").append(pokemon.getName()).append("*\n");
sb.append("**").append(activeText).append(":** ").append(printTimeIfSameDay(getStartOfRaid(raid.getEndOfRaid(), false))).append("-").append(printTimeIfSameDay(raid.getEndOfRaid())).append("\t**").append(numberOfPeople).append(" ").append(localeService.getMessageFor(LocaleService.SIGNED_UP, localeForUser)).append("**").append(signUps.size() > 0 ? ":\n" + allSignUpNames : "").append("\n").append(startGroupText).append(":\n*!raid group ").append(printTime(raid.getEndOfRaid().toLocalTime().minusMinutes(15))).append(" ").append(gymName).append("*\n\n");
sb.append(localeService.getMessageFor(LocaleService.CREATED_BY, localeForUser)).append(": ").append(raid.getCreator());
embedBuilder.setFooter(findYourWayText + localeService.getMessageFor(LocaleService.GOOGLE_MAPS, localeService.getLocaleForUser(user)), Utils.getPokemonIcon(pokemon));
embedBuilder.setDescription(sb.toString());
final MessageEmbed messageEmbed = embedBuilder.build();
replyBasedOnConfig(config, commandEvent, messageEmbed);
}
use of pokeraidbot.domain.raid.signup.SignUp 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));
}
}
Aggregations