use of pokeraidbot.domain.pokemon.Pokemon in project pokeraidbot by magnusmickelsson.
the class GymHuntrRaidEventListener method onEvent.
@Override
public void onEvent(Event event) {
if (event instanceof GuildMessageReceivedEvent) {
GuildMessageReceivedEvent guildEvent = (GuildMessageReceivedEvent) event;
final User messageAuthor = guildEvent.getAuthor();
try {
if (isUserGymhuntrBot(messageAuthor) || isUserPokeAlarmBot(messageAuthor)) {
final String serverName = guildEvent.getGuild().getName().toLowerCase();
final Config config = serverConfigRepository.getConfigForServer(serverName);
if (config == null) {
LOGGER.warn("Server configuration is null for this guild: " + guildEvent.getGuild().getName());
return;
}
if (!config.useBotIntegration()) {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Skipping trigger, since bot integration setting is false for server " + guildEvent.getGuild().getName());
}
return;
}
final List<MessageEmbed> embeds = guildEvent.getMessage().getEmbeds();
if (embeds != null && embeds.size() > 0) {
for (MessageEmbed embed : embeds) {
final LocalDateTime currentDateTime = clockService.getCurrentDateTime();
final String description = embed.getDescription();
final String title = embed.getTitle();
List<String> newRaidArguments;
if (isUserGymhuntrBot(messageAuthor)) {
newRaidArguments = gymhuntrArgumentsToCreateRaid(title, description, clockService);
} else if (isUserPokeAlarmBot(messageAuthor)) {
newRaidArguments = pokeAlarmArgumentsToCreateRaid(title, description, clockService);
} else {
newRaidArguments = new ArrayList<>();
}
try {
if (newRaidArguments != null && newRaidArguments.size() > 0) {
final Iterator<String> iterator = newRaidArguments.iterator();
final String gym = iterator.next();
final String pokemon = iterator.next();
final String time = iterator.next();
final Pokemon raidBoss = pokemonRepository.getByName(pokemon);
final String region = config.getRegion();
final Gym raidGym = gymRepository.findByName(gym, region);
final LocalDate currentDate = currentDateTime.toLocalDate();
final LocalDateTime endOfRaid = LocalDateTime.of(currentDate, LocalTime.parse(time, Utils.timeParseFormatter));
final SelfUser botUser = botService.getBot().getSelfUser();
final PokemonRaidInfo raidInfo;
raidInfo = strategyService.getRaidInfo(raidBoss);
handleRaidFromIntegration(botUser, guildEvent, raidBoss, raidGym, endOfRaid, config, clockService, raidInfo, strategyService);
} else {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("No arguments to create raid with for server " + config + ", skipping. Raw command: " + guildEvent.getMessage().getRawContent());
}
}
} catch (Throwable t) {
LOGGER.warn("Exception when trying to get arguments for raid creation: " + t.getMessage());
}
}
}
}
} catch (Throwable t) {
LOGGER.warn("Exception thrown for event listener: " + t.getMessage());
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Stacktrace: ", t);
}
}
}
}
use of pokeraidbot.domain.pokemon.Pokemon in project pokeraidbot by magnusmickelsson.
the class StartRaidAndCreateGroupCommand 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 start-group groudon 10:00 solna platform"));
}
String pokemonName = args[0].trim();
Pokemon pokemon = pokemonRepository.search(pokemonName, user);
String timeString = args[1].trim();
LocalTime startAtTime = Utils.parseTime(user, timeString, localeService);
assertTimeNotInNoRaidTimespan(user, startAtTime, localeService);
StringBuilder gymNameBuilder = new StringBuilder();
for (int i = 2; i < args.length; i++) {
gymNameBuilder.append(args[i]).append(" ");
}
String gymName = gymNameBuilder.toString().trim();
final String region = config.getRegion();
final Gym gym = gymRepository.search(user, gymName, region);
final Raid raid;
if (!raidRepository.isActiveOrExRaidAt(gym, region)) {
final LocalDateTime endOfRaid = LocalDateTime.of(LocalDate.now(), startAtTime.plusMinutes(Utils.RAID_DURATION_IN_MINUTES));
raid = raidRepository.newRaid(user, new Raid(pokemon, endOfRaid, gym, localeService, region), commandEvent.getGuild(), config, commandEvent.getMessage().getRawContent());
} else {
raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, region, 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.pokemon.Pokemon in project pokeraidbot by magnusmickelsson.
the class NewRaidGroupCommand method getRaidGroupMessageEmbed.
private static MessageEmbed getRaidGroupMessageEmbed(LocalDateTime startAt, String raidId, LocaleService localeService, ClockService clockService, Locale locale, TimeUnit delayTimeUnit, int delay, RaidRepository raidRepository) {
Raid currentStateOfRaid = raidRepository.getById(raidId);
final Gym gym = currentStateOfRaid.getGym();
final Pokemon pokemon = currentStateOfRaid.getPokemon();
MessageEmbed messageEmbed;
EmbedBuilder embedBuilder = new EmbedBuilder();
final String headline = localeService.getMessageFor(LocaleService.GROUP_HEADLINE, locale, currentStateOfRaid.getPokemon().getName(), gym.getName() + (gym.isExGym() ? Emotes.STAR : ""));
final String getHereText = localeService.getMessageFor(LocaleService.GETTING_HERE, locale);
embedBuilder.setTitle(getHereText + " " + gym.getName(), Utils.getNonStaticMapUrl(gym));
final LocalDateTime endOfRaid = currentStateOfRaid.getEndOfRaid();
embedBuilder.setAuthor(headline + " " + Utils.printTime(Utils.getStartOfRaid(endOfRaid, currentStateOfRaid.isExRaid()).toLocalTime()) + "-" + Utils.printTime(endOfRaid.toLocalTime()), null, Utils.getPokemonIcon(pokemon));
final Set<SignUp> signUpsAt = currentStateOfRaid.getSignUpsAt(startAt.toLocalTime());
final Set<String> signUpNames = getNamesOfThoseWithSignUps(signUpsAt, false);
final String allSignUpNames = signUpNames.size() > 0 ? StringUtils.join(signUpNames, ", ") : "-";
final int numberOfPeopleArrivingAt = signUpsAt.stream().mapToInt(SignUp::getHowManyPeople).sum();
final String numberOfSignupsText = localeService.getMessageFor(LocaleService.SIGNED_UP, locale);
final String totalSignUpsText = numberOfSignupsText + ": " + numberOfPeopleArrivingAt;
final String thoseWhoAreComingText = localeService.getMessageFor(LocaleService.WHO_ARE_COMING, locale) + ":";
embedBuilder.clearFields();
final String handleSignUpText = localeService.getMessageFor(LocaleService.HANDLE_SIGNUP, locale);
final Set<RaidGroup> groups = raidRepository.getGroups(currentStateOfRaid);
final String descriptionAppendixText;
if (groups.size() > 1) {
descriptionAppendixText = raidRepository.listGroupsForRaid(currentStateOfRaid, groups);
} else {
descriptionAppendixText = "- " + handleSignUpText;
}
embedBuilder.setDescription("**Start: " + printTimeIfSameDay(startAt) + "** " + descriptionAppendixText);
embedBuilder.addField(totalSignUpsText + ". " + thoseWhoAreComingText, allSignUpNames, true);
final String updatedMessage = localeService.getMessageFor(LocaleService.UPDATED_EVERY_X, locale, LocaleService.asString(delayTimeUnit, locale), String.valueOf(delay)) + " " + localeService.getMessageFor(LocaleService.LAST_UPDATE, locale, printTime(clockService.getCurrentTime())) + ".";
embedBuilder.setFooter(updatedMessage, null);
messageEmbed = embedBuilder.build();
return messageEmbed;
}
use of pokeraidbot.domain.pokemon.Pokemon 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.pokemon.Pokemon in project pokeraidbot by magnusmickelsson.
the class RaidListCommand method executeWithConfig.
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
final User user = commandEvent.getAuthor();
final String args = commandEvent.getArgs();
final Locale locale = localeService.getLocaleForUser(user);
Set<Raid> raids;
if (args != null && args.length() > 0) {
raids = raidRepository.getRaidsInRegionForPokemon(config.getRegion(), pokemonRepository.search(args, user));
} else {
raids = raidRepository.getAllRaidsForRegion(config.getRegion());
}
if (raids.size() == 0) {
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setTitle(null);
embedBuilder.setAuthor(null, null, null);
embedBuilder.setDescription(localeService.getMessageFor(LocaleService.LIST_NO_RAIDS, locale));
commandEvent.reply(embedBuilder.build());
} else {
StringBuilder stringBuilder = new StringBuilder();
StringBuilder exRaids = new StringBuilder();
stringBuilder.append("**").append(localeService.getMessageFor(LocaleService.CURRENT_RAIDS, locale));
if (args != null && args.length() > 0) {
stringBuilder.append(" (").append(args).append(")");
}
stringBuilder.append(":**");
stringBuilder.append("\n").append(localeService.getMessageFor(LocaleService.RAID_DETAILS, localeService.getLocaleForUser(user))).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();
stringBuilder.append("\n**").append(currentPokemon.getName()).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);
}
replyBasedOnConfig(config, commandEvent, stringBuilder.toString());
}
}
Aggregations