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_remove.go
98 lines (69 loc) · 2.43 KB
/
command_remove.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"strconv"
"strings"
"github.com/bwmarrin/discordgo"
)
var RemoveCommand Command = Command{
Name: "remove",
Description: "Removes a song from the queue.\ns[index]remove [position]",
Aliases: []string{"rm", "delete"},
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
}
var posToRemove []string = strings.Split(arg, " ")
if len(posToRemove) == 1 {
pos, err := strconv.Atoi(posToRemove[0])
if err != nil {
client.MessageInteraction(message, ERROR_MSG, COLOR_ERROR)
return
}
if pos-1 < 0 || int(pos)-1 >= len(client.Queue.Queue) {
client.MessageInteraction(message, "Please inform a valid input!", COLOR_ERROR)
return
}
if (pos - 1) == client.Queue.GetNextIndex() {
client.MessageInteraction(message, "You can't delete the current song!", COLOR_ERROR)
return
}
client.Queue.Remove(pos - 1)
client.MessageInteraction(message, "Song removed!", COLOR_SUCCESS)
} else {
var positions []int = []int{}
for _, istr := range posToRemove {
conv, err := strconv.Atoi(istr)
if err != nil {
client.MessageInteraction(message, ERROR_MSG, COLOR_ERROR)
return
}
if conv-1 < 0 || int(conv)-1 >= len(client.Queue.Queue) {
client.MessageInteraction(message, WARN_INVALID_INPUT, COLOR_WARNING)
return
}
if (conv - 1) == client.Queue.GetNextIndex() {
client.MessageInteraction(message, CustomWarning("You can't delete the current song!"), COLOR_WARNING)
return
}
positions = append(positions, conv-1)
}
var newQueue []Track = []Track{}
var lowerBound int = 0
for i := 0; i < len(positions); i++ {
newQueue = append(newQueue, client.Queue.Queue[lowerBound:positions[i]]...)
lowerBound = positions[i] + 1
}
client.Queue.Queue = newQueue
client.Queue.CurrentIndex -= int16(len(posToRemove))
client.MessageInteraction(message, CustomSuccess("Song(s) removed."), COLOR_SUCCESS)
}
},
}