소스 검색

Fix UserChannelPermissions

abalabahaha 8 년 전
부모
커밋
539b9d203f
2개의 변경된 파일20개의 추가작업 그리고 22개의 파일을 삭제
  1. 7 9
      restapi.go
  2. 13 13
      structs.go

+ 7 - 9
restapi.go

@@ -352,27 +352,25 @@ func (s *Session) UserChannelPermissions(userID, channelID string) (apermissions
 		return
 	}
 
-	apermissions = 0
-
 	for _, role := range guild.Roles {
 		for _, roleID := range member.Roles {
 			if role.ID == roleID {
-				apermissions = apermissions | role.Permissions
+				apermissions |= role.Permissions
 				break
 			}
 		}
 	}
 
-	if apermissions & (PermissionManageRoles) > 0 {
-		apermissions = PermissionAll
+	if apermissions & PermissionManageRoles > 0 {
+		apermissions |= PermissionAll
 	}
 
 	// Member overwrites can override role overrides, so do two passes
 	for _, overwrite := range channel.PermissionOverwrites {
 		for _, roleID := range member.Roles {
 			if overwrite.Type == "role" && roleID == overwrite.ID {
-				apermissions = apermissions & ^overwrite.Deny
-				apermissions = apermissions | overwrite.Allow
+				apermissions &= ^overwrite.Deny
+				apermissions |= overwrite.Allow
 				break
 			}
 		}
@@ -380,8 +378,8 @@ func (s *Session) UserChannelPermissions(userID, channelID string) (apermissions
 
 	for _, overwrite := range channel.PermissionOverwrites {
 		if overwrite.Type == "member" && overwrite.ID == userID {
-			apermissions = apermissions & ^overwrite.Deny
-			apermissions = apermissions | overwrite.Allow
+			apermissions &= ^overwrite.Deny
+			apermissions |= overwrite.Allow
 			break
 		}
 	}

+ 13 - 13
structs.go

@@ -366,19 +366,6 @@ type State struct {
 	MaxMessageCount int
 }
 
-// Constants for the different bit offsets of general permissions
-const (
-	PermissionCreateInstantInvite = 1 << iota
-	PermissionKickMembers
-	PermissionBanMembers
-	PermissionManageRoles
-	PermissionManageChannels
-	PermissionManageServer
-
-	PermissionAll        = 66321471
-	PermissionAllChannel = 66321433
-)
-
 // Constants for the different bit offsets of text channel permissions
 const (
 	PermissionReadMessages = 1 << (iota + 10)
@@ -399,4 +386,17 @@ const (
 	PermissionVoiceDeafenMembers
 	PermissionVoiceMoveMembers
 	PermissionVoiceUseVAD
+)
+
+// Constants for the different bit offsets of general permissions
+const (
+	PermissionCreateInstantInvite = 1 << iota
+	PermissionKickMembers
+	PermissionBanMembers
+	PermissionManageRoles
+	PermissionManageChannels
+	PermissionManageServer
+
+	PermissionAllChannel = PermissionReadMessages | PermissionSendMessages | PermissionSendTTSMessages | PermissionManageMessages | PermissionEmbedLinks | PermissionAttachFiles | PermissionReadMessageHistory | PermissionMentionEveryone | PermissionVoiceConnect | PermissionVoiceSpeak | PermissionVoiceMuteMembers | PermissionVoiceDeafenMembers | PermissionVoiceMoveMembers | PermissionVoiceUseVAD | PermissionCreateInstantInvite | PermissionManageRoles | PermissionManageChannels
+	PermissionAll        = PermissionAllChannel | PermissionKickMembers | PermissionBanMembers | PermissionManageServer
 )