Yucked/Victoria

[ BUG ] Some video make Victoria throw a silent exception, making all event not tigger anymore

v0fbu1vm opened this issue · 1 comments


Describe the bug/issue.

When I'm trying to play or skip a track, I keep getting this error. Check below!
Here is how my Program.cs looks like. It contains the configuration.

DotNetEnv.Env.Load();
var host = Host.CreateDefaultBuilder()
    .ConfigureDiscordHost((_, config) =>
    {
        config.SocketConfig = new DiscordSocketConfig
        {
            LogLevel = LogSeverity.Verbose,
            GatewayIntents = GatewayIntents.All,
            AlwaysDownloadUsers = true,
            MessageCacheSize = 1000,
            LogGatewayIntentWarnings = false,
        };

        config.Token = Environment.GetEnvironmentVariable("DISCORD_TOKEN") ?? string.Empty;
    })
    .UseInteractionService((_, config) =>
    {
        config.LogLevel = LogSeverity.Info;
        config.UseCompiledLambda = true;
        config.DefaultRunMode = Discord.Interactions.RunMode.Async;
    })
    .ConfigureServices((_, services) =>
    {
        services.AddLavaNode(x =>
        {
            x.SelfDeaf = true;
            x.SocketConfiguration = new WebSocketConfiguration
            {
                BufferSize = UInt16.MaxValue
            };
        });
        services.AddSingleton<JokeService>();
        services.AddSingleton<MemeService>();
        services.AddSingleton<MusicService>();
        services.AddHostedService<InteractionHandler>();
        services.AddHostedService<BotStatusService>();
    }).Build();

await host.RunAsync();

Here is the Play command

[SlashCommand("play", "I will play whatever you like babe 🤘🏻.")]
    public async Task PlayAsync([Remainder] string searchQuery)
    {
        if (string.IsNullOrWhiteSpace(searchQuery))
        {
            await RespondAsync("Please provide search terms.");
            return;
        }

        if (!_service.LavaNode.TryGetPlayer(Context.Guild, out var player))
        {
            var voiceState = Context.User as IVoiceState;
            if (voiceState?.VoiceChannel == null)
            {
                await RespondAsync("You must be connected to a voice channel!");
                return;
            }

            try
            {
                player = await _service.LavaNode.JoinAsync(voiceState.VoiceChannel, Context.Channel as ITextChannel);
            }
            catch (Exception exception)
            {
                await RespondAsync(exception.Message);
            }
        }

        try
        {
            var searchResponse = await _service.LavaNode.SearchAsync(Uri.TryCreate(searchQuery, UriKind.Absolute, out _) ? SearchType.Direct : SearchType.YouTube, searchQuery);
            if (searchResponse.Status is SearchStatus.LoadFailed or SearchStatus.NoMatches)
            {
                await RespondAsync($"I wasn't able to find anything for `{searchQuery}`.");
                return;
            }

            if (!string.IsNullOrWhiteSpace(searchResponse.Playlist.Name))
            {
                player.Vueue.Enqueue(searchResponse.Tracks);
                await RespondAsync($"Enqueued `{searchResponse.Tracks.Count}` songs.");
            }
            else
            {
                var track = searchResponse.Tracks.FirstOrDefault();
                player.Vueue.Enqueue(track);

                await RespondAsync($"Enqueued `{track?.Title}`.");
            }

            if (player.PlayerState is PlayerState.Playing or PlayerState.Paused)
            {
                return;
            }

            player.Vueue.TryDequeue(out var lavaTrack);
            await player.PlayAsync(lavaTrack);
        }
        catch (Exception) { }
    }

Here is the Skip command

[SlashCommand("skip", "I will skip the currently playing track ⏩.")]
    public async Task SkipAsync()
    {
        if (!_service.LavaNode.TryGetPlayer(Context.Guild, out var player))
        {
            await RespondAsync("I'm not connected to a voice channel.");
            return;
        }

        if (player.PlayerState != PlayerState.Playing)
        {
            await RespondAsync("Woaaah there, I can't skip when nothing is playing.");
            return;
        }

        try
        {
            var (oldTrack, currenTrack) = await player.SkipAsync();
            await RespondAsync($"Skipped `{oldTrack.Title}`.");
        }
        catch (Exception exception)
        {
            await RespondAsync(exception.Message);
        }
    }

Even after changing the buffer size it doesn't seem to have any effect!
Any help would be appreciated?
Sincerely

Stacktrace / Screenshots

When debugging yourself, you can attach screenshots of Autos/Locals tabs in Visual Studio.
Screenshot 2023-03-14 200204

@Yucked
I believe the issue is from here:

private async Task ReceiveAsync() {

The finalBuffer variable is used to hold data that hasn't been fully received yet. But there's a potential bug: when the finalBuffer needs to be resized, the current data in buffer isn't taken into account. So, when copying buffer into finalBuffer, it's not starting at the right index. This means that data could get overwritten, which would cause problems. The code needs to calculate the correct starting index based on the existing data in both buffer and finalBuffer.

Does this make any sense?
Sincerely!