use of toby.jpa.dto.MusicDto in project toby-bot by ml404.
the class IntroSongCommand method persistMusicUrl.
private void persistMusicUrl(UserDto targetDto, Integer deleteDelay, TextChannel channel, String filename, String url, String memberName, int introVolume) {
MusicDto musicFileDto = targetDto.getMusicDto();
byte[] urlBytes = url.getBytes();
if (musicFileDto == null) {
MusicDto musicDto = new MusicDto(targetDto.getDiscordId(), targetDto.getGuildId(), filename, introVolume, urlBytes);
musicFileService.createNewMusicFile(musicDto);
targetDto.setMusicDto(musicDto);
userService.updateUser(targetDto);
channel.sendMessageFormat("Successfully set %s's intro song to '%s' with volume '%d'", memberName, musicDto.getFileName(), musicDto.getIntroVolume()).queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
musicFileDto.setFileName(filename);
musicFileDto.setIntroVolume(introVolume);
musicFileDto.setMusicBlob(urlBytes);
musicFileService.updateMusicFile(musicFileDto);
channel.sendMessageFormat("Successfully updated %s's intro song to '%s' with volume '%d'", memberName, filename, introVolume).queue(message -> ICommand.deleteAfter(message, deleteDelay));
}
use of toby.jpa.dto.MusicDto in project toby-bot by ml404.
the class IntroSongCommand method persistMusicFile.
private void persistMusicFile(UserDto targetDto, Integer deleteDelay, TextChannel channel, String filename, int introVolume, InputStream inputStream, String memberName) {
byte[] fileContents;
try {
fileContents = readInputStreamToByteArray(inputStream);
} catch (ExecutionException | InterruptedException | IOException e) {
channel.sendMessageFormat("Unable to read file '%s'", filename).queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
MusicDto musicFileDto = targetDto.getMusicDto();
if (musicFileDto == null) {
MusicDto musicDto = new MusicDto(targetDto.getDiscordId(), targetDto.getGuildId(), filename, introVolume, fileContents);
musicFileService.createNewMusicFile(musicDto);
targetDto.setMusicDto(musicDto);
userService.updateUser(targetDto);
channel.sendMessageFormat("Successfully set %s's intro song to '%s' with volume '%d'", memberName, musicDto.getFileName(), musicDto.getIntroVolume()).queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
musicFileDto.setFileName(filename);
musicFileDto.setIntroVolume(introVolume);
musicFileDto.setMusicBlob(fileContents);
musicFileService.updateMusicFile(musicFileDto);
channel.sendMessageFormat("Successfully updated %s's intro song to '%s' with volume '%d'", memberName, filename, introVolume).queue(message -> ICommand.deleteAfter(message, deleteDelay));
}
use of toby.jpa.dto.MusicDto in project toby-bot by ml404.
the class MusicPlayerHelper method playUserIntro.
public static void playUserIntro(UserDto dbUser, Guild guild, TextChannel channel, int deleteDelay) {
MusicDto musicDto = dbUser.getMusicDto();
PlayerManager instance = PlayerManager.getInstance();
int currentVolume = PlayerManager.getInstance().getMusicManager(guild).getAudioPlayer().getVolume();
if (musicDto != null && musicDto.getFileName() != null) {
Integer introVolume = musicDto.getIntroVolume();
changeVolumeForIntro(channel, deleteDelay, currentVolume, introVolume);
PlayerManager.getInstance().getMusicManager(guild).getAudioPlayer().setVolume(introVolume != null ? introVolume : currentVolume);
instance.loadAndPlay(guild.getSystemChannel(), String.format(ConsumeWebService.getWebUrl() + "/music?id=%s", musicDto.getId()), true, 0);
} else if (musicDto != null) {
Integer introVolume = musicDto.getIntroVolume();
PlayerManager.getInstance().getMusicManager(guild).getAudioPlayer().setVolume(introVolume != null ? introVolume : currentVolume);
changeVolumeForIntro(channel, deleteDelay, currentVolume, introVolume);
instance.setPreviousVolume(currentVolume);
instance.loadAndPlay(guild.getSystemChannel(), Arrays.toString(dbUser.getMusicDto().getMusicBlob()), true, 0);
}
}
use of toby.jpa.dto.MusicDto in project toby-bot by ml404.
the class UserDtoHelper method calculateUserDto.
public static UserDto calculateUserDto(long guildId, long discordId, boolean isSuperUser, IUserService userService, int introVolume) {
Optional<UserDto> dbUserDto = userService.listGuildUsers(guildId).stream().filter(userDto -> userDto.getGuildId().equals(guildId) && userDto.getDiscordId().equals(discordId)).findFirst();
if (dbUserDto.isEmpty()) {
UserDto userDto = new UserDto();
userDto.setDiscordId(discordId);
userDto.setGuildId(guildId);
userDto.setSuperUser(isSuperUser);
MusicDto musicDto = new MusicDto(userDto.getDiscordId(), userDto.getGuildId(), null, introVolume, null);
userDto.setMusicDto(musicDto);
return userService.createNewUser(userDto);
}
return userService.getUserById(discordId, guildId);
}
use of toby.jpa.dto.MusicDto in project toby-bot by ml404.
the class MusicFilePersistenceImpl method getMusicFileById.
@Override
public MusicDto getMusicFileById(String id) {
Query q = em.createNamedQuery("MusicDto.getById", MusicDto.class);
q.setParameter("id", id);
return (MusicDto) q.getSingleResult();
}
Aggregations