Merge pull request #165 from b1naryth1ef/bugfix/channel-mappings
Fix channelMap not being filled for bot users/>100 guilds
This commit is contained in:
commit
4c4e8386bc
1 changed files with 13 additions and 19 deletions
32
state.go
32
state.go
|
@ -45,7 +45,6 @@ func (s *State) OnReady(r *Ready) error {
|
||||||
|
|
||||||
for _, c := range g.Channels {
|
for _, c := range g.Channels {
|
||||||
c.GuildID = g.ID
|
c.GuildID = g.ID
|
||||||
|
|
||||||
s.channelMap[c.ID] = c
|
s.channelMap[c.ID] = c
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,16 +63,17 @@ func (s *State) GuildAdd(guild *Guild) error {
|
||||||
return ErrNilState
|
return ErrNilState
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the channels to point to the right guild
|
|
||||||
for _, c := range guild.Channels {
|
|
||||||
c.GuildID = guild.ID
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the guild exists, replace it.
|
|
||||||
if g, err := s.Guild(guild.ID); err == nil {
|
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
|
// Update the channels to point to the right guild, adding them to the channelMap as we go
|
||||||
|
for _, c := range guild.Channels {
|
||||||
|
c.GuildID = guild.ID
|
||||||
|
s.channelMap[c.ID] = c
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the guild exists, replace it.
|
||||||
|
if g, ok := s.guildMap[guild.ID]; ok {
|
||||||
// If this guild already exists with data, don't stomp on props.
|
// If this guild already exists with data, don't stomp on props.
|
||||||
if g.Unavailable != nil && !*g.Unavailable {
|
if g.Unavailable != nil && !*g.Unavailable {
|
||||||
guild.Members = g.Members
|
guild.Members = g.Members
|
||||||
|
@ -86,9 +86,6 @@ func (s *State) GuildAdd(guild *Guild) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
|
|
||||||
s.Guilds = append(s.Guilds, guild)
|
s.Guilds = append(s.Guilds, guild)
|
||||||
s.guildMap[guild.ID] = guild
|
s.guildMap[guild.ID] = guild
|
||||||
|
|
||||||
|
@ -224,11 +221,11 @@ func (s *State) ChannelAdd(channel *Channel) error {
|
||||||
return ErrNilState
|
return ErrNilState
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the channel exists, replace it.
|
|
||||||
if c, err := s.Channel(channel.ID); err == nil {
|
|
||||||
s.Lock()
|
s.Lock()
|
||||||
defer s.Unlock()
|
defer s.Unlock()
|
||||||
|
|
||||||
|
// If the channel exists, replace it
|
||||||
|
if c, ok := s.channelMap[channel.ID]; ok {
|
||||||
channel.Messages = c.Messages
|
channel.Messages = c.Messages
|
||||||
channel.PermissionOverwrites = c.PermissionOverwrites
|
channel.PermissionOverwrites = c.PermissionOverwrites
|
||||||
|
|
||||||
|
@ -236,15 +233,12 @@ func (s *State) ChannelAdd(channel *Channel) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Lock()
|
|
||||||
defer s.Unlock()
|
|
||||||
|
|
||||||
if channel.IsPrivate {
|
if channel.IsPrivate {
|
||||||
s.PrivateChannels = append(s.PrivateChannels, channel)
|
s.PrivateChannels = append(s.PrivateChannels, channel)
|
||||||
} else {
|
} else {
|
||||||
guild, err := s.Guild(channel.GuildID)
|
guild, ok := s.guildMap[channel.GuildID]
|
||||||
if err != nil {
|
if !ok {
|
||||||
return err
|
return errors.New("Guild for channel not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
guild.Channels = append(guild.Channels, channel)
|
guild.Channels = append(guild.Channels, channel)
|
||||||
|
|
Loading…
Reference in a new issue