Skip to content

Commit

Permalink
Fix empty queue
Browse files Browse the repository at this point in the history
  • Loading branch information
robrotheram committed Jan 2, 2024
1 parent 19528e4 commit 396b890
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/discord/components/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ func paginate(pageNum int, pageSize int, sliceLength int) (int, int) {
if end > sliceLength {
end = sliceLength
}

if start < 0 {
start = 0
}
if end >= sliceLength {
end = sliceLength - 1
}
return start, end
}

Expand All @@ -95,7 +102,18 @@ func truncate(text string, maxLen int) string {
return text
}

func emptyQueue() *discordgo.InteractionResponseData {
return &discordgo.InteractionResponseData{
Content: "Queue is empty",
Flags: discordgo.MessageFlagsEphemeral,
}
}

func QueueCompontent(queue []media.Media, pageNum int) *discordgo.InteractionResponseData {
if len(queue) == 0 {
return emptyQueue()
}

start, end := paginate(pageNum, pageSize, len(queue))
pagedSlice := queue[start:end]
if len(pagedSlice) == 0 {
Expand Down

0 comments on commit 396b890

Please sign in to comment.