added unknown event handler.

This commit is contained in:
5elenay 2021-08-27 11:02:07 +03:00
parent 6554800a09
commit 02e22d0196
2 changed files with 13 additions and 0 deletions

View File

@ -29,6 +29,7 @@ type Client struct {
OnChannelCreateFunctions []func(channel *Channel)
OnChannelUpdateFunctions []func(channel_id, clear string, payload map[string]interface{})
OnChannelDeleteFunctions []func(channel_id string)
OnUnknownEventFunctions []func(message string)
}
// Client cache struct.
@ -83,6 +84,11 @@ func (c *Client) OnChannelDelete(fn func(channel_id string)) {
c.OnChannelDeleteFunctions = append(c.OnChannelDeleteFunctions, fn)
}
// On unknown event will run when client gets a unknown event.
func (c *Client) OnUnknownEvent(fn func(message string)) {
c.OnUnknownEventFunctions = append(c.OnUnknownEventFunctions, fn)
}
// Fetch a channel by Id.
func (c *Client) FetchChannel(id string) (*Channel, error) {
channel := &Channel{}

View File

@ -179,6 +179,13 @@ func (c *Client) handleEvents(rawData *struct {
for _, i := range c.OnChannelDeleteFunctions {
i(data.ChannelId)
}
} else {
// Unknown Event
if c.OnUnknownEventFunctions != nil {
for _, i := range c.OnUnknownEventFunctions {
i(message)
}
}
}
}