interactions yay!!
This commit is contained in:
parent
b9a05bedf9
commit
f60033a3e4
30 changed files with 716 additions and 44 deletions
38
interactions/router.go
Normal file
38
interactions/router.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package interactions
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.sapphic.engineer/roleypoly/v4/types"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
type InteractionHandler func(interaction Interaction) (InteractionResponse, error)
|
||||
|
||||
type InteractionRouter struct {
|
||||
Routes map[string]InteractionHandler
|
||||
}
|
||||
|
||||
func NewInteractionRouter() *InteractionRouter {
|
||||
return &InteractionRouter{
|
||||
Routes: map[string]InteractionHandler{},
|
||||
}
|
||||
}
|
||||
|
||||
func (r *InteractionRouter) Add(name string, h InteractionHandler) {
|
||||
r.Routes[name] = h
|
||||
}
|
||||
|
||||
func (r *InteractionRouter) Handle(c fiber.Ctx, interaction Interaction) error {
|
||||
route, ok := r.Routes[interaction.Data.Name]
|
||||
if !ok {
|
||||
return types.NewAPIError(http.StatusNotFound, "command not found").Send(c)
|
||||
}
|
||||
|
||||
resp, err := route(interaction)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.JSON(resp)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue