feat(lib,commands,context): Context and ChatCommandContext for Handler

This commit is contained in:
Guz
2024-11-22 10:37:40 -03:00
parent db21d12dfc
commit 334e098cdd
2 changed files with 20 additions and 10 deletions

View File

@@ -1,22 +1,32 @@
package bot
import "github.com/bwmarrin/discordgo"
import (
"errors"
"github.com/bwmarrin/discordgo"
)
type Command interface {
ApplicationCommand() *discordgo.ApplicationCommand
Validate() (bool, error)
}
type Handler interface {
Handle(s *discordgo.Session, ic *discordgo.InteractionCreate) error
type Handler[CTX any] interface {
Handle(ctx CTX) error
}
type HandlerFunc func(s *discordgo.Session, ic *discordgo.InteractionCreate) error
type HandlerFunc[CTX any] func(ctx CTX) error
func (h HandlerFunc) Handle(
s *discordgo.Session,
ic *discordgo.InteractionCreate,
) error {
return h(s, ic)
func (h HandlerFunc[CTX]) Handle(ctx CTX) error {
return h(ctx)
}
type Context struct {
discordgo.Interaction
}
type ChatCommandContext struct {
Context
}
}

View File

@@ -16,7 +16,7 @@ type ChatCommand struct {
Description string
DescriptionLocalizations *map[discordgo.Locale]string
Options []ChatCommandOption
Handler Handler
Handler Handler[ChatCommandContext]
}
func (c *ChatCommand) ApplicationCommand() *discordgo.ApplicationCommand {