1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-12-14 01:15:00 +00:00
arikawa/utils/bot/_example/advanced_bot/debug.go

64 lines
1.6 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"log"
"runtime"
"strings"
"github.com/diamondburned/arikawa/v3/gateway"
2021-09-22 17:56:35 +00:00
"github.com/diamondburned/arikawa/v3/utils/bot"
"github.com/diamondburned/arikawa/v3/utils/bot/extras/middlewares"
)
// 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.
// Those methods can take in a regular Go method reference.
sub.ChangeCommandInfo(d.GOOS, "GOOS", "Prints the current operating system")
sub.ChangeCommandInfo(d.GC, "GC", "Triggers the garbage collector")
// They could also take in the raw name.
sub.ChangeCommandInfo("Goroutines", "", "Prints the current number of Goroutines")
sub.Hide(d.Die)
sub.AddMiddleware(d.Die, middlewares.AdminOnly(d.Context))
}
// ~go goroutines
func (d *Debug) Goroutines(*gateway.MessageCreateEvent) (string, error) {
2020-01-26 09:08:53 +00:00
return fmt.Sprintf(
"goroutines: %d",
runtime.NumGoroutine(),
2020-01-26 09:08:53 +00:00
), nil
}
// ~go GOOS
func (d *Debug) GOOS(*gateway.MessageCreateEvent) (string, error) {
2020-01-26 09:08:53 +00:00
return strings.Title(runtime.GOOS), nil
}
// ~go GC
func (d *Debug) GC(*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) Die(m *gateway.MessageCreateEvent) error {
log.Fatalln("User", m.Author.Username, "killed the bot x_x")
return nil
}