Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance queue management and interaction response #617

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hqtruong27
Copy link
Contributor

Description

  • Introduced a new EditResponseAsync method for string content.
  • Created DefaultQueueEntry class for track playback handling.
  • Updated LavalinkConfiguration with a customizable QueueEntryFactory.
  • Refactored LavalinkGuildPlayer to utilize a static QueueInternal for guild-specific queues.
  • Deprecated the QueueEntries property in favor of the new Queue property.
  • Implemented a new thread-safe LavalinkQueue<T> class for queue operations.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • interaction response:
    I really like the short, not too long way of writing.
    The EditResponseAsync method is used a lot and I think the input is mainly a content, so I added a method input which is string content, hope you agree.
  • queue management
    tested the queue part with 3 servers and they work fine (only manual test, no automation test and code test).
  • queue entry
    In case the user only wants to use Queue(EnableBuiltInQueueSystem = true) and does not want to use pipeline queue entry
    a transient pipeline DefaultQueueEntry will be used.
    If they want to use it, just sets a QueueEntryFactory function that creates queue entry objects.
    We can use QueueEntryFactory with DI
public record QueueEntryFactory(IEventPublisher publisher) : IQueueEntry
{
    public LavalinkTrack Track { get; set; } = default!;

    public async Task AfterPlayingAsync(LavalinkGuildPlayer player)
    {
        await player.Channel.SendMessageAsync($"Track ended: {Track.Info.Title}-{player.Guild.Name}");
    }

    public async Task<bool> BeforePlayingAsync(LavalinkGuildPlayer player)
    {
        await player.Channel.SendMessageAsync($"Track Started: {Track.Info.Title}-{player.Guild.Name}");
        await publisher.PublishAsync(new TrackStarted());

        return await Task.FromResult(true);
    }
}
 services.AddTransient<IQueueEntry, Features.Tracks.Interactions.QueueEntryFactory>();
 await lavalink.ConnectAsync(new LavalinkConfiguration()
 {
     Password = options.Password,
     RestEndpoint = endpoint,
     SocketEndpoint = endpoint,
     EnableBuiltInQueueSystem = true,
     QueueEntryFactory = () => scope.ServiceProvider.GetRequiredService<IQueueEntry>
 });

Otherwise we can create it with delegate instance

    await lavalink.ConnectAsync(new LavalinkConfiguration()
    {
        Password = options.Password,
        RestEndpoint = endpoint,
        SocketEndpoint = endpoint,
        EnableBuiltInQueueSystem = true,
        QueueEntryFactory = () => new Features.Tracks.Interactions.QueueEntryFactory()
    });

When playing the tracks it will also create a transient of QueueEntryFactory

Test Configuration:

  • Firmware version:
  • Hardware: I5-12400F, 64GB, Nvidia RTX 4070 Super
  • Toolchain: window 10, visual studio, lavalink run on ubuntu 24.04
  • SDK: C#.NET 9

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published in downstream modules

@Aiko-IT-Systems/discatsharp

- Introduced a new `EditResponseAsync` method for string content.
- Created `DefaultQueueEntry` class for track playback handling.
- Updated `LavalinkConfiguration` with a customizable `QueueEntryFactory`.
- Refactored `LavalinkGuildPlayer` to utilize a static `QueueInternal` for guild-specific queues.
- Deprecated the `QueueEntries` property in favor of the new `Queue` property.
- Implemented a new thread-safe `LavalinkQueue<T>` class for queue operations.
@hqtruong27 hqtruong27 requested review from NyuwBot, Lulalaby and a team as code owners January 10, 2025 17:25
@hqtruong27 hqtruong27 requested a review from Chibi310 January 10, 2025 17:25
@CLAassistant
Copy link

CLAassistant commented Jan 10, 2025

CLA assistant check
All committers have signed the CLA.

@Lulalaby Lulalaby requested review from TheXorog and removed request for Chibi310 January 10, 2025 21:00
We don't use Obsolete anymore, instead we use Deprecated.
We distribute our own code analyzers.
@Lulalaby
Copy link
Member

Lulalaby commented Jan 10, 2025

A few minor things I fixed:

  • We use is and is not over == and !=
  • We document 100% of the library, so private fields etc. too
  • Some formatting

@Lulalaby
Copy link
Member

To

interaction response:
I really like the short, not too long way of writing.
The EditResponseAsync method is used a lot and I think the input is mainly a content, so I added a method input which is string content, hope you agree.

I have no problem with adding it, but I don't think it'll be in use for long since discord is changing some stuff cough #601 cough

@hqtruong27
Copy link
Contributor Author

To

interaction response:
I really like the short, not too long way of writing.
The EditResponseAsync method is used a lot and I think the input is mainly a content, so I added a method input which is string content, hope you agree.

I have no problem with adding it, but I don't think it'll be in use for long since discord is changing some stuff cough #601 cough

got it
so, should i revert it?

@Lulalaby
Copy link
Member

no its fine, we'll leave it in

@Lulalaby
Copy link
Member

We just have to test it out
Will do it later the day with @TheXorog (I'm forcing you darling)
Then we can get this merged.

Solid work, many thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants