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());
}
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());
}
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;
}
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();
}
}
Aggregations