feat(lib,commands,context): Context and ChatCommandContext for Handler
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user