use of pokeraidbot.infrastructure.jpa.raid.RaidGroup in project pokeraidbot by magnusmickelsson.
the class AlterRaidCommand method changeGroupTime.
private boolean changeGroupTime(CommandEvent commandEvent, Config config, User user, String userName, Raid raid, LocalDateTime newDateTime) {
boolean groupChanged = false;
final Set<RaidGroup> groups = raidRepository.getGroups(raid);
final Set<EmoticonSignUpMessageListener> listenersToCheck = getListenersToCheck(commandEvent, config, user, raid, groups);
for (EmoticonSignUpMessageListener listener : listenersToCheck) {
final String raidId = raid.getId();
final LocalDateTime currentStartAt = listener.getStartAt();
if (currentStartAt != null && currentStartAt.equals(newDateTime)) {
LOGGER.info("Group is already at input time.");
// This group is already at the time to change to
commandEvent.reactError();
} else if (currentStartAt != null) {
LOGGER.info("Changing group time from " + currentStartAt + " to " + newDateTime);
RaidGroup raidGroup = raidRepository.changeGroup(user, raidId, listener.getUserId(), currentStartAt, newDateTime);
raidRepository.moveAllSignUpsForTimeToNewTime(raidId, currentStartAt, newDateTime, user);
listener.setStartAt(newDateTime);
groupChanged = true;
replyBasedOnConfigAndRemoveAfter(config, commandEvent, localeService.getMessageFor(LocaleService.MOVED_GROUP, localeService.getLocaleForUser(user), printTimeIfSameDay(currentStartAt), printTimeIfSameDay(newDateTime), raid.getGym().getName()), BotServerMain.timeToRemoveFeedbackInSeconds);
LOGGER.info("Group time changed. Group: " + raidGroup);
commandEvent.reactSuccess();
} else {
LOGGER.info("Group is about to get cleaned up.");
commandEvent.reactError();
// This group is about to get cleaned up since its start time is null
replyBasedOnConfigAndRemoveAfter(config, commandEvent, localeService.getMessageFor(LocaleService.GROUP_CLEANING_UP, localeService.getLocaleForUser(user)), BotServerMain.timeToRemoveFeedbackInSeconds);
return true;
}
}
if (!groupChanged) {
throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid change group 10:00 solna platform"));
}
return false;
}
use of pokeraidbot.infrastructure.jpa.raid.RaidGroup in project pokeraidbot by magnusmickelsson.
the class RaidRepository method deleteGroup.
public RaidGroup deleteGroup(String raidId, String groupId) {
final RaidEntity entity = findEntityByRaidId(raidId);
if (entity == null) {
return null;
}
final RaidGroup removedGroup = entity.removeGroup(groupId);
if (removedGroup == null) {
throw new RuntimeException("No group with ID " + groupId + " for raid " + entity);
}
return removedGroup;
}
use of pokeraidbot.infrastructure.jpa.raid.RaidGroup in project pokeraidbot by magnusmickelsson.
the class RaidRepository method getGroups.
public Set<RaidGroup> getGroups(Raid raid) {
RaidEntity entity = findEntityByRaidId(raid.getId());
final Set<RaidGroup> groups = entity.getGroupsAsSet();
return groups;
}
use of pokeraidbot.infrastructure.jpa.raid.RaidGroup 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.infrastructure.jpa.raid.RaidGroup in project pokeraidbot by magnusmickelsson.
the class RaidOverviewCommand method getOverviewMessage.
private static String getOverviewMessage(Config config, LocaleService localeService, RaidRepository raidRepository, ClockService clockService, Locale locale, PokemonRaidStrategyService strategyService) {
Set<Raid> raids = raidRepository.getAllRaidsForRegion(config.getRegion());
StringBuilder stringBuilder = new StringBuilder();
if (raids.size() == 0) {
stringBuilder.append(localeService.getMessageFor(LocaleService.LIST_NO_RAIDS, locale));
} else {
StringBuilder exRaids = new StringBuilder();
stringBuilder.append("**").append(localeService.getMessageFor(LocaleService.CURRENT_RAIDS, locale));
stringBuilder.append(":**");
stringBuilder.append("\n").append(localeService.getMessageFor(LocaleService.RAID_DETAILS, locale)).append("\n");
Pokemon currentPokemon = null;
for (Raid raid : raids) {
final Pokemon raidBoss = raid.getPokemon();
if (!raid.isExRaid() && (currentPokemon == null || (!currentPokemon.equals(raidBoss)))) {
currentPokemon = raid.getPokemon();
final PokemonRaidInfo raidInfo = strategyService.getRaidInfo(currentPokemon);
stringBuilder.append("\n**").append(currentPokemon.getName()).append("**");
if (raidInfo != null && raidInfo.getBossTier() > 0) {
stringBuilder.append(" (").append(raidInfo.getBossTier()).append(")");
}
stringBuilder.append("\n");
}
final int numberOfPeople = raid.getNumberOfPeopleSignedUp();
final Gym raidGym = raid.getGym();
final Set<RaidGroup> groups = raidRepository.getGroups(raid);
if (!raid.isExRaid()) {
if (raidGym.isExGym()) {
stringBuilder.append("**").append(raidGym.getName()).append(Emotes.STAR + "**");
} else {
stringBuilder.append("*").append(raidGym.getName()).append("*");
}
stringBuilder.append(" ").append(printTimeIfSameDay(getStartOfRaid(raid.getEndOfRaid(), false))).append("-").append(printTime(raid.getEndOfRaid().toLocalTime()));
if (groups.size() < 1) {
stringBuilder.append(" (**").append(numberOfPeople).append("**)");
} else {
stringBuilder.append(raidRepository.listGroupsForRaid(raid, groups));
}
stringBuilder.append("\n");
} else {
exRaids.append("\n*").append(raidGym.getName());
exRaids.append("* ").append(localeService.getMessageFor(LocaleService.RAID_BETWEEN, locale, printTimeIfSameDay(getStartOfRaid(raid.getEndOfRaid(), true)), printTime(raid.getEndOfRaid().toLocalTime())));
if (groups.size() < 1) {
exRaids.append(" (**").append(numberOfPeople).append("**)");
} else {
exRaids.append(raidRepository.listGroupsForRaid(raid, groups));
}
}
}
final String exRaidList = exRaids.toString();
if (exRaidList.length() > 1) {
stringBuilder.append("\n**Raid-EX:**").append(exRaidList);
}
}
stringBuilder.append("\n\n").append(localeService.getMessageFor(LocaleService.UPDATED_EVERY_X, locale, LocaleService.asString(TimeUnit.SECONDS, locale), String.valueOf(60))).append(" ").append(localeService.getMessageFor(LocaleService.LAST_UPDATE, locale, printTime(clockService.getCurrentTime())));
return stringBuilder.toString();
}
Aggregations