Search in sources :

Example 11 with MusicDto

use of toby.jpa.dto.MusicDto in project toby-bot by ml404.

the class UserServiceImplIntegrationTest method whenValidDiscordIdAndGuild_thenUserShouldBeFound.

@Test
public void whenValidDiscordIdAndGuild_thenUserShouldBeFound() {
    UserDto userDto = new UserDto();
    userDto.setDiscordId(1L);
    userDto.setGuildId(1L);
    MusicDto musicDto = new MusicDto(userDto.getDiscordId(), userDto.getGuildId(), null, 0, null);
    userDto.setMusicDto(musicDto);
    userService.createNewUser(userDto);
    UserDto dbUser = userService.getUserById(userDto.getDiscordId(), userDto.getGuildId());
    assertEquals(dbUser.getDiscordId(), userDto.getDiscordId());
    assertEquals(dbUser.getGuildId(), userDto.getGuildId());
    assertTrue(dbUser.hasMusicPermission());
    assertTrue(dbUser.hasMemePermission());
    assertTrue(dbUser.hasDigPermission());
    assertFalse(dbUser.isSuperUser());
    assertNotNull(dbUser.getMusicDto());
}
Also used : UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with MusicDto

use of toby.jpa.dto.MusicDto in project toby-bot by ml404.

the class UserServiceImplIntegrationTest method whenMusicFileExistsWithSameDiscordIdAndGuild_thenUserShouldBeFoundWithMusicFile.

@Test
public void whenMusicFileExistsWithSameDiscordIdAndGuild_thenUserShouldBeFoundWithMusicFile() {
    UserDto userDto = new UserDto();
    userDto.setDiscordId(1L);
    userDto.setGuildId(1L);
    MusicDto musicDto = new MusicDto(userDto.getDiscordId(), userDto.getGuildId(), "test", 0, null);
    userDto.setMusicDto(musicDto);
    userService.createNewUser(userDto);
    UserDto dbUser = userService.getUserById(userDto.getDiscordId(), userDto.getGuildId());
    assertEquals(dbUser.getDiscordId(), userDto.getDiscordId());
    assertEquals(dbUser.getGuildId(), userDto.getGuildId());
    assertTrue(dbUser.hasMusicPermission());
    assertTrue(dbUser.hasMemePermission());
    assertTrue(dbUser.hasDigPermission());
    assertFalse(dbUser.isSuperUser());
    MusicDto dbMusicFileDto = userDto.getMusicDto();
    assertNotNull(dbMusicFileDto);
    assertEquals(dbMusicFileDto.getId(), musicDto.getId());
    assertEquals(dbMusicFileDto.getFileName(), musicDto.getFileName());
}
Also used : UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with MusicDto

use of toby.jpa.dto.MusicDto in project toby-bot by ml404.

the class UserPersistenceImpl method updateUser.

@Override
public UserDto updateUser(UserDto userDto) {
    UserDto dbUser = getUserById(userDto.getDiscordId(), userDto.getGuildId());
    MusicDto musicFileById = musicFileService.getMusicFileById(userDto.getMusicDto().getId());
    MusicDto requestMusicDto = dbUser.getMusicDto();
    if (!requestMusicDto.equals(musicFileById)) {
        musicFileService.updateMusicFile(requestMusicDto);
    }
    if (!userDto.equals(dbUser)) {
        em.merge(userDto);
        em.flush();
    }
    return userDto;
}
Also used : UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto)

Example 14 with MusicDto

use of toby.jpa.dto.MusicDto in project toby-bot by ml404.

the class UserInfoCommand method printUserInfo.

private void printUserInfo(TextChannel channel, Message message, UserDto requestingUserDto, Integer deleteDelay) {
    if (message.getMentionedMembers().isEmpty()) {
        if (requestingUserDto != null) {
            channel.sendMessage(String.format("Here are your permissions: '%s'.", requestingUserDto)).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
            MusicDto musicDto = requestingUserDto.getMusicDto();
            if (musicDto != null) {
                if (musicDto.getFileName() == null || musicDto.getFileName().isBlank()) {
                    channel.sendMessage("There is no intro music file associated with your user.").queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
                } else if (musicDto.getFileName() != null) {
                    channel.sendMessage(String.format("Your intro song is currently set as: '%s'.", musicDto.getFileName())).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
                }
            } else
                channel.sendMessage("I was unable to retrieve your music file.").queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
        }
    } else {
        if (requestingUserDto.isSuperUser()) {
            message.getMentionedMembers().forEach(member -> {
                UserDto mentionedUser = userService.getUserById(member.getIdLong(), member.getGuild().getIdLong());
                channel.sendMessageFormat("Here are the permissions for '%s': '%s'.", member.getEffectiveName(), mentionedUser).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
                MusicDto musicDto = mentionedUser.getMusicDto();
                if (musicDto != null) {
                    if (musicDto.getFileName() == null || musicDto.getFileName().isBlank()) {
                        channel.sendMessageFormat("There is no intro music file associated with '%s'.", member.getEffectiveName()).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
                    } else if (musicDto.getFileName() != null) {
                        channel.sendMessage(String.format("Their intro song is currently set as: '%s'.", musicDto.getFileName())).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
                    }
                } else
                    channel.sendMessageFormat("I was unable to retrieve an associated music file for '%s'.", member.getNickname()).queue(message1 -> ICommand.deleteAfter(message1, deleteDelay));
            });
        } else
            channel.sendMessage("You do not have permission to view user permissions, if this is a mistake talk to the server owner").queue();
    }
}
Also used : Message(net.dv8tion.jda.api.entities.Message) CommandContext(toby.command.CommandContext) Arrays(java.util.Arrays) List(java.util.List) UserDto(toby.jpa.dto.UserDto) ICommand(toby.command.ICommand) TextChannel(net.dv8tion.jda.api.entities.TextChannel) IUserService(toby.jpa.service.IUserService) MusicDto(toby.jpa.dto.MusicDto) UserDto(toby.jpa.dto.UserDto) MusicDto(toby.jpa.dto.MusicDto)

Aggregations

MusicDto (toby.jpa.dto.MusicDto)14 UserDto (toby.jpa.dto.UserDto)8 Test (org.junit.jupiter.api.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 IUserService (toby.jpa.service.IUserService)3 Arrays (java.util.Arrays)2 List (java.util.List)2 Message (net.dv8tion.jda.api.entities.Message)2 TextChannel (net.dv8tion.jda.api.entities.TextChannel)2 CommandContext (toby.command.CommandContext)2 ICommand (toby.command.ICommand)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URI (java.net.URI)1 URL (java.net.URL)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 Collectors (java.util.stream.Collectors)1 Query (javax.persistence.Query)1