diff --git a/djpianalto.com/goff/exts/init.go b/djpianalto.com/goff/exts/init.go new file mode 100644 index 0000000..2032cab --- /dev/null +++ b/djpianalto.com/goff/exts/init.go @@ -0,0 +1,17 @@ +package exts + +import "github.com/MikeModder/anpan" + +func AddCommandHandlers(h *anpan.CommandHandler) { + // Arguments: + // name - command name - string + // desc - command description - string + // owneronly - only allow owners to run - bool + // hidden - hide command from non-owners - bool + // perms - permissisions required - anpan.Permission (int) + // type - command type, sets where the command is available + // run - function to run - func(anpan.Context, []string) / CommandRunFunc + h.AddCommand("ping", "Check the bot's ping", false, false, 0, anpan.CommandTypeEverywhere, pingCommand) + h.AddCommand("say", "Repeat a message", false, false, 0, anpan.CommandTypeEverywhere, sayCommand) + h.AddCommand("user", "Show info about a user", false, false, 0, anpan.CommandTypeEverywhere, userCommand) +} diff --git a/djpianalto.com/goff/exts/utils.go b/djpianalto.com/goff/exts/utils.go index f9a2768..1639714 100644 --- a/djpianalto.com/goff/exts/utils.go +++ b/djpianalto.com/goff/exts/utils.go @@ -11,7 +11,7 @@ import ( "time" ) -func PingCommand(ctx anpan.Context, _ []string) error { +func pingCommand(ctx anpan.Context, _ []string) error { timeBefore := time.Now() msg, _ := ctx.Reply("Pong!") took := time.Now().Sub(timeBefore) @@ -19,7 +19,7 @@ func PingCommand(ctx anpan.Context, _ []string) error { return err } -func SayCommand(ctx anpan.Context, args []string) error { +func sayCommand(ctx anpan.Context, args []string) error { resp := strings.Join(args, " ") resp = strings.ReplaceAll(resp, "@everyone", "@\ufff0everyone") resp = strings.ReplaceAll(resp, "@here", "@\ufff0here") @@ -27,7 +27,7 @@ func SayCommand(ctx anpan.Context, args []string) error { return err } -func UserCommand(ctx anpan.Context, args []string) error { +func userCommand(ctx anpan.Context, args []string) error { var member *discordgo.Member if len(args) == 0 { member, _ = ctx.Session.GuildMember(ctx.Guild.ID, ctx.Message.Author.ID) diff --git a/djpianalto.com/goff/goff.go b/djpianalto.com/goff/goff.go index 2923a07..4776152 100644 --- a/djpianalto.com/goff/goff.go +++ b/djpianalto.com/goff/goff.go @@ -41,17 +41,12 @@ func main() { // check perms - bool handler := anpan.NewCommandHandler(prefixes, owners, true, true) - // Arguments: - // name - command name - string - // desc - command description - string - // owneronly - only allow owners to run - bool - // hidden - hide command from non-owners - bool - // perms - permissisions required - anpan.Permission (int) - // type - command type, sets where the command is available - // run - function to run - func(anpan.Context, []string) / CommandRunFunc - handler.AddCommand("ping", "Check the bot's ping", false, false, 0, anpan.CommandTypeEverywhere, exts.PingCommand) - handler.AddCommand("say", "Repeat a message", false, false, 0, anpan.CommandTypeEverywhere, exts.SayCommand) - handler.AddCommand("user", "Show info about a user", false, false, 0, anpan.CommandTypeEverywhere, exts.UserCommand) + // Add Command Handlers + exts.AddCommandHandlers(&handler) + + if _, ok := handler.Commands["help"]; !ok { + handler.AddDefaultHelpCommand() + } dg.AddHandler(handler.OnMessage) dg.AddHandler(handler.StatusHandler.OnReady) @@ -68,5 +63,8 @@ func main() { <-sc fmt.Println("Shutting Down...") - dg.Close() + err = dg.Close() + if err != nil { + fmt.Println(err) + } }