Search in sources :

Example 11 with Config

use of pokeraidbot.infrastructure.jpa.config.Config in project pokeraidbot by magnusmickelsson.

the class RaidRepositoryTest method testCreateGetAndDeleteGroup.

@Test
public void testCreateGetAndDeleteGroup() 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);
    Raid enteiRaid1 = enteiRaid;
    try {
        enteiRaid1 = repo.newRaid(user, enteiRaid1, guild, config, "test");
    } catch (RuntimeException e) {
        System.err.println(e.getMessage());
        fail("Could not save raid: " + e.getMessage());
    }
    enteiRaid = enteiRaid1;
    User user2 = mock(User.class);
    String userName = "testUser2";
    when(user2.getName()).thenReturn(userName);
    LocalTime arrivalTime = nowTime.plusMinutes(30);
    RaidGroup group = new RaidGroup("testserver", "channel", "infoId", "emoteId", "userId", LocalDateTime.of(LocalDate.now(), arrivalTime));
    group = repo.newGroupForRaid(user2, group, enteiRaid, guild, config);
    List<RaidGroup> groupsForServer = repo.getGroupsForServer("testserver");
    assertThat(group != null, is(true));
    assertThat(groupsForServer.size(), is(1));
    assertThat(groupsForServer.iterator().next(), is(group));
    RaidGroup deleted = repo.deleteGroup(enteiRaid.getId(), group.getId());
    assertThat(deleted != null, is(true));
    groupsForServer = repo.getGroupsForServer("testserver");
    assertThat(groupsForServer.size(), is(0));
}
Also used : LocalDateTime(java.time.LocalDateTime) User(net.dv8tion.jda.core.entities.User) LocalTime(java.time.LocalTime) Config(pokeraidbot.infrastructure.jpa.config.Config) Gym(pokeraidbot.domain.gym.Gym) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) Guild(net.dv8tion.jda.core.entities.Guild) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with Config

use of pokeraidbot.infrastructure.jpa.config.Config in project pokeraidbot by magnusmickelsson.

the class RaidRepositoryTest method testSignUp.

@Test
public void testSignUp() 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());
    }
    User user2 = mock(User.class);
    String userName = "testUser2";
    when(user2.getName()).thenReturn(userName);
    Raid raid = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user2);
    // Set to same id for equals comparison
    enteiRaid.setId(raid.getId());
    // Set creator to same for equals comparison
    enteiRaid.setCreator(raid.getCreator());
    assertThat(raid, is(enteiRaid));
    int howManyPeople = 3;
    LocalTime arrivalTime = nowTime.plusMinutes(30);
    raid.signUp(user2, howManyPeople, arrivalTime, repo);
    assertThat(raid.getSignUps().size(), is(1));
    assertThat(raid.getNumberOfPeopleSignedUp(), is(howManyPeople));
    final Raid raidFromDb = repo.getActiveRaidOrFallbackToExRaid(gym, uppsalaRegion, user2);
    assertThat(raidFromDb, is(raid));
    assertThat(raidFromDb.getSignUps().size(), is(1));
}
Also used : LocalDateTime(java.time.LocalDateTime) User(net.dv8tion.jda.core.entities.User) LocalTime(java.time.LocalTime) Config(pokeraidbot.infrastructure.jpa.config.Config) Gym(pokeraidbot.domain.gym.Gym) Guild(net.dv8tion.jda.core.entities.Guild) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with Config

use of pokeraidbot.infrastructure.jpa.config.Config in project pokeraidbot by magnusmickelsson.

the class UnsignWithMinusCommandListener method attemptUnsignFromMinusCommand.

private void attemptUnsignFromMinusCommand(GuildMessageReceivedEvent guildMessageReceivedEvent, String[] splitArguments) {
    final String numberOfPeopleArgument = splitArguments[0];
    final String[] gymArgument = ArrayUtils.removeAll(splitArguments, 0);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Trying to remove " + numberOfPeopleArgument + " from raid, gym " + StringUtils.join(gymArgument, " "));
    }
    final String guild = guildMessageReceivedEvent.getGuild().getName().trim().toLowerCase();
    final Config configForServer = serverConfigRepository.getConfigForServer(guild);
    final User user = guildMessageReceivedEvent.getAuthor();
    String message;
    try {
        message = raidRepository.executeUnsignCommand(configForServer, user, localeService.getLocaleForUser(user), splitArguments, "signup");
        guildMessageReceivedEvent.getMessage().addReaction(Emotes.OK).queue();
        ConfigAwareCommand.removeOriginMessageIfConfigSaysSo(configForServer, guildMessageReceivedEvent);
    } catch (Throwable t) {
        LOGGER.debug("Unsign command failed: " + t.getMessage());
        message = t.getMessage() + "\n\n" + "Syntax: *-1 Solna Platform*";
        guildMessageReceivedEvent.getMessage().addReaction(Emotes.ERROR).queue();
        ConfigAwareCommand.removeOriginMessageIfConfigSaysSo(configForServer, guildMessageReceivedEvent);
    }
    if (!StringUtils.isEmpty(message)) {
        EmbedBuilder embedBuilder = new EmbedBuilder();
        embedBuilder.setAuthor(null, null, null);
        embedBuilder.setTitle(null);
        embedBuilder.setDescription(message);
        final String msgRemoveText = localeService.getMessageFor(LocaleService.KEEP_CHAT_CLEAN, localeService.getLocaleForUser(user), "15");
        embedBuilder.setFooter(msgRemoveText, null);
        guildMessageReceivedEvent.getMessage().getChannel().sendMessage(embedBuilder.build()).queue(msg -> {
            // Clean up feedback after x seconds
            msg.delete().queueAfter(15, TimeUnit.SECONDS);
        });
        LOGGER.debug("Removed signup.");
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) User(net.dv8tion.jda.core.entities.User) Config(pokeraidbot.infrastructure.jpa.config.Config)

Example 14 with Config

use of pokeraidbot.infrastructure.jpa.config.Config in project pokeraidbot by magnusmickelsson.

the class SignupWithPlusCommandListener method attemptSignUpFromPlusCommand.

private void attemptSignUpFromPlusCommand(GuildMessageReceivedEvent guildMessageReceivedEvent, String[] splitArguments) {
    final String numberOfPeopleArgument = splitArguments[0];
    final String etaArgument = splitArguments[1];
    final String[] gymArgument = ArrayUtils.removeAll(splitArguments, 0, 1);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Trying to add " + numberOfPeopleArgument + " to raid, ETA " + etaArgument + " to gym " + StringUtils.join(gymArgument, " "));
    }
    final String guild = guildMessageReceivedEvent.getGuild().getName().trim().toLowerCase();
    final Config configForServer = serverConfigRepository.getConfigForServer(guild);
    final User user = guildMessageReceivedEvent.getAuthor();
    String message;
    try {
        message = raidRepository.executeSignUpCommand(configForServer, user, localeService.getLocaleForUser(user), splitArguments, "signup");
        guildMessageReceivedEvent.getMessage().addReaction(Emotes.OK).queue();
        ConfigAwareCommand.removeOriginMessageIfConfigSaysSo(configForServer, guildMessageReceivedEvent);
    } catch (Throwable t) {
        LOGGER.debug("Signup plus command failed: " + t.getMessage());
        message = t.getMessage() + "\n\n" + "Syntax: *+1 09:45 Solna Platform*";
        guildMessageReceivedEvent.getMessage().addReaction(Emotes.ERROR).queue();
        ConfigAwareCommand.removeOriginMessageIfConfigSaysSo(configForServer, guildMessageReceivedEvent);
    }
    if (!StringUtils.isEmpty(message)) {
        EmbedBuilder embedBuilder = new EmbedBuilder();
        embedBuilder.setAuthor(null, null, null);
        embedBuilder.setTitle(null);
        embedBuilder.setDescription(message);
        final String msgRemoveText = localeService.getMessageFor(LocaleService.KEEP_CHAT_CLEAN, localeService.getLocaleForUser(user), "15");
        embedBuilder.setFooter(msgRemoveText, null);
        guildMessageReceivedEvent.getMessage().getChannel().sendMessage(embedBuilder.build()).queue(msg -> {
            // Clean up feedback after x seconds
            msg.delete().queueAfter(15, TimeUnit.SECONDS);
        });
        LOGGER.debug("Added signup.");
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) User(net.dv8tion.jda.core.entities.User) Config(pokeraidbot.infrastructure.jpa.config.Config)

Example 15 with Config

use of pokeraidbot.infrastructure.jpa.config.Config in project pokeraidbot by magnusmickelsson.

the class TestServerMain method initializeConfig.

@PostConstruct
@Transactional
public void initializeConfig() {
    if (serverConfigRepository.findAll().size() == 0) {
        // My test servers
        serverConfigRepository.save(new Config("uppsala", "zhorhn tests stuff"));
        serverConfigRepository.save(new Config("uppsala", "pokeraidbot_lab"));
        serverConfigRepository.save(new Config("uppsala", "pokeraidbot_lab2"));
        serverConfigRepository.save(new Config("uppsala", "pokeraidbot_stage"));
        serverConfigRepository.save(new Config("uppsala", "pokeraidbot_test"));
        // External user's servers
        serverConfigRepository.save(new Config("luleå", "pokémon luleå"));
        serverConfigRepository.save(new Config("ängelholm", "test pokemongo ängelholm"));
        serverConfigRepository.save(new Config("norrköping", true, "raid-test-nkpg"));
        serverConfigRepository.save(new Config("norrköping", true, "raid - pokemon go norrköping"));
    }
}
Also used : Config(pokeraidbot.infrastructure.jpa.config.Config) PostConstruct(javax.annotation.PostConstruct) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Config (pokeraidbot.infrastructure.jpa.config.Config)18 User (net.dv8tion.jda.core.entities.User)9 Guild (net.dv8tion.jda.core.entities.Guild)8 LocalDateTime (java.time.LocalDateTime)7 Gym (pokeraidbot.domain.gym.Gym)7 LocalTime (java.time.LocalTime)5 Test (org.junit.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 Transactional (org.springframework.transaction.annotation.Transactional)3 HashMap (java.util.HashMap)2 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)2 CSVGymDataReader (pokeraidbot.infrastructure.CSVGymDataReader)2 RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)2 SocketTimeoutException (java.net.SocketTimeoutException)1 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Locale (java.util.Locale)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1