forked from pothtonswer/discordmuffin
Merge pull request #249 from iopred/develop
Correctly merge GUILD_UPDATE events. Closes #242
This commit is contained in:
commit
9b6b657083
3 changed files with 17 additions and 6 deletions
|
@ -102,7 +102,7 @@ func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
|
||||||
// This function will be called (due to AddHandler above) every time a new
|
// This function will be called (due to AddHandler above) every time a new
|
||||||
// guild is joined.
|
// guild is joined.
|
||||||
func guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
|
func guildCreate(s *discordgo.Session, event *discordgo.GuildCreate) {
|
||||||
if event.Guild.Unavailable != nil {
|
if event.Guild.Unavailable {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
19
state.go
19
state.go
|
@ -98,16 +98,27 @@ func (s *State) GuildAdd(guild *Guild) error {
|
||||||
s.channelMap[c.ID] = c
|
s.channelMap[c.ID] = c
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the guild exists, replace it.
|
|
||||||
if g, ok := s.guildMap[guild.ID]; ok {
|
if g, ok := s.guildMap[guild.ID]; ok {
|
||||||
// If this guild already exists with data, don't stomp on props.
|
// We are about to replace `g` in the state with `guild`, but first we need to
|
||||||
if g.Unavailable != nil && !*g.Unavailable {
|
// make sure we preserve any fields that the `guild` doesn't contain from `g`.
|
||||||
|
if guild.Roles == nil {
|
||||||
|
guild.Roles = g.Roles
|
||||||
|
}
|
||||||
|
if guild.Emojis == nil {
|
||||||
|
guild.Emojis = g.Emojis
|
||||||
|
}
|
||||||
|
if guild.Members == nil {
|
||||||
guild.Members = g.Members
|
guild.Members = g.Members
|
||||||
|
}
|
||||||
|
if guild.Presences == nil {
|
||||||
guild.Presences = g.Presences
|
guild.Presences = g.Presences
|
||||||
|
}
|
||||||
|
if guild.Channels == nil {
|
||||||
guild.Channels = g.Channels
|
guild.Channels = g.Channels
|
||||||
|
}
|
||||||
|
if guild.VoiceStates == nil {
|
||||||
guild.VoiceStates = g.VoiceStates
|
guild.VoiceStates = g.VoiceStates
|
||||||
}
|
}
|
||||||
|
|
||||||
*g = *guild
|
*g = *guild
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,7 +217,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"`
|
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