fix issues with empty perms
This commit is contained in:
		
							parent
							
								
									81ac111e71
								
							
						
					
					
						commit
						7fa6c35a31
					
				
					 2 changed files with 23 additions and 2 deletions
				
			
		| 
						 | 
					@ -109,6 +109,9 @@ func GetSortedChannels(guildId string, withCategories bool, withPrivate bool) []
 | 
				
			||||||
      perms := discord.CalcOverwrites(*guild, channel, *selfMember)
 | 
					      perms := discord.CalcOverwrites(*guild, channel, *selfMember)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      private := !perms.Has(discord.PermissionViewChannel)
 | 
					      private := !perms.Has(discord.PermissionViewChannel)
 | 
				
			||||||
 | 
					      if perms == 0 {
 | 
				
			||||||
 | 
					        private = false
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      if private && !withPrivate {
 | 
					      if private && !withPrivate {
 | 
				
			||||||
        continue
 | 
					        continue
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					@ -192,6 +195,9 @@ func GetSortedChannels(guildId string, withCategories bool, withPrivate bool) []
 | 
				
			||||||
      perms := discord.CalcOverwrites(*guild, channel, *selfMember)
 | 
					      perms := discord.CalcOverwrites(*guild, channel, *selfMember)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      private := !perms.Has(discord.PermissionViewChannel)
 | 
					      private := !perms.Has(discord.PermissionViewChannel)
 | 
				
			||||||
 | 
					      if perms == 0 {
 | 
				
			||||||
 | 
					        private = false
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
      if private && !withPrivate {
 | 
					      if private && !withPrivate {
 | 
				
			||||||
        continue
 | 
					        continue
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
| 
						 | 
					@ -247,6 +253,10 @@ func ListChannelsCommand() {
 | 
				
			||||||
    perms := discord.CalcOverwrites(*guild, channel, *selfMember)
 | 
					    perms := discord.CalcOverwrites(*guild, channel, *selfMember)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private := !perms.Has(discord.PermissionViewChannel)
 | 
					    private := !perms.Has(discord.PermissionViewChannel)
 | 
				
			||||||
 | 
					    if perms == 0 {
 | 
				
			||||||
 | 
					      private = false
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
    category := channel.Type == discord.GuildCategory
 | 
					    category := channel.Type == discord.GuildCategory
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    catLen := 0
 | 
					    catLen := 0
 | 
				
			||||||
| 
						 | 
					@ -272,6 +282,9 @@ func ListChannelsCommand() {
 | 
				
			||||||
    perms := discord.CalcOverwrites(*guild, channel, *selfMember)
 | 
					    perms := discord.CalcOverwrites(*guild, channel, *selfMember)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private := !perms.Has(discord.PermissionViewChannel)
 | 
					    private := !perms.Has(discord.PermissionViewChannel)
 | 
				
			||||||
 | 
					    if perms == 0 {
 | 
				
			||||||
 | 
					        private = false
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    category := channel.Type == discord.GuildCategory
 | 
					    category := channel.Type == discord.GuildCategory
 | 
				
			||||||
    topic := REGEX_EMOTE.ReplaceAllString(channel.Topic, ":$1:")
 | 
					    topic := REGEX_EMOTE.ReplaceAllString(channel.Topic, ":$1:")
 | 
				
			||||||
    topic = strings.ReplaceAll(topic, "\n", " ")
 | 
					    topic = strings.ReplaceAll(topic, "\n", " ")
 | 
				
			||||||
| 
						 | 
					@ -368,7 +381,11 @@ func ListUsersCommand() {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    perms := discord.CalcOverwrites(*guild, *channel, *member)
 | 
					    perms := discord.CalcOverwrites(*guild, *channel, *member)
 | 
				
			||||||
    if !perms.Has(discord.PermissionViewChannel) {
 | 
					    private := !perms.Has(discord.PermissionViewChannel)
 | 
				
			||||||
 | 
					    if perms == 0 {
 | 
				
			||||||
 | 
					      private = false
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    if private {
 | 
				
			||||||
      continue
 | 
					      continue
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,8 +50,12 @@ func SendMode() {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  perms := discord.CalcOverwrites(*guild, *channel, *selfMember)
 | 
					  perms := discord.CalcOverwrites(*guild, *channel, *selfMember)
 | 
				
			||||||
 | 
					  cannotSend := !perms.Has(discord.PermissionSendMessages)
 | 
				
			||||||
 | 
					  if perms == 0 {
 | 
				
			||||||
 | 
					    cannotSend = false
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if !perms.Has(discord.PermissionSendMessages) {
 | 
					  if cannotSend {
 | 
				
			||||||
    fmt.Print("<you do not have permission to send messages here>\n\r")
 | 
					    fmt.Print("<you do not have permission to send messages here>\n\r")
 | 
				
			||||||
    return
 | 
					    return
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue