-
Notifications
You must be signed in to change notification settings - Fork 2
/
default_search_handlers.go
270 lines (251 loc) · 4.97 KB
/
default_search_handlers.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
package control
import (
"fmt"
"strings"
"github.com/insomnimus/libman/handler"
"github.com/insomnimus/libman/handler/scmd"
)
func defaultSTrackHandlers() handler.Set {
hand := func(
c uint8,
name string,
about string,
usage string,
help string,
aliases ...string,
) handler.Handler {
return handler.Handler{
Cmd: c,
Name: name,
About: about,
Usage: usage,
Help: help,
Aliases: aliases,
Run: func(string) error {
panic("called handler.Run which was nil")
},
Complete: completeNothing,
}
}
set := handler.Set{
hand(
scmd.Play,
"play",
"Play a track.",
"play <N>",
"Play a track from the list. You can also just enter its number.",
"pl",
),
hand(
scmd.Save,
"save",
"Save a track to a playlist.",
"save <N> <playlist>",
"Save a track from the list to one of your playlists.",
"add",
),
hand(
scmd.Like,
"like",
"Add a track to your favourites folder.",
"like <N>",
"Add a track from the list to your favorites folder.",
"fav", "fave",
),
hand(
scmd.Queue,
"queue",
"Add a track to your playing queue.",
"queue <N>",
"Add a track from the list to your playing queue.",
"q", "que",
),
hand(
scmd.Help,
"help",
"Display help about a command.",
"help [command]",
"Display help about a command or list available commands.",
),
}
set.Find(scmd.Help).Run = set.RunHelp
set.Find(scmd.Help).Complete = newWordCompleter(set.CommandsAndAliases()...)
set.Find(scmd.Save).Complete = func(command, arg string) []string {
if !strings.Contains(arg, " ") {
return nil
}
left, arg := splitCmd(arg)
// complete arg (playlist name)
if err := updateCache(); err != nil {
return nil
}
pls := make([]string, 0, len(cache))
if arg == "" {
for _, p := range cache {
pls = append(pls, fmt.Sprintf("%s %s %s", command, left, p.Name))
}
return pls
}
for _, p := range cache {
if hasPrefixFold(p.Name, arg) {
pls = append(pls, fmt.Sprintf("%s %s %s", command, left, p.Name))
}
}
// return nil if there are no candidates
if len(pls) == 0 {
return nil
}
return pls
}
return set
}
func defaultSArtistHandlers() handler.Set {
hand := func(
c uint8,
name string,
about string,
usage string,
help string,
aliases ...string,
) handler.Handler {
return handler.Handler{
Cmd: c,
Name: name,
About: about,
Usage: usage,
Help: help,
Aliases: aliases,
Run: func(string) error {
panic("called handler.Run which was nil")
},
Complete: completeNothing,
}
}
set := handler.Set{
hand(
scmd.Play,
"play",
"Play an artist.",
"play <N>",
"Play an artist from the list.",
"pl",
),
hand(
scmd.Follow,
"follow",
"Follow an artist.",
"follow <N>",
"Follow an artist from the list.",
),
hand(
scmd.Help,
"help",
"Display help about a command.",
"help [command]",
"Display help about a command or list available commands.",
),
}
set.Find(scmd.Help).Complete = set.CompleteHelp
set.Find(scmd.Help).Run = set.RunHelp
return set
}
func defaultSAlbumHandlers() handler.Set {
hand := func(
c uint8,
name string,
about string,
usage string,
help string,
aliases ...string,
) handler.Handler {
return handler.Handler{
Cmd: c,
Name: name,
About: about,
Usage: usage,
Help: help,
Aliases: aliases,
Run: func(string) error {
panic("called handler.Run which was nil")
},
Complete: completeNothing,
}
}
set := handler.Set{
hand(
scmd.Play,
"play",
"Play an album.",
"play <N>",
"Play an album from the list.",
"pl",
),
hand(
scmd.Save,
"save",
"Save an album to your library.",
"save <N>",
"Save an album from the list to your library.",
),
hand(
scmd.Help,
"help",
"Display help about a command.",
"help [command]",
"Display help about a command or list available commands.",
),
}
set.Find(scmd.Help).Run = set.RunHelp
set.Find(scmd.Help).Complete = set.CompleteHelp
return set
}
func defaultSPlaylistHandlers() handler.Set {
hand := func(
c uint8,
name string,
about string,
usage string,
help string,
aliases ...string,
) handler.Handler {
return handler.Handler{
Cmd: c,
Name: name,
About: about,
Usage: usage,
Help: help,
Aliases: aliases,
Run: func(string) error {
panic("called handler.Run which was nil")
},
Complete: completeNothing,
}
}
set := handler.Set{
hand(
scmd.Play,
"play",
"Play a playlist.",
"play <N>",
"Play a playlist from the list.",
"pl",
),
hand(
scmd.Follow,
"follow",
"Follow a playlist.",
"follow <N>",
"Follow a playlist from the list.",
),
hand(
scmd.Help,
"help",
"display help about a command.",
"help [command]",
"Display help about a command or list available commands.",
),
}
set.Find(scmd.Help).Run = set.RunHelp
set.Find(scmd.Help).Complete = set.CompleteHelp
return set
}