This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_sort.go
61 lines (45 loc) · 1.91 KB
/
command_sort.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"sort"
"github.com/bwmarrin/discordgo"
)
type ByTitle []Track
func (a ByTitle) Len() int { return len(a) }
func (a ByTitle) Less(i, j int) bool { return a[i].AudioTrack.Info.Title < a[j].AudioTrack.Info.Title }
func (a ByTitle) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
type ByRequester []Track
func (a ByRequester) Len() int { return len(a) }
func (a ByRequester) Less(i, j int) bool { return a[i].RequesterName < a[j].RequesterName }
func (a ByRequester) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
var SortCommand Command = Command{
Name: "sort",
Description: "Sort the next songs in queue.\ns[index]sort [title/requester]",
Aliases: []string{},
Instance: func(client *Client, message *discordgo.MessageCreate, arg string) {
userPermission, _, _ := client.CheckPermissionsForUser(message)
if userPermission == PERM_ERROR {
client.MessageInteraction(message, ERROR_MSG, COLOR_ERROR)
return
} else if userPermission == PERM_NOT_IN_VC {
client.MessageInteraction(message, "❌ | You're not in a voice channel!", COLOR_ERROR)
return
} else if userPermission == PERM_WRONG_VC {
client.MessageInteraction(message, "⚠️ | I'm in another voice channel!", COLOR_WARNING)
return
}
if len(client.Queue.Queue) < 2 && int(client.Queue.GetNextIndex()+1) < len(client.Queue.Queue) {
client.MessageInteraction(message, CustomError("You can't do that!"), COLOR_ERROR)
return
}
if arg == "title" {
sort.Sort(ByTitle(client.Queue.Queue[client.Queue.GetNextIndex()+1:]))
} else if arg == "requester" {
sort.Sort(ByRequester(client.Queue.Queue[client.Queue.GetNextIndex()+1:]))
} else {
client.MessageInteraction(message, CustomWarning("Invalid input, try: `title` or `requester`."), COLOR_WARNING)
return
}
client.MessageInteraction(message, CustomSuccess(fmt.Sprintf("Queue sorted by %s", arg)), COLOR_SUCCESS)
},
}