1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-12-12 16:35:30 +00:00
arikawa/_example/advanced_bot/debug.go

63 lines
1.4 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"log"
"runtime"
"strings"
"github.com/diamondburned/arikawa/bot"
"github.com/diamondburned/arikawa/gateway"
)
// Flag for administrators only.
type Debug struct {
Context *bot.Context
}
// Setup demonstrates the CanSetup interface. This function will never be parsed
// as a callback of any event.
func (d *Debug) Setup(sub *bot.Subcommand) {
// Set a custom command (e.g. "!go ..."):
sub.Command = "go"
// Set a custom description:
sub.Description = "Print Go debugging variables"
// Manually set the usage for each function.
sub.ChangeCommandInfo("GOOS", "",
"Prints the current operating system")
sub.ChangeCommandInfo("GC", "",
"Triggers the garbage collecto")
sub.ChangeCommandInfo("Goroutines", "",
"Prints the current number of Goroutines")
}
// ~go goroutines
2020-01-26 09:08:53 +00:00
func (d *Debug) Goroutines(m *gateway.MessageCreateEvent) (string, error) {
return fmt.Sprintf(
"goroutines: %d",
runtime.NumGoroutine(),
2020-01-26 09:08:53 +00:00
), nil
}
// ~go GOOS
2020-01-26 09:08:53 +00:00
func (d *Debug) RーGOOS(m *gateway.MessageCreateEvent) (string, error) {
return strings.Title(runtime.GOOS), nil
}
// ~go GC
2020-01-26 09:08:53 +00:00
func (d *Debug) RーGC(m *gateway.MessageCreateEvent) (string, error) {
runtime.GC()
2020-01-26 09:08:53 +00:00
return "Done.", nil
}
// ~go die
// This command will be hidden from ~help by default.
func (d *Debug) AーDie(m *gateway.MessageCreateEvent) error {
log.Fatalln("User", m.Author.Username, "killed the bot x_x")
return nil
}