diff --git a/lib/command.go b/lib/command.go index 63fcbea..f80b380 100644 --- a/lib/command.go +++ b/lib/command.go @@ -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 +} + +} diff --git a/lib/command_chat.go b/lib/command_chat.go index 766b1ab..74ef0f3 100644 --- a/lib/command_chat.go +++ b/lib/command_chat.go @@ -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 {