use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.
the class CSVGymDataReader method readAll.
public Set<Gym> readAll() {
String line;
Set<Gym> gyms = new HashSet<>();
Set<String> exGyms = readExGymListIfExists(inputStreamEx, resourceName);
try {
final InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
BufferedReader br = new BufferedReader(inputStreamReader);
while ((line = br.readLine()) != null) {
String[] rowElements = line.split(GymDataImportTool.separator);
if (rowElements[0].equalsIgnoreCase("ID")) {
// This is the header of the file, ignore
} else {
try {
String id = rowElements[0].trim();
String x = rowElements[1].replaceAll("\"", "").trim();
String y = rowElements[2].replaceAll("\"", "").trim();
String name = rowElements[3].trim();
String area = rowElements[4].trim();
final boolean isExGym = exGyms.contains(name);
Gym gym = new Gym(name, id, x, y, area, isExGym);
gyms.add(gym);
} catch (Throwable t) {
LOGGER.warn("Encountered problem for this row: " + line + " - error: " + t.getMessage());
throw new RuntimeException(t);
}
}
}
} catch (IOException e) {
LOGGER.error("Error while trying to open gym file input stream " + resourceName + ": " + e.getMessage());
}
LOGGER.info("Parsed " + gyms.size() + " gyms from \"" + resourceName + "\".");
return gyms;
}
use of pokeraidbot.domain.gym.Gym 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.gym.Gym 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.gym.Gym in project pokeraidbot by magnusmickelsson.
the class WhereIsGymCommand method executeWithConfig.
@Override
protected void executeWithConfig(CommandEvent commandEvent, Config config) {
String gymName = commandEvent.getArgs();
final Gym gym = gymRepository.search(commandEvent.getAuthor(), gymName, config.getRegion());
String staticUrl = Utils.getStaticMapUrl(gym);
String nonStaticUrl = Utils.getNonStaticMapUrl(gym);
replyMapBasedOnConfig(config, commandEvent, new EmbedBuilder().setImage(staticUrl).setTitle(gym.getName(), nonStaticUrl).build());
}
use of pokeraidbot.domain.gym.Gym in project pokeraidbot by magnusmickelsson.
the class NewRaidGroupCommand 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 group 10:00 solna platform"));
}
String timeString = args[0];
LocalTime startAtTime = Utils.parseTime(user, timeString, localeService);
assertTimeNotInNoRaidTimespan(user, startAtTime, localeService);
StringBuilder gymNameBuilder = new StringBuilder();
for (int i = 1; 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 = raidRepository.getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), 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);
}
Aggregations