Merge pull request #161 from b1naryth1ef/bugfix/lazy-guild-loading
Support guild lazy loading.
This commit is contained in:
commit
6101abeb27
2 changed files with 16 additions and 13 deletions
28
state.go
28
state.go
|
@ -57,24 +57,26 @@ func (s *State) GuildAdd(guild *Guild) error {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
// If the guild exists, replace it.
|
|
||||||
for i, g := range s.Guilds {
|
|
||||||
if g.ID == guild.ID {
|
|
||||||
// Don't stomp on properties that don't come in updates.
|
|
||||||
guild.Members = g.Members
|
|
||||||
guild.Presences = g.Presences
|
|
||||||
guild.Channels = g.Channels
|
|
||||||
guild.VoiceStates = g.VoiceStates
|
|
||||||
s.Guilds[i] = guild
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, update the channels to point to the right guild
|
// Otherwise, update the channels to point to the right guild
|
||||||
for _, c := range guild.Channels {
|
for _, c := range guild.Channels {
|
||||||
c.GuildID = guild.ID
|
c.GuildID = guild.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the guild exists, replace it.
|
||||||
|
for i, g := range s.Guilds {
|
||||||
|
if g.ID == guild.ID {
|
||||||
|
// If this guild already exists with data, don't stomp on props
|
||||||
|
if !g.Unavailable {
|
||||||
|
guild.Members = g.Members
|
||||||
|
guild.Presences = g.Presences
|
||||||
|
guild.Channels = g.Channels
|
||||||
|
guild.VoiceStates = g.VoiceStates
|
||||||
|
}
|
||||||
|
s.Guilds[i] = guild
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
s.Guilds = append(s.Guilds, guild)
|
s.Guilds = append(s.Guilds, guild)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,6 +178,7 @@ type Guild struct {
|
||||||
Presences []*Presence `json:"presences"`
|
Presences []*Presence `json:"presences"`
|
||||||
Channels []*Channel `json:"channels"`
|
Channels []*Channel `json:"channels"`
|
||||||
VoiceStates []*VoiceState `json:"voice_states"`
|
VoiceStates []*VoiceState `json:"voice_states"`
|
||||||
|
Unavailable bool `json:"unavailable"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A GuildParams stores all the data needed to update discord guild settings
|
// A GuildParams stores all the data needed to update discord guild settings
|
||||||
|
|
Loading…
Reference in a new issue