This repository was archived by the owner on Dec 31, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDefaultCommands.go
More file actions
64 lines (57 loc) · 1.49 KB
/
DefaultCommands.go
File metadata and controls
64 lines (57 loc) · 1.49 KB
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
package SpecterGO
import (
"github.com/SpecterTeam/SpecterGO/command"
"github.com/SpecterTeam/SpecterGO/utils"
"strconv"
)
func InitCommands() {
command.GetCommandMap().AddCommand(HelpCommand())
command.GetCommandMap().AddCommand(StopCommand())
}
func HelpCommand() command.Command {
return command.NewCommand("help", []string{"?"}, "sends a list of commands", "specter.help", func(args []string){
GetLogger().Info("Commands :")
if len(args) == 0 {
for name, c := range command.GetCommandMap().Commands() {
GetLogger().Info("/" + name + ": " + c.Description())
}
} else {
page,err := strconv.Atoi(args[0])
if err != nil {
utils.HandleError(err)
} else {
list := makeHelpList()
max := len(list)
if page > max {
for name,c := range list[0] {
GetLogger().Info("/" + name + ": " + c.Description())
}
} else {
page--
for name,c := range list[page] {
GetLogger().Info("/" + name + ": " + c.Description())
}
}
}
}
})
}
func StopCommand() command.Command {
return command.NewCommand("stop", []string{"shutdown", "exit"}, "Stop the server", "specter.stop", func(args []string) {
GetLogger().Info("Stopping the server...")
GetServer().Shutdown()
})
}
func makeHelpList() map[int]map[string]command.Command {
list := make(map[int]map[string]command.Command)
count,page := 0,0
for name,c := range command.GetCommandMap().Commands() {
if count == 5 {
page++
count = 0
}
list[page][name] = c
count++
}
return list
}