Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
use same style for search and queue
Browse files Browse the repository at this point in the history
  • Loading branch information
sarisia committed Oct 6, 2020
1 parent 4b46a94 commit 033efed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
7 changes: 2 additions & 5 deletions aria/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,8 @@ func (b *bot) cmdQueue(m *discordgo.Message, _ []string) {

e.Fields = []*discordgo.MessageEmbedField{}
for i := 0; i < flen; i++ {
e.Fields = append(e.Fields, &discordgo.MessageEmbedField{
Name: "Track " + strconv.Itoa(i+1) + " - " + q.Queue[i].Source,
Value: digitEmojis[i+1] + " " + q.Queue[i].Title,
Inline: false,
})
header := digitEmojis[i+1] + " "
e.Fields = append(e.Fields, embedFieldFromEntry(&q.Queue[i], header))
}

if len(q.Queue) > 5 {
Expand Down
17 changes: 2 additions & 15 deletions aria/packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,22 +308,9 @@ func (w *searchWindow) render() (e *discordgo.MessageEmbed) {
if _, ok := w.selected[entry.URI]; ok {
header += " ✅"
}
header += " "

meta := fmt.Sprintf("from `%s`", entry.Source)
if entry.Entry != nil {
if entry.Entry.User != "" {
meta = fmt.Sprintf("%s `(%s)`", meta, entry.Entry.User)
}
if entry.Entry.Album != "" {
meta = fmt.Sprintf("%s, in `%s`", meta, entry.Entry.Album)
}
}

e.Fields = append(e.Fields, &discordgo.MessageEmbedField{
Name: fmt.Sprintf("%s %s", header, entry.Title),
Value: meta,
Inline: false,
})
e.Fields = append(e.Fields, embedFieldFromEntry(&entry, header))
}

return e
Expand Down
20 changes: 20 additions & 0 deletions aria/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package aria
import (
"fmt"
"time"

"github.com/bwmarrin/discordgo"
)

func durationString(rawdur float64) (dstr string) {
Expand All @@ -19,6 +21,24 @@ func durationString(rawdur float64) (dstr string) {
return
}

func embedFieldFromEntry(entry *entry, header string) *discordgo.MessageEmbedField {
meta := fmt.Sprintf("from `%s`", entry.Source)
if entry.Entry != nil {
if entry.Entry.User != "" {
meta = fmt.Sprintf("%s `(%s)`", meta, entry.Entry.User)
}
if entry.Entry.Album != "" {
meta = fmt.Sprintf("%s, in `%s`", meta, entry.Entry.Album)
}
}

return &discordgo.MessageEmbedField{
Name: header + entry.Title,
Value: meta,
Inline: false,
}
}

func max(a, b int) int {
if a > b {
return a
Expand Down

0 comments on commit 033efed

Please sign in to comment.