This repository has been archived by the owner on May 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.go
134 lines (117 loc) · 3.91 KB
/
commands.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
package commands
import (
"fmt"
"strings"
)
var exitCommands = [4]string{"exit", "e", "quit", "q"}
var urlCommands = [2]string{"url", "u"}
var markdownCommands = [2]string{"md", "m"}
var bbcodeCommands = [2]string{"bbcode", "b"}
var deleteCommands = [2]string{"delete", "del"}
var configCommands = [2]string{"config", "details"}
var countCommands = [2]string{"count", "gifs"}
var helpCommands = [2]string{"help", "?"}
var versionCommands = [2]string{"version", "v"}
var taylorCommands = [4]string{"taylor", "taylorswift", "taylor swift", "swiftie"}
// Exit returns true if the input is an exit command
func Exit(input string) (exists bool) {
return supported(input, exitCommands[:])
}
// URLMode returns true if the input is a url mode command
func URLMode(input string) (exists bool) {
return supported(input, urlCommands[:])
}
// MarkdownMode returns true if the input is a markdown mode command
func MarkdownMode(input string) bool {
return supported(input, markdownCommands[:])
}
// BBCodeMode returns true if the input is a bbcode mode command
func BBCodeMode(input string) bool {
return supported(input, bbcodeCommands[:])
}
// Delete returns true if the input is a delete command
func Delete(input string) (exists bool) {
return supported(input, deleteCommands[:])
}
// Help returns true if the input is a help command
func Help(input string) bool {
return supported(input, helpCommands[:])
}
// Config returns true if the input is a config command
func Config(input string) bool {
return supported(input, configCommands[:])
}
// Count returns true if the input is a count command
func Count(input string) bool {
return supported(input, countCommands[:])
}
// Version returns true if the input is a version command
func Version(input string) bool {
return supported(input, versionCommands[:])
}
// Taylor returns true if the input is a <3 Taylor Swift <3 command
func Taylor(input string) bool {
return supported(input, taylorCommands[:])
}
// Any returns true if the input is in any of the commands
func Any(input string) bool {
var all []string
for _, v := range urlCommands {
all = append(all, v)
}
for _, v := range markdownCommands {
all = append(all, v)
}
for _, v := range bbcodeCommands {
all = append(all, v)
}
for _, v := range deleteCommands {
all = append(all, v)
}
for _, v := range helpCommands {
all = append(all, v)
}
for _, v := range versionCommands {
all = append(all, v)
}
for _, v := range countCommands {
all = append(all, v)
}
for _, v := range exitCommands {
all = append(all, v)
}
for _, v := range configCommands {
all = append(all, v)
}
for _, v := range taylorCommands {
all = append(all, v)
}
return supported(input, all[:])
}
// HelpOutput outputs the entries for each command
func HelpOutput() string {
output := "Supported Commands:\n"
output += fmt.Sprintf(" %v - Shift to URL Mode\n", strings.Join(urlCommands[:], ", "))
output += fmt.Sprintf(" %v - Shift to Markdown Mode\n", strings.Join(markdownCommands[:], ", "))
output += fmt.Sprintf(" %v - Shift to BBCode Mode\n", strings.Join(bbcodeCommands[:], ", "))
output += fmt.Sprintf(" %v - Delete Last Record\n", strings.Join(deleteCommands[:], ", "))
output += fmt.Sprintf(" %v - Database Record Count\n", strings.Join(countCommands[:], ", "))
output += fmt.Sprintf(" %v - Loaded Configuration\n", strings.Join(configCommands[:], ", "))
output += fmt.Sprintf(" %v - Version Details\n", strings.Join(versionCommands[:], ", "))
output += fmt.Sprintf(" %v - Exit Program\n", strings.Join(exitCommands[:], ", "))
output += fmt.Sprintf(" %v - Help (This Menu)\n", strings.Join(helpCommands[:], ", "))
return output
}
// returns whether the passed input (or a variant) exists in the commands slice
func supported(input string, commands []string) (exists bool) {
if strings.HasPrefix(input, ":") {
input = strings.Replace(input, ":", "", 1)
}
for _, k := range commands {
if input == k {
exists = true
break
}
}
return
}