use of pokeraidbot.infrastructure.jpa.config.Config in project pokeraidbot by magnusmickelsson.
the class RaidRepositoryTest method moveTimeForGroupWorks.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void moveTimeForGroupWorks() throws Exception {
// We're not allowed to create signups at night, so mocking time
clockService.setMockTime(LocalTime.of(10, 0));
final LocalDateTime now = clockService.getCurrentDateTime();
final LocalTime nowTime = now.toLocalTime();
LocalDateTime endOfRaid = now.plusMinutes(45);
final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
String raidCreatorName = "testUser1";
User user = mock(User.class);
when(user.getName()).thenReturn(raidCreatorName);
Guild guild = mock(Guild.class);
Config config = mock(Config.class);
try {
repo.newRaid(user, enteiRaid, guild, config, "test");
} catch (RuntimeException e) {
System.err.println(e.getMessage());
fail("Could not save raid: " + e.getMessage());
}
List<User> raiders = new ArrayList<>();
for (int i = 0; i < 5; i++) {
final User raider = mock(User.class);
when(raider.getName()).thenReturn("User" + i);
raiders.add(raider);
}
Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
final LocalDateTime raidGroupTime = endOfRaid.minusMinutes(10);
for (User raider : raiders) {
repo.addSignUp(raider, raid, new SignUp(raider.getName(), 2, raidGroupTime.toLocalTime()));
}
final LocalDateTime newRaidGroupTime = raidGroupTime.plusMinutes(2);
RaidEntity entity = raidEntityRepository.findOne(raid.getId());
repo.moveAllSignUpsForTimeToNewTime(raid.getId(), raidGroupTime, newRaidGroupTime, user);
entity = raidEntityRepository.findOne(raid.getId());
raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
entity = raidEntityRepository.findOne(raid.getId());
assertThat(raid.getSignUps().size(), is(5));
assertThat(raid.getNumberOfPeopleSignedUp(), is(10));
assertThat(raid.getSignUpsAt(newRaidGroupTime.toLocalTime()).size(), is(5));
assertThat(raid.getSignUpsAt(raidGroupTime.toLocalTime()).size(), is(0));
}
use of pokeraidbot.infrastructure.jpa.config.Config in project pokeraidbot by magnusmickelsson.
the class RaidRepositoryTest method changeEndOfRaidWorks.
@Test
public void changeEndOfRaidWorks() throws Exception {
// We're not allowed to create signups at night, so mocking time
clockService.setMockTime(LocalTime.of(10, 0));
final LocalDateTime now = clockService.getCurrentDateTime();
final LocalTime nowTime = now.toLocalTime();
LocalDateTime endOfRaid = now.plusMinutes(45);
final Gym gym = gymRepository.findByName("Blenda", uppsalaRegion);
Raid enteiRaid = new Raid(pokemonRepository.search("Entei", null), endOfRaid, gym, localeService, uppsalaRegion);
String raidCreatorName = "testUser1";
User user = mock(User.class);
when(user.getName()).thenReturn(raidCreatorName);
Guild guild = mock(Guild.class);
Config config = mock(Config.class);
try {
repo.newRaid(user, enteiRaid, guild, config, "test");
} catch (RuntimeException e) {
System.err.println(e.getMessage());
fail("Could not save raid: " + e.getMessage());
}
Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user);
Raid changedRaid = repo.changeEndOfRaid(raid.getId(), endOfRaid.plusMinutes(5), guild, config, user, "test");
assertThat(raid.getEndOfRaid(), not(changedRaid.getEndOfRaid()));
assertThat(changedRaid.getEndOfRaid(), is(raid.getEndOfRaid().plusMinutes(5)));
assertThat(raid.getGym(), is(changedRaid.getGym()));
assertThat(raid.getSignUps(), is(changedRaid.getSignUps()));
assertThat(raid.getRegion(), is(changedRaid.getRegion()));
assertThat(raid.getPokemon().getName(), is(changedRaid.getPokemon().getName()));
}
use of pokeraidbot.infrastructure.jpa.config.Config 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);
}
}
}
}
Aggregations