slash roleypoly yay
This commit is contained in:
parent
02f5075d3b
commit
607d7e121c
22 changed files with 394 additions and 66 deletions
|
@ -2,6 +2,7 @@ package interactions
|
|||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
|
@ -9,23 +10,30 @@ import (
|
|||
|
||||
"git.sapphic.engineer/roleypoly/v4/discord"
|
||||
"git.sapphic.engineer/roleypoly/v4/types"
|
||||
"git.sapphic.engineer/roleypoly/v4/utils"
|
||||
)
|
||||
|
||||
type Interactions struct {
|
||||
PublicKey ed25519.PublicKey
|
||||
Guilds *discord.GuildService
|
||||
Router *InteractionRouter
|
||||
PublicKey ed25519.PublicKey
|
||||
PublicBaseURL string
|
||||
Guilds *discord.GuildService
|
||||
Router *InteractionRouter
|
||||
|
||||
// if interactions are able to be used
|
||||
OK bool
|
||||
|
||||
commandsMap []InteractionCommand
|
||||
commandsMentions map[string]string
|
||||
}
|
||||
|
||||
func NewInteractions(publicKey string, guildsService *discord.GuildService) *Interactions {
|
||||
func NewInteractions(publicKey string, publicBaseURL string, guildsService *discord.GuildService) *Interactions {
|
||||
|
||||
return &Interactions{
|
||||
PublicKey: ed25519.PublicKey(publicKey),
|
||||
Guilds: guildsService,
|
||||
Router: NewInteractionRouter(),
|
||||
OK: len(publicKey) != 0,
|
||||
PublicKey: ed25519.PublicKey(publicKey),
|
||||
PublicBaseURL: publicBaseURL,
|
||||
Guilds: guildsService,
|
||||
Router: NewInteractionRouter(),
|
||||
OK: len(publicKey) != 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -68,6 +76,32 @@ func (i *Interactions) PostHandler(c fiber.Ctx) error {
|
|||
return types.NewAPIError(http.StatusNotImplemented, "not implemented").Send(c)
|
||||
}
|
||||
|
||||
// func (i *Interactions) Respond(ix Interaction, ir InteractionResponse) error {
|
||||
// i.Guilds
|
||||
// }
|
||||
func (i *Interactions) CommandsMap() map[string]string {
|
||||
if i.commandsMentions != nil {
|
||||
return i.commandsMentions
|
||||
}
|
||||
|
||||
dc := i.Guilds.Client()
|
||||
req := discord.NewRequest("GET", utils.J("applications", i.Guilds.Client().GetClientID(), "commands"))
|
||||
dc.BotAuth(req)
|
||||
|
||||
resp, err := dc.Do(req)
|
||||
if err != nil {
|
||||
log.Println("interactions: commands map fetch failed")
|
||||
return nil
|
||||
}
|
||||
|
||||
i.commandsMap = []InteractionCommand{}
|
||||
err = discord.OutputResponse(resp, &i.commandsMap)
|
||||
if err != nil {
|
||||
log.Println("interactions: commands map parse failed")
|
||||
return nil
|
||||
}
|
||||
|
||||
i.commandsMentions = map[string]string{}
|
||||
for _, command := range i.commandsMap {
|
||||
i.commandsMentions[command.Name] = fmt.Sprintf("</%s:%s>", command.ID, command.Name)
|
||||
}
|
||||
|
||||
return i.commandsMentions
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue