-
Notifications
You must be signed in to change notification settings - Fork 75
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
Add queue command #1
Conversation
Off the top of your head, can the current way of writing the list cause any issues (unwanted mentions, janky text, etc.)? Also is there a way for me to get the song requester that is readily available? Or does that need to be implemented separately? |
Sorry for the late reply. I'm currently sick.
All mentions are configured to be disabled by default. Janky text is possible. At some point I would like to write formatter helper functions that take unsafe args as varargs. Don't worry about it for now.
We'd need to store metadata about it. Lavaplayer is in no way aware of JDA. Lavaplayer has a way to set custom data with each track. I have a fancy way of doing this with Kotlin. |
duration += queue.getDuration() | ||
return duration | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These new functions looks a lot like a Java dev trying to write Java in Kotlin. Kotlin has some tricks that would make these much shorter.
var duration: Long = 0 | ||
|
||
if (player.playingTrack != null) | ||
duration += player.playingTrack.info.length |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This gets the total length not the remaining length. Subtract track the position.
) : Command("q") { | ||
|
||
private val pageSize = 5 | ||
private val response = StringBuilder() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this a class property?? This is in no way thread-safe.
val pageIndex: Int | ||
|
||
// Handle edge cases for arguments | ||
if (index == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This chain can be replaced by a single call to Int#coerceIn()
If you were using Java, I would recommend Math.max()
and Math.min()
on a single line.
pageIndex = index | ||
|
||
//Add header | ||
response.append("Page **${pageIndex}** of **${pageCount}**\n\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
response.append("Page **${pageIndex}** of **${pageCount}**\n\n") | |
response.append("Page **$pageIndex** of **$pageCount**\n\n") |
return hms | ||
} | ||
|
||
private fun CommandContext.paginateQueue(queue: List<AudioTrack>, index: Int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try this neat helper function to use a StringBuilder as receiver and return a string
private fun CommandContext.paginateQueue(queue: List<AudioTrack>, index: Int) { | |
private fun CommandContext.paginateQueue(queue: List<AudioTrack>, index: Int) = builder { |
|
||
// Preserve original indexes | ||
queue.forEachIndexed { ind, t -> | ||
if (t in queue.chunked(pageSize)[pageIndex - 1]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be smarter to just iterate a sublist?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't a sublist hold its' own indexes, in this case 0-4? Or am I mistaken?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, but we can just calculate an offset
return queue | ||
} | ||
fun getDuration(): Long { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Want to save 6 lines of code?
fun getDuration() = queue.sumOf { it.info.length }
Basic list of songs queued, including the one currently playing.
Stuff to be taken care of after initial approval: