Git Product home page Git Product logo

Comments (12)

Yucked avatar Yucked commented on August 21, 2024 2

Okay that was dumb on my part. Casting hierarchy doesn't work that way. So, yeah I will have to creator a CTOR for LavaTrack. I'll do it in next release hopefully in few hours.

from victoria.

Yucked avatar Yucked commented on August 21, 2024 1

This feature has been added in v5.1.9. You are now able to extend LavaTracks.

from victoria.

Yucked avatar Yucked commented on August 21, 2024

Hey, you can extend LavaTrack or have a class that implements IQueueable. For example:

public sealed class Request : IQueueable {
     public LavaTrack Track { get; set; }
     public ulong UserId { get; set; }
     public IGuildUser User { get; set; }
}
...
if !(lavaPlayer.Queue.TryDequeue(out var queueable))
     return;

var request = queueable as Request;
await lavaPlayer.PlayAsync(request.LavaTrack);
await ReplyAsync($"Now Playing: {request.LavaTrack.Title}\nRequested By: {request.User}");

from victoria.

snoww avatar snoww commented on August 21, 2024

I implemented IQueueable, but when I queue the track, I lose the user I lose the user information. Same issue when getting the player’s current track. I’m not sure how I’d go on extending LavaTrack

from victoria.

Yucked avatar Yucked commented on August 21, 2024

Can you show me your code? I can help debug that issue and extending LavaTrack is simple.

public sealed class CustomTrack : LavaTrack {

}

Then instead of queueing LavaTrack you queue your CustomTrack. And cast IQueueable to CustomTrack when de-queueing from queue.

from victoria.

snoww avatar snoww commented on August 21, 2024

For the interface method heres my implementation:

public class RokiRequest : IQueueable
{
    public LavaTrack Track { get; set; }
    public IGuildUser User { get; set; }
}

and then I create a new request and add it to the queue.

var request = new RokiRequest {Track = result.Tracks.FirstOrDefault(), User = ctx.User as IGuildUser};
player.Queue.Enqueue(request);

this all works fine. But when I cannot get the custom request when doing getting the current track info
i.e.

var currTrack = player.Track;

the currTrack would be a LavaTrack

from victoria.

Yucked avatar Yucked commented on August 21, 2024

Yeah then my previous reply should be of help.

from victoria.

snoww avatar snoww commented on August 21, 2024

So when I extend LavaTrack, would it be something like this?

public class RokiTrack : LavaTrack
{
    public IGuildUser User { get; set; }
}

and then I do

var request = (RokiTrack) result.Tracks.First();
request.User = ctx.User as IGuildUser;
player.Queue.Enqueue(request);

correct?

from victoria.

Yucked avatar Yucked commented on August 21, 2024

Yes, that should be it.

from victoria.

snoww avatar snoww commented on August 21, 2024

I get this error when casting

System.InvalidCastException: Unable to cast object of type 'Victoria.LavaTrack' to type 'Roki.Modules.Music.Common.RokiTrack'.

from victoria.

Yucked avatar Yucked commented on August 21, 2024

Rip I know why. Okay so when you get tracks from search they are not RokiTrack. What you need to do is.

var track = Tracks.FirstOrDefault();
var RokiTrack = track as RokiTrack;

Try that and Lmk.

from victoria.

snoww avatar snoww commented on August 21, 2024

heres what I did

var track = result.Tracks.FirstOrDefault();
var request = track as RokiTrack;
if (request == null)
{
    _log.Error("Error casting");
    return;
}

the if statement is true every time

do I need to add the LavaTrack properties in RokiTrack? I dont think so right? since its extended from it.

Edit: what I've found out is that I would need to have a constructor in RokiTrack that sets the properties from LavaTrack, but I cannot since the set is private in LavaTrack

from victoria.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.