use of pokeraidbot.domain.pokemon.PokemonRaidInfo 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.PokemonRaidInfo in project pokeraidbot by magnusmickelsson.
the class EggHatchedCommand method executeWithConfig.
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
final User user = commandEvent.getAuthor();
final String userName = user.getName();
final String[] args = commandEvent.getArgs().split(" ");
if (args.length < 2) {
throw new UserMessedUpException(userName, localeService.getMessageFor(LocaleService.BAD_SYNTAX, localeService.getLocaleForUser(user), "!raid hatch Ho-Oh solna platform"));
}
String pokemonName = args[0].trim().toLowerCase();
final String[] gymArguments = ArrayUtils.removeAll(args, 0);
String gymName = StringUtils.join(gymArguments, " ");
final String region = config.getRegion();
final Gym gym = gymRepository.search(user, gymName, region);
final Raid raid = raidRepository.getActiveRaidOrFallbackToExRaid(gym, region, user);
final Pokemon pokemon = pokemonRepository.search(pokemonName, user);
final PokemonRaidInfo existingRaidInfo = raidStrategyService.getRaidInfo(raid.getPokemon());
final int newBossTier = raidStrategyService.getRaidInfo(pokemon).getBossTier();
if (!raid.getPokemon().isEgg()) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.EGG_ALREADY_HATCHED, localeService.getLocaleForUser(user), raid.getPokemon().toString()));
}
if (pokemon.isEgg() || newBossTier != existingRaidInfo.getBossTier()) {
throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.EGG_WRONG_TIER, localeService.getLocaleForUser(user)));
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Trying to hatch raid " + raid + " into " + pokemonName);
}
AlterRaidCommand.changePokemon(gymRepository, localeService, pokemonRepository, raidRepository, commandEvent, config, user, userName, pokemonName, gymArguments);
}
Aggregations