1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-12-01 08:37:23 +00:00

Fixed Webhook Update event

This commit is contained in:
diamondburned (Forefront) 2020-01-24 21:24:33 -08:00
parent b45c0489bb
commit ea9f2c2036
5 changed files with 33 additions and 16 deletions

View file

@ -57,5 +57,5 @@ var EventCreator = map[string]func() Event{
"VOICE_STATE_UPDATE": func() Event { return new(VoiceStateUpdateEvent) },
"VOICE_SERVER_UPDATE": func() Event { return new(VoiceServerUpdateEvent) },
"WEBHOOKS_UDPATE": func() Event { return new(WebhooksUpdateEvent) },
"WEBHOOKS_UPDATE": func() Event { return new(WebhooksUpdateEvent) },
}

1
go.mod
View file

@ -3,6 +3,7 @@ module github.com/diamondburned/arikawa
go 1.13
require (
github.com/davecgh/go-spew v1.1.1
github.com/gorilla/schema v1.1.0
github.com/pkg/errors v0.8.1
github.com/sasha-s/go-csync v0.0.0-20160729053059-3bc6c8bdb3fa

View file

@ -38,6 +38,7 @@ type Handler struct {
Synchronous bool
handlers map[uint64]handler
horders []uint64
hserial uint64
hmutex sync.Mutex
}
@ -55,7 +56,13 @@ func (h *Handler) Call(ev interface{}) {
h.hmutex.Lock()
defer h.hmutex.Unlock()
for _, handler := range h.handlers {
for _, order := range h.horders {
handler, ok := h.handlers[order]
if !ok {
// This shouldn't ever happen, but we're adding this just in case.
continue
}
if handler.not(evT) {
continue
}
@ -123,18 +130,30 @@ func (h *Handler) addHandler(handler interface{}) (rm func(), err error) {
h.hmutex.Lock()
defer h.hmutex.Unlock()
// Get the current counter value and increment the counter
// Get the current counter value and increment the counter:
serial := h.hserial
h.hserial++
// Use the serial for the map
// Use the serial for the map:
h.handlers[serial] = *r
// Append the serial into the list of keys:
h.horders = append(h.horders, serial)
return func() {
h.hmutex.Lock()
defer h.hmutex.Unlock()
// Delete the handler from the map:
delete(h.handlers, serial)
// Delete the key from the orders slice:
for i, order := range h.horders {
if order == serial {
h.horders = append(h.horders[:i], h.horders[i+1:]...)
break
}
}
}, nil
}

View file

@ -57,9 +57,7 @@ func NewFromSession(s *session.Session, store Store) (*State, error) {
}
func New(token string) (*State, error) {
return NewWithStore(token, NewDefaultStore(&DefaultStoreOptions{
MaxMessages: 50,
}))
return NewWithStore(token, NewDefaultStore(nil))
}
func NewWithStore(token string, store Store) (*State, error) {

View file

@ -39,17 +39,12 @@ func NewDefaultStore(opts *DefaultStoreOptions) *DefaultStore {
}
}
return &DefaultStore{
ds := &DefaultStore{
DefaultStoreOptions: opts,
privates: map[discord.Snowflake]*discord.Channel{},
guilds: map[discord.Snowflake]*discord.Guild{},
channels: map[discord.Snowflake][]discord.Channel{},
members: map[discord.Snowflake][]discord.Member{},
presences: map[discord.Snowflake][]discord.Presence{},
messages: map[discord.Snowflake][]discord.Message{},
}
ds.Reset()
return ds
}
func (s *DefaultStore) Reset() error {
@ -60,6 +55,10 @@ func (s *DefaultStore) Reset() error {
s.privates = map[discord.Snowflake]*discord.Channel{}
s.guilds = map[discord.Snowflake]*discord.Guild{}
s.channels = map[discord.Snowflake][]discord.Channel{}
s.members = map[discord.Snowflake][]discord.Member{}
s.presences = map[discord.Snowflake][]discord.Presence{}
s.messages = map[discord.Snowflake][]discord.Message{}
return nil