Search in sources :

Example 6 with RaidGroup

use of pokeraidbot.infrastructure.jpa.raid.RaidGroup in project pokeraidbot by magnusmickelsson.

the class StartUpEventListener method onEvent.

@Override
public void onEvent(Event event) {
    if (event instanceof ReadyEvent) {
        final List<Guild> guilds = event.getJDA().getGuilds();
        for (Guild guild : guilds) {
            Config config = serverConfigRepository.getConfigForServer(guild.getName().trim().toLowerCase());
            if (config != null) {
                final String messageId = config.getOverviewMessageId();
                if (!StringUtils.isEmpty(messageId)) {
                    for (MessageChannel channel : guild.getTextChannels()) {
                        if (attachToOverviewMessageIfExists(guild, config, messageId, channel, pokemonRaidStrategyService)) {
                            break;
                        } else {
                            if (LOGGER.isDebugEnabled()) {
                                LOGGER.debug("Didn't find overview in channel " + channel.getName());
                            }
                        }
                    }
                }
                final List<RaidGroup> groupsForServer = raidRepository.getGroupsForServer(config.getServer());
                for (RaidGroup group : groupsForServer) {
                    attachToGroupMessage(guild, config, group);
                }
            }
        }
    }
}
Also used : ReadyEvent(net.dv8tion.jda.core.events.ReadyEvent) MessageChannel(net.dv8tion.jda.core.entities.MessageChannel) Config(pokeraidbot.infrastructure.jpa.config.Config) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) Guild(net.dv8tion.jda.core.entities.Guild)

Example 7 with RaidGroup

use of pokeraidbot.infrastructure.jpa.raid.RaidGroup 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 8 with RaidGroup

use of pokeraidbot.infrastructure.jpa.raid.RaidGroup in project pokeraidbot by magnusmickelsson.

the class RaidEntityRepositoryTest method createWithGroup.

@Test
public void createWithGroup() throws Exception {
    final String id = "id1";
    RaidEntity raidEntity = new RaidEntity(id, "Mupp", LocalDateTime.now().plusMinutes(20), "Thegym", "Theuser", "Theregion");
    final RaidGroup group = new RaidGroup("testserver", "channel", "abc1", "abc2", "testId", LocalDateTime.now().plusMinutes(10));
    assertThat(raidEntity.addGroup(group), is(true));
    raidEntity = entityRepository.save(raidEntity);
    final RaidEntity loaded = entityRepository.findOne(id);
    assertThat(loaded, is(raidEntity));
    final Set<RaidGroup> groups = loaded.getGroupsAsSet();
    assertThat(groups.size(), is(1));
    assertThat(groups.iterator().next(), is(group));
    final List<RaidGroup> groupsForServer = entityRepository.findGroupsForServer("testserver");
    assertThat(groupsForServer.size(), is(1));
    assertThat(groupsForServer.iterator().next(), is(group));
}
Also used : RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with RaidGroup

use of pokeraidbot.infrastructure.jpa.raid.RaidGroup in project pokeraidbot by magnusmickelsson.

the class RaidRepository method listGroupsForRaid.

public String listGroupsForRaid(Raid raid, Set<RaidGroup> groups) {
    StringBuilder sb = new StringBuilder();
    if (groups.size() > 0) {
        sb.append(" " + Emotes.GROUP + " ");
        Set<String> times = new LinkedHashSet<>();
        int signUpsInGroups = 0;
        for (RaidGroup group : groups) {
            final LocalTime groupTime = group.getStartsAt().toLocalTime();
            final int numberOfPeopleInGroup = countSignups(raid.getSignUpsAt(groupTime));
            times.add(printTime(groupTime) + " (**" + numberOfPeopleInGroup + "**)");
            signUpsInGroups += numberOfPeopleInGroup;
        }
        sb.append(StringUtils.join(times, ", "));
        RaidEntity entity = findEntityByRaidId(raid.getId());
        final Set<RaidEntitySignUp> signUpsAsSet = entity.getSignUpsAsSet();
        final long totalSignUps = signUpsAsSet.stream().mapToInt(RaidEntitySignUp::getNumberOfPeople).sum();
        if (totalSignUps > signUpsInGroups) {
            sb.append(", -:- (**").append(totalSignUps - signUpsInGroups).append("**)");
        }
    }
    return sb.toString();
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) LocalTime(java.time.LocalTime) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity)

Example 10 with RaidGroup

use of pokeraidbot.infrastructure.jpa.raid.RaidGroup 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;
}
Also used : LocalDateTime(java.time.LocalDateTime) SignUp(pokeraidbot.domain.raid.signup.SignUp) MessageEmbed(net.dv8tion.jda.core.entities.MessageEmbed) Raid(pokeraidbot.domain.raid.Raid) EmbedBuilder(net.dv8tion.jda.core.EmbedBuilder) Gym(pokeraidbot.domain.gym.Gym) RaidGroup(pokeraidbot.infrastructure.jpa.raid.RaidGroup) Pokemon(pokeraidbot.domain.pokemon.Pokemon)

Aggregations

RaidGroup (pokeraidbot.infrastructure.jpa.raid.RaidGroup)15 Gym (pokeraidbot.domain.gym.Gym)6 Raid (pokeraidbot.domain.raid.Raid)6 LocalDateTime (java.time.LocalDateTime)5 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)5 RaidEntity (pokeraidbot.infrastructure.jpa.raid.RaidEntity)5 EmoticonSignUpMessageListener (pokeraidbot.domain.raid.signup.EmoticonSignUpMessageListener)4 LocalTime (java.time.LocalTime)3 MessageChannel (net.dv8tion.jda.core.entities.MessageChannel)3 Pokemon (pokeraidbot.domain.pokemon.Pokemon)3 Locale (java.util.Locale)2 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)2 Guild (net.dv8tion.jda.core.entities.Guild)2 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)2 User (net.dv8tion.jda.core.entities.User)2 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Config (pokeraidbot.infrastructure.jpa.config.Config)2 LocalDate (java.time.LocalDate)1 TimeUnit (java.util.concurrent.TimeUnit)1