-
Notifications
You must be signed in to change notification settings - Fork 15
/
commands-dev.go
163 lines (127 loc) · 3.9 KB
/
commands-dev.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
package main
import (
"fmt"
"os"
"os/exec"
"runtime"
"strconv"
"strings"
"time"
)
// Enables developer mode (prints debug output, etc.)
func cmdDevMode(params cmdArguments) {
s := params.s
m := params.m
if !DeveloperMode {
DeveloperMode = true
fmt.Println("[INFO] Developer mode has been enabled!!!")
_, _ = s.ChannelMessageSend(m.ChannelID, "Developer Mode Enabled!")
} else {
DeveloperMode = false
fmt.Println("[INFO] Developer mode has been disabled.")
_, _ = s.ChannelMessageSend(m.ChannelID, "Developer Mode Disabled!")
}
}
// Runs a test feature (subject to change at any time)
func cmdTest(params cmdArguments) {
s := params.s
m := params.m
_, _ = s.ChannelMessageSend(m.ChannelID, "Not implemented.")
}
// Simple test command. "Ping" -> "Pong!"
func cmdPing(params cmdArguments) {
s := params.s
m := params.m
_, _ = s.ChannelMessageSend(m.ChannelID, "Pong!")
}
// Echos what the user gives
func cmdSay(params cmdArguments) {
s := params.s
m := params.m
args := params.args
name := args[0]
msg := strings.Join(args, " ")
msg = strings.Replace(msg, name, "", 1)
_, _ = s.ChannelMessageSend(m.ChannelID, msg)
}
// Outputs detailed memory usage statistics
func cmdMem(params cmdArguments) {
var mem runtime.MemStats
var embedFields []embedField
s := params.s
m := params.m
runtime.ReadMemStats(&mem)
embedTitle := embedField{
name: "Memory Usage",
value: "-",
inline: false,
}
embedAllocated := embedField{
name: "Allocated (not including free objects)",
value: strconv.FormatUint(mem.Alloc/1024, 10) + " bytes",
inline: false,
}
embedTotalAllocated := embedField{
name: "Total Allocated (including free objects)",
value: strconv.FormatUint(mem.TotalAlloc/1024, 10) + " bytes",
inline: false,
}
embedSystem := embedField{
name: "System (including stack, heap, .text, etc.)",
value: strconv.FormatUint(mem.Sys/1024, 10) + " bytes",
inline: false,
}
embedFields = append(embedFields, embedTitle, embedAllocated, embedTotalAllocated, embedSystem)
discordSendEmbeddedMsg(s, m.ChannelID, embedFields, "", 0x57D5FF, "https://secure.webtoolhub.com/static/resources/icons/set8/9b41f8b3af63.png")
}
// Gives the current uptime
func cmdUptime(params cmdArguments) {
var embedFields []embedField
s := params.s
m := params.m
uptime := time.Since(startTime)
days := padLeft(strconv.Itoa(int(uptime.Hours())/24), "0", 2)
hours := padLeft(strconv.Itoa(int(uptime.Hours())%24), "0", 2)
mins := padLeft(strconv.Itoa(int(uptime.Minutes())%60), "0", 2)
secs := padLeft(strconv.Itoa(int(uptime.Seconds())%60), "0", 2)
// Notify the user of the uptime
embedUptime := embedField {
name: "Uptime",
value: days + " days, " + hours + " hours, " + mins + " minutes, " + secs + " seconds.",
inline: false,
}
embedFields = append(embedFields, embedUptime)
discordSendEmbeddedMsg(s, m.ChannelID, embedFields, "", 0x00BFFF, "https://i.imgur.com/2yCS7A7.png")
}
// Restarts the bot.
func cmdRestart(params cmdArguments) {
var embedFields []embedField
s := params.s
m := params.m
// Notify the user of the restart
embedRestart := embedField{
name: "Restarting!",
value: "I'm now restarting - be right back!",
inline: false,
}
embedFields = append(embedFields, embedRestart)
discordSendEmbeddedMsg(s, m.ChannelID, embedFields, "", 0x00BFFF, "https://cdn4.iconfinder.com/data/icons/circle-blue/64/restart.png")
cmd := exec.Command("./restart.sh")
_ = cmd.Start()
os.Exit(0)
}
// Kills the bot.
func cmdDie(params cmdArguments) {
var embedFields []embedField
s := params.s
m := params.m
// Notify the user of the restart
embedRestart := embedField{
name: "Shutting Down!",
value: "I'm shutting down now, goodbye.",
inline: false,
}
embedFields = append(embedFields, embedRestart)
discordSendEmbeddedMsg(s, m.ChannelID, embedFields, "", 0x00BFFF, "https://cdn3.iconfinder.com/data/icons/ginux/Png/Shutdown-64.png")
os.Exit(0)
}