Search in sources :

Example 1 with GuildVoiceJoinEvent

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()));
    }
}
Also used : AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) net.dv8tion.jda.api.entities(net.dv8tion.jda.api.entities) MusicPlayerHelper.playUserIntro(toby.helpers.MusicPlayerHelper.playUserIntro) JDA(net.dv8tion.jda.api.JDA) BotMain(toby.BotMain) UserDto(toby.jpa.dto.UserDto) AudioManager(net.dv8tion.jda.api.managers.AudioManager) LoggerFactory(org.slf4j.LoggerFactory) Configurable(org.springframework.beans.factory.annotation.Configurable) Autowired(org.springframework.beans.factory.annotation.Autowired) GuildVoiceLeaveEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent) EventWaiter(com.jagrosh.jdautilities.commons.waiter.EventWaiter) ReadyEvent(net.dv8tion.jda.api.events.ReadyEvent) ConfigDto(toby.jpa.dto.ConfigDto) Service(org.springframework.stereotype.Service) Nonnull(javax.annotation.Nonnull) GuildMessageReceivedEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent) Logger(org.slf4j.Logger) Emotes(toby.emote.Emotes) GuildVoiceMoveEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent) ListenerAdapter(net.dv8tion.jda.api.hooks.ListenerAdapter) GuildMusicManager(toby.lavaplayer.GuildMusicManager) CommandManager(toby.managers.CommandManager) Collectors(java.util.stream.Collectors) PlayerManager(toby.lavaplayer.PlayerManager) Objects(java.util.Objects) toby.jpa.service(toby.jpa.service) GuildVoiceJoinEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent) List(java.util.List) MessageReceivedEvent(net.dv8tion.jda.api.events.message.MessageReceivedEvent) AudioManager(net.dv8tion.jda.api.managers.AudioManager) ConfigDto(toby.jpa.dto.ConfigDto) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) UserDto(toby.jpa.dto.UserDto)

Example 2 with GuildVoiceJoinEvent

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;
    }
}
Also used : GuildBanEvent(net.dv8tion.jda.api.events.guild.GuildBanEvent) GuildVoiceJoinEvent(net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent) GuildMemberJoinEvent(net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent) GuildMessageDeleteEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent) MessageBulkDeleteEvent(net.dv8tion.jda.api.events.message.MessageBulkDeleteEvent) GuildMemberLeaveEvent(net.dv8tion.jda.api.events.guild.member.GuildMemberLeaveEvent) GuildMessageUpdateEvent(net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent)

Aggregations

GuildVoiceJoinEvent (net.dv8tion.jda.api.events.guild.voice.GuildVoiceJoinEvent)2 EventWaiter (com.jagrosh.jdautilities.commons.waiter.EventWaiter)1 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 JDA (net.dv8tion.jda.api.JDA)1 net.dv8tion.jda.api.entities (net.dv8tion.jda.api.entities)1 ReadyEvent (net.dv8tion.jda.api.events.ReadyEvent)1 GuildBanEvent (net.dv8tion.jda.api.events.guild.GuildBanEvent)1 GuildMemberJoinEvent (net.dv8tion.jda.api.events.guild.member.GuildMemberJoinEvent)1 GuildMemberLeaveEvent (net.dv8tion.jda.api.events.guild.member.GuildMemberLeaveEvent)1 GuildVoiceLeaveEvent (net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent)1 GuildVoiceMoveEvent (net.dv8tion.jda.api.events.guild.voice.GuildVoiceMoveEvent)1 MessageBulkDeleteEvent (net.dv8tion.jda.api.events.message.MessageBulkDeleteEvent)1 MessageReceivedEvent (net.dv8tion.jda.api.events.message.MessageReceivedEvent)1 GuildMessageDeleteEvent (net.dv8tion.jda.api.events.message.guild.GuildMessageDeleteEvent)1 GuildMessageReceivedEvent (net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent)1 GuildMessageUpdateEvent (net.dv8tion.jda.api.events.message.guild.GuildMessageUpdateEvent)1