Merge pull request #221 from iopred/permstate
Use State for UserChannelPermissions when possible.
This commit is contained in:
commit
5f6a972b91
1 changed files with 18 additions and 10 deletions
28
restapi.go
28
restapi.go
|
@ -380,15 +380,20 @@ func (s *Session) UserGuildSettingsEdit(guildID string, settings *UserGuildSetti
|
||||||
// userID : The ID of the user to calculate permissions for.
|
// userID : The ID of the user to calculate permissions for.
|
||||||
// channelID : The ID of the channel to calculate permission for.
|
// channelID : The ID of the channel to calculate permission for.
|
||||||
func (s *Session) UserChannelPermissions(userID, channelID string) (apermissions int, err error) {
|
func (s *Session) UserChannelPermissions(userID, channelID string) (apermissions int, err error) {
|
||||||
|
channel, err := s.State.Channel(channelID)
|
||||||
channel, err := s.Channel(channelID)
|
if err != nil || channel == nil {
|
||||||
if err != nil {
|
channel, err = s.Channel(channelID)
|
||||||
return
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
guild, err := s.Guild(channel.GuildID)
|
guild, err := s.State.Guild(channel.GuildID)
|
||||||
if err != nil {
|
if err != nil || guild == nil {
|
||||||
return
|
guild, err = s.Guild(channel.GuildID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if userID == guild.OwnerID {
|
if userID == guild.OwnerID {
|
||||||
|
@ -396,9 +401,12 @@ func (s *Session) UserChannelPermissions(userID, channelID string) (apermissions
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
member, err := s.GuildMember(guild.ID, userID)
|
member, err := s.State.Member(guild.ID, userID)
|
||||||
if err != nil {
|
if err != nil || member == nil {
|
||||||
return
|
member, err = s.GuildMember(guild.ID, userID)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, role := range guild.Roles {
|
for _, role := range guild.Roles {
|
||||||
|
|
Loading…
Reference in a new issue