use of toby.jpa.dto.ConfigDto in project toby-bot by ml404.
the class Handler method onGuildVoiceMove.
@Override
public void onGuildVoiceMove(GuildVoiceMoveEvent event) {
Guild guild = event.getGuild();
AudioManager audioManager = guild.getAudioManager();
String volumePropertyName = ConfigDto.Configurations.VOLUME.getConfigValue();
ConfigDto databaseConfig = configService.getConfigByName(volumePropertyName, event.getGuild().getId());
int defaultVolume = databaseConfig != null ? Integer.parseInt(databaseConfig.getValue()) : 100;
List<Member> nonBotConnectedMembersInOldChannel = event.getChannelLeft().getMembers().stream().filter(member -> !member.getUser().isBot()).collect(Collectors.toList());
if (Objects.equals(audioManager.getConnectedChannel(), event.getChannelLeft()) && nonBotConnectedMembersInOldChannel.isEmpty()) {
closeAudioPlayer(guild, audioManager, defaultVolume);
}
List<Member> nonBotConnectedMembers = event.getChannelJoined().getMembers().stream().filter(member -> !member.getUser().isBot()).collect(Collectors.toList());
if (!nonBotConnectedMembers.isEmpty() && !audioManager.isConnected()) {
PlayerManager.getInstance().getMusicManager(guild).getAudioPlayer().setVolume(defaultVolume);
audioManager.openAudioConnection(event.getChannelJoined());
}
}
use of toby.jpa.dto.ConfigDto in project toby-bot by ml404.
the class Handler method onGuildVoiceJoin.
// Auto joining voice channel when it becomes occupied and an audio connection doesn't already exist on the server, then play the associated user's intro song
@Override
public void onGuildVoiceJoin(GuildVoiceJoinEvent event) {
Guild guild = event.getGuild();
AudioManager audioManager = guild.getAudioManager();
String volumePropertyName = ConfigDto.Configurations.VOLUME.getConfigValue();
ConfigDto databaseVolumeConfig = configService.getConfigByName(volumePropertyName, event.getGuild().getId());
ConfigDto deleteDelayConfig = configService.getConfigByName(ConfigDto.Configurations.DELETE_DELAY.getConfigValue(), event.getGuild().getId());
int defaultVolume = databaseVolumeConfig != null ? Integer.parseInt(databaseVolumeConfig.getValue()) : 100;
List<Member> nonBotConnectedMembers = event.getChannelJoined().getMembers().stream().filter(member -> !member.getUser().isBot()).collect(Collectors.toList());
AudioPlayer audioPlayer = PlayerManager.getInstance().getMusicManager(guild).getAudioPlayer();
if (!nonBotConnectedMembers.isEmpty() && !audioManager.isConnected()) {
audioPlayer.setVolume(defaultVolume);
audioManager.openAudioConnection(event.getChannelJoined());
}
Member member = event.getMember();
long discordId = member.getUser().getIdLong();
long guildId = member.getGuild().getIdLong();
UserDto userDto = userService.getUserById(discordId, guildId);
if (Objects.equals(audioManager.getConnectedChannel(), event.getChannelJoined())) {
playUserIntro(userDto, guild, guild.getDefaultChannel(), Integer.parseInt(deleteDelayConfig.getValue()));
}
}
use of toby.jpa.dto.ConfigDto in project toby-bot by ml404.
the class LeaveCommand method handle.
@Override
public void handle(CommandContext ctx, String prefix, UserDto requestingUserDto, Integer deleteDelay) {
ICommand.deleteAfter(ctx.getMessage(), deleteDelay);
final TextChannel channel = ctx.getChannel();
final Member self = ctx.getSelfMember();
final GuildVoiceState selfVoiceState = self.getVoiceState();
if (!requestingUserDto.hasMusicPermission()) {
sendErrorMessage(ctx, channel, deleteDelay);
return;
}
if (!selfVoiceState.inVoiceChannel()) {
channel.sendMessage("I'm not in a voice channel, somebody shoot this guy").queue(message -> ICommand.deleteAfter(message, deleteDelay));
return;
}
final Member member = ctx.getMember();
final GuildVoiceState memberVoiceState = member.getVoiceState();
Guild guild = ctx.getGuild();
final AudioManager audioManager = guild.getAudioManager();
final VoiceChannel memberChannel = memberVoiceState.getChannel();
GuildMusicManager musicManager = PlayerManager.getInstance().getMusicManager(guild);
if (PlayerManager.getInstance().isCurrentlyStoppable() || member.hasPermission(Permission.KICK_MEMBERS)) {
String volumePropertyName = ConfigDto.Configurations.VOLUME.getConfigValue();
ConfigDto databaseConfig = configService.getConfigByName(volumePropertyName, ctx.getGuild().getId());
int defaultVolume = databaseConfig != null ? Integer.parseInt(databaseConfig.getValue()) : 100;
musicManager.getScheduler().setLooping(false);
musicManager.getScheduler().getQueue().clear();
musicManager.getAudioPlayer().stopTrack();
musicManager.getAudioPlayer().setVolume(defaultVolume);
audioManager.closeAudioConnection();
channel.sendMessageFormat("Disconnecting from `\uD83D\uDD0A %s`", memberChannel.getName()).queue(message -> ICommand.deleteAfter(message, deleteDelay));
} else {
sendDeniedStoppableMessage(channel, musicManager, deleteDelay);
}
}
use of toby.jpa.dto.ConfigDto in project toby-bot by ml404.
the class ConfigServiceImplIntegrationTest method testUpdate_thenNewConfigShouldBeReturned.
@Test
public void testUpdate_thenNewConfigShouldBeReturned() {
ConfigDto configDto = new ConfigDto("TOKEN", "1234", "test");
configService.createNewConfig(configDto);
ConfigDto dbConfig1 = configService.getConfigByName(configDto.getName(), configDto.getGuildId());
ConfigDto configDtoUpdated = new ConfigDto("TOKEN", "12345", "test");
configService.updateConfig(configDtoUpdated);
ConfigDto dbConfig2 = configService.getConfigByName(configDto.getName(), configDto.getGuildId());
int configSize = configService.listGuildConfig("test").size();
assertEquals(dbConfig1.getName(), configDto.getName());
assertEquals(dbConfig1.getGuildId(), configDto.getGuildId());
assertEquals(dbConfig2.getName(), configDtoUpdated.getName());
assertEquals(dbConfig2.getGuildId(), configDtoUpdated.getGuildId());
assertEquals(1, configSize);
}
use of toby.jpa.dto.ConfigDto in project toby-bot by ml404.
the class ConfigServiceImplIntegrationTest method whenValidNameAndGuild_thenConfigShouldBeFound.
@Test
public void whenValidNameAndGuild_thenConfigShouldBeFound() {
ConfigDto configDto = new ConfigDto("TOKEN", "1234", "test");
configService.createNewConfig(configDto);
ConfigDto dbConfig = configService.getConfigByName(configDto.getName(), configDto.getGuildId());
assertEquals(dbConfig.getName(), configDto.getName());
assertEquals(dbConfig.getGuildId(), configDto.getGuildId());
}
Aggregations