session: Add AddInteractionHandlerFunc

Also remove session.AddInteractionHandler (exported func).
This commit is contained in:
diamondburned 2022-08-23 13:46:42 -07:00
parent 75ff7342b1
commit 91b2c6c840
No known key found for this signature in database
GPG Key ID: D78C4471CE776659
1 changed files with 9 additions and 9 deletions

View File

@ -309,21 +309,21 @@ func (s *Session) WithContext(ctx context.Context) *Session {
// AddInteractionHandler adds an interaction handler function to be handled with
// the gateway and the API client. Use this as a compatibility layer for bots
// that support both methods of hosting.
func (s *Session) AddInteractionHandler(f webhook.InteractionHandler) {
func (s *Session) AddInteractionHandler(h webhook.InteractionHandler) {
// State doesn't override this, but it doesn't touch
// InteractionCreateEvents, so it shouldn't need to.
AddInteractionHandler(s.Handler, s.Client, f)
}
// AddInteractionHandler is used by (*Session).AddInteractionHandler.
func AddInteractionHandler(h *handler.Handler, c *api.Client, f webhook.InteractionHandler) {
h.AddHandler(func(ev *gateway.InteractionCreateEvent) {
if resp := f.HandleInteraction(&ev.InteractionEvent); resp != nil {
c.RespondInteraction(ev.ID, ev.Token, *resp)
s.AddHandler(func(ev *gateway.InteractionCreateEvent) {
if resp := h.HandleInteraction(&ev.InteractionEvent); resp != nil {
s.RespondInteraction(ev.ID, ev.Token, *resp)
}
})
}
// AddInteractionHandlerFunc is a function variant of AddInteractionHandler.
func (s *Session) AddInteractionHandlerFunc(f webhook.InteractionHandlerFunc) {
s.AddInteractionHandler(f)
}
// Close closes the underlying Websocket connection, invalidating the session
// ID. It will send a closing frame before ending the connection, closing it
// gracefully. This will cause the bot to appear as offline instantly. To