Exemplo n.º 1
0
        private async Task UserVoiceAnnounceAsync(SocketUser user, SocketVoiceState beforeVoiceState,
                                                  SocketVoiceState afterVoiceState)
        {
            if (!(user is SocketGuildUser guildUser))
            {
                return;
            }
            var guild  = guildUser.Guild;
            var record = await _coreRepository.GetOrCreateActivityAsync(guild).ConfigureAwait(false);

            if (!record.ShouldLogVoice)
            {
                return;
            }
            var logChannel = guild.GetTextChannel(record.LogChannel);

            if (logChannel == null)
            {
                return;
            }
            var embed = new EmbedBuilder
            {
                Author = new EmbedAuthorBuilder
                {
                    IconUrl = user.GetAvatarUrlOrDefault()
                }
            };

            if (afterVoiceState.VoiceChannel != null && beforeVoiceState.VoiceChannel == null)
            {
                embed.Color       = Color.Blue;
                embed.Title       = "Voice Joined";
                embed.Description = $"{user} ({user.Id}) joined {Format.Bold(afterVoiceState.VoiceChannel?.Name)}!";
                await logChannel.SendMessageAsync("", embed : embed.Build()).ConfigureAwait(false);

                return;
            }
            if (beforeVoiceState.VoiceChannel != null && afterVoiceState.VoiceChannel == null)
            {
                embed.Color       = Color.Orange;
                embed.Title       = "Voice Left";
                embed.Description = $"{user} ({user.Id}) left {Format.Bold(beforeVoiceState.VoiceChannel?.Name)}!";
                await logChannel.SendMessageAsync("", embed : embed.Build()).ConfigureAwait(false);

                return;
            }
            if (afterVoiceState.VoiceChannel != null && beforeVoiceState.VoiceChannel != null)
            {
                embed.Color       = Color.DarkerGrey;
                embed.Title       = "Voice Changed Channel";
                embed.Description =
                    $"{user} ({user.Id}) moved from {Format.Bold(beforeVoiceState.VoiceChannel?.Name)} to {Format.Bold(afterVoiceState.VoiceChannel?.Name)}!";
                await logChannel.SendMessageAsync("", embed : embed.Build()).ConfigureAwait(false);
            }
        }