use of net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent 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 net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent in project Gary by help-chat.
the class LoggingHandler method execute.
@Override
protected void execute(GenericEvent event) {
switch(EventsEnum.fromEvent(event)) {
case MEMBER_JOIN:
GuildMemberJoinEvent e = (GuildMemberJoinEvent) event;
log(EventsEnum.MEMBER_JOIN, e.getJDA(), e.getGuild(), e.getUser());
break;
case MEMBER_LEAVE:
if (!wasBan) {
GuildMemberLeaveEvent e2 = (GuildMemberLeaveEvent) event;
log(EventsEnum.MEMBER_LEAVE, e2.getJDA(), e2.getGuild(), e2.getUser());
} else {
wasBan = false;
}
break;
case MEMBER_BANNED:
wasBan = true;
GuildBanEvent e3 = (GuildBanEvent) event;
log(EventsEnum.MEMBER_BANNED, e3.getJDA(), e3.getGuild(), e3.getUser());
break;
case MESSAGE_EDIT:
GuildMessageUpdateEvent e5 = (GuildMessageUpdateEvent) event;
if (!e5.getAuthor().isBot() && StringUtils.equalsIgnoreCase(e5.getChannel().getName(), Constants.CHANNELS)) {
log(EventsEnum.MESSAGE_EDIT, e5.getJDA(), e5.getGuild(), e5.getAuthor(), e5.getChannel(), e5.getMessage());
}
break;
case MESSAGE_DELETE:
GuildMessageDeleteEvent e6 = (GuildMessageDeleteEvent) event;
if ((StringUtils.equalsIgnoreCase(e6.getChannel().getName(), Constants.CHANNELS))) {
log(EventsEnum.MESSAGE_DELETE, e6.getJDA(), e6.getGuild(), MessageUtils.getAuthor(e6.getMessageIdLong()), e6.getChannel(), e6.getMessageIdLong(), MessageUtils.getMessage(e6.getMessageIdLong()));
}
break;
case MESSAGE_BULK_DELETE:
MessageBulkDeleteEvent e7 = (MessageBulkDeleteEvent) event;
if ((StringUtils.equalsIgnoreCase(e7.getChannel().getName(), Constants.CHANNELS))) {
log(EventsEnum.MESSAGE_BULK_DELETE, e7.getJDA(), e7.getGuild(), e7.getChannel(), e7.getMessageIds());
}
break;
case VOICE_JOIN:
GuildVoiceJoinEvent e8 = (GuildVoiceJoinEvent) event;
log(EventsEnum.VOICE_JOIN, e8.getJDA(), e8.getGuild(), e8.getMember().getUser(), e8.getChannelJoined());
break;
}
}
Aggregations