session: Add AddInteractionHandlerFunc
Also remove session.AddInteractionHandler (exported func).
This commit is contained in:
parent
75ff7342b1
commit
91b2c6c840
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue