Search in sources :

Example 6 with SignUp

use of pokeraidbot.domain.raid.signup.SignUp 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));
}
Also used : LocalDateTime(java.time.LocalDateTime) SignUp(pokeraidbot.domain.raid.signup.SignUp) User(net.dv8tion.jda.core.entities.User) LocalTime(java.time.LocalTime) Config(pokeraidbot.infrastructure.jpa.config.Config) ArrayList(java.util.ArrayList) Guild(net.dv8tion.jda.core.entities.Guild) RaidEntity(pokeraidbot.infrastructure.jpa.raid.RaidEntity) Gym(pokeraidbot.domain.gym.Gym) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with SignUp

use of pokeraidbot.domain.raid.signup.SignUp in project pokeraidbot by magnusmickelsson.

the class RaidRepository method executeUnsignCommand.

public String executeUnsignCommand(Config config, User user, Locale localeForUser, String[] args, String help) {
    String people = args[0];
    String userName = user.getName();
    if (args.length < 2 || args.length > 10) {
        throw new WrongNumberOfArgumentsException(user, localeService, 2, args.length, help);
    }
    Integer numberOfPeople = Utils.assertNotTooManyOrNoNumber(user, localeService, people);
    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());
    Raid raid = getActiveRaidOrFallbackToExRaid(gym, config.getRegion(), user);
    final RaidEntitySignUp signUp = findEntityByRaidId(raid.getId()).getSignUp(user.getName());
    if (signUp == null) {
        throw new UserMessedUpException(user, localeService.getMessageFor(LocaleService.NO_SIGNUP_AT_GYM, localeForUser, user.getName(), gym.getName()));
    }
    raid = removeFromSignUp(raid.getId(), user, 0, 0, 0, numberOfPeople, LocalDateTime.of(raid.getEndOfRaid().toLocalDate(), signUp.getArrivalTime()));
    final String currentSignupText = localeService.getMessageFor(LocaleService.CURRENT_SIGNUPS, localeForUser);
    final Set<SignUp> signUps = raid.getSignUps();
    Set<String> signUpNames = Utils.getNamesOfThoseWithSignUps(signUps, true);
    final String allSignUpNames = StringUtils.join(signUpNames, ", ");
    final String signUpText = raid.getSignUps().size() > 1 ? currentSignupText + "\n" + allSignUpNames : "";
    return localeService.getMessageFor(LocaleService.UNSIGN, localeForUser, userName, gym.getName(), signUpText);
}
Also used : RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) SignUp(pokeraidbot.domain.raid.signup.SignUp) WrongNumberOfArgumentsException(pokeraidbot.domain.errors.WrongNumberOfArgumentsException) RaidEntitySignUp(pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp) UserMessedUpException(pokeraidbot.domain.errors.UserMessedUpException) Gym(pokeraidbot.domain.gym.Gym)

Example 8 with SignUp

use of pokeraidbot.domain.raid.signup.SignUp in project pokeraidbot by magnusmickelsson.

the class Raid method signUp.

public void signUp(User user, int howManyPeople, LocalTime arrivalTime, RaidRepository repository) {
    SignUp signUp = signUps.get(user.getName());
    if (signUp != null) {
        int numberOfPeopleInSignup = signUp.getHowManyPeople();
        if (arrivalTime.equals(signUp.getArrivalTime())) {
            numberOfPeopleInSignup += howManyPeople;
        } else {
            numberOfPeopleInSignup = howManyPeople;
            signUp.setEta(arrivalTime);
        }
        Utils.assertNotTooManyOrNoNumber(user, localeService, String.valueOf(numberOfPeopleInSignup));
        signUp.setHowManyPeople(numberOfPeopleInSignup);
    } else {
        signUp = new SignUp(user.getName(), howManyPeople, arrivalTime);
        signUps.put(user.getName(), signUp);
    }
    repository.addSignUp(user, this, signUp);
}
Also used : SignUp(pokeraidbot.domain.raid.signup.SignUp)

Example 9 with SignUp

use of pokeraidbot.domain.raid.signup.SignUp 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

SignUp (pokeraidbot.domain.raid.signup.SignUp)9 Gym (pokeraidbot.domain.gym.Gym)6 LocalDateTime (java.time.LocalDateTime)3 User (net.dv8tion.jda.core.entities.User)3 Raid (pokeraidbot.domain.raid.Raid)3 RaidEntitySignUp (pokeraidbot.infrastructure.jpa.raid.RaidEntitySignUp)3 LocalTime (java.time.LocalTime)2 Locale (java.util.Locale)2 EmbedBuilder (net.dv8tion.jda.core.EmbedBuilder)2 MessageEmbed (net.dv8tion.jda.core.entities.MessageEmbed)2 UserMessedUpException (pokeraidbot.domain.errors.UserMessedUpException)2 WrongNumberOfArgumentsException (pokeraidbot.domain.errors.WrongNumberOfArgumentsException)2 Pokemon (pokeraidbot.domain.pokemon.Pokemon)2 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Guild (net.dv8tion.jda.core.entities.Guild)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Transactional (org.springframework.transaction.annotation.Transactional)1 Config (pokeraidbot.infrastructure.jpa.config.Config)1