Compare commits
3 commits
fe836f61dc
...
5e6d804380
Author | SHA1 | Date | |
---|---|---|---|
5e6d804380 | |||
b2b4ac358c | |||
4f21449ffe |
3 changed files with 84 additions and 89 deletions
|
@ -107,25 +107,21 @@ func GetSortedChannels(guildId string, withCategories bool, withPrivate bool) []
|
|||
continue
|
||||
}
|
||||
|
||||
perms := lib.CalcPermissionsFixed(*guild, channel, *selfMember)
|
||||
private := false
|
||||
|
||||
private := !perms.Has(discord.PermissionViewChannel)
|
||||
fmt.Print(channel.Name, " ", perms, " ", private, "\n\r")
|
||||
if perms == 0 {
|
||||
if channel.ParentID.IsValid() {
|
||||
category, err := client.ChannelStore.Channel(channel.ParentID)
|
||||
if err == nil {
|
||||
perms := lib.CalcPermissionsFixed(*guild, *category, *selfMember)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
fmt.Print(category.Name, " ", perms, " ", private, "\n\r")
|
||||
if perms == 0 {
|
||||
private = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
private = false
|
||||
if channel.ParentID.IsValid() {
|
||||
category, err := client.ChannelStore.Channel(channel.ParentID)
|
||||
if err == nil {
|
||||
perms := lib.ChannelPermissionsOf(*guild, *category, *selfMember)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
}
|
||||
}
|
||||
|
||||
if private {
|
||||
perms := lib.ChannelPermissionsOf(*guild, channel, *selfMember)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
}
|
||||
|
||||
if private && !withPrivate {
|
||||
continue
|
||||
}
|
||||
|
@ -206,23 +202,21 @@ func GetSortedChannels(guildId string, withCategories bool, withPrivate bool) []
|
|||
continue
|
||||
}
|
||||
|
||||
perms := lib.CalcPermissionsFixed(*guild, channel, *selfMember)
|
||||
private := false
|
||||
|
||||
private := !perms.Has(discord.PermissionViewChannel)
|
||||
if perms == 0 {
|
||||
if channel.ParentID.IsValid() {
|
||||
category, err := client.ChannelStore.Channel(channel.ParentID)
|
||||
if err == nil {
|
||||
perms := lib.CalcPermissionsFixed(*guild, *category, *selfMember)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
if perms == 0 {
|
||||
private = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
private = false
|
||||
if channel.ParentID.IsValid() {
|
||||
category, err := client.ChannelStore.Channel(channel.ParentID)
|
||||
if err == nil {
|
||||
perms := lib.ChannelPermissionsOf(*guild, *category, *selfMember)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
}
|
||||
}
|
||||
|
||||
if private {
|
||||
perms := lib.ChannelPermissionsOf(*guild, channel, *selfMember)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
}
|
||||
|
||||
if private && !withPrivate {
|
||||
continue
|
||||
}
|
||||
|
@ -275,24 +269,21 @@ func ListChannelsCommand() {
|
|||
channels := GetSortedChannels(currentGuild, true, false)
|
||||
|
||||
for _, channel := range channels {
|
||||
perms := lib.CalcPermissionsFixed(*guild, channel, *selfMember)
|
||||
private := false
|
||||
|
||||
private := !perms.Has(discord.PermissionViewChannel)
|
||||
if perms == 0 {
|
||||
if channel.ParentID.IsValid() {
|
||||
category, err := client.ChannelStore.Channel(channel.ParentID)
|
||||
if err == nil {
|
||||
perms := lib.CalcPermissionsFixed(*guild, *category, *selfMember)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
if perms == 0 {
|
||||
private = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
private = false
|
||||
if channel.ParentID.IsValid() {
|
||||
category, err := client.ChannelStore.Channel(channel.ParentID)
|
||||
if err == nil {
|
||||
perms := lib.ChannelPermissionsOf(*guild, *category, *selfMember)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if private {
|
||||
perms := lib.ChannelPermissionsOf(*guild, channel, *selfMember)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
}
|
||||
|
||||
category := channel.Type == discord.GuildCategory
|
||||
|
||||
catLen := 0
|
||||
|
@ -315,23 +306,21 @@ func ListChannelsCommand() {
|
|||
fmt.Printf(" %*s created topic\n\r", longest, "channel-name")
|
||||
fmt.Print(strings.Repeat("-", 80) + "\n\r")
|
||||
for _, channel := range channels {
|
||||
perms := lib.CalcPermissionsFixed(*guild, channel, *selfMember)
|
||||
private := false
|
||||
|
||||
private := !perms.Has(discord.PermissionViewChannel)
|
||||
if perms == 0 {
|
||||
if channel.ParentID.IsValid() {
|
||||
category, err := client.ChannelStore.Channel(channel.ParentID)
|
||||
if err == nil {
|
||||
perms := lib.CalcPermissionsFixed(*guild, *category, *selfMember)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
if perms == 0 {
|
||||
private = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
private = false
|
||||
if channel.ParentID.IsValid() {
|
||||
category, err := client.ChannelStore.Channel(channel.ParentID)
|
||||
if err == nil {
|
||||
perms := lib.ChannelPermissionsOf(*guild, *category, *selfMember)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
}
|
||||
}
|
||||
|
||||
if private {
|
||||
perms := lib.ChannelPermissionsOf(*guild, channel, *selfMember)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
}
|
||||
|
||||
category := channel.Type == discord.GuildCategory
|
||||
topic := REGEX_EMOTE.ReplaceAllString(channel.Topic, ":$1:")
|
||||
topic = strings.ReplaceAll(topic, "\n", " ")
|
||||
|
@ -427,25 +416,19 @@ func ListUsersCommand() {
|
|||
continue
|
||||
}
|
||||
|
||||
perms := lib.CalcPermissionsFixed(*guild, *channel, *member)
|
||||
private := false
|
||||
|
||||
private := !perms.Has(discord.PermissionViewChannel)
|
||||
if perms == 0 {
|
||||
if channel.ParentID.IsValid() {
|
||||
category, err := client.ChannelStore.Channel(channel.ParentID)
|
||||
if err == nil {
|
||||
perms := lib.CalcPermissionsFixed(*guild, *category, *member)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
if perms == 0 {
|
||||
private = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
private = false
|
||||
if channel.ParentID.IsValid() {
|
||||
category, err := client.ChannelStore.Channel(channel.ParentID)
|
||||
if err == nil {
|
||||
perms := lib.ChannelPermissionsOf(*guild, *category, *member)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
}
|
||||
}
|
||||
|
||||
if private {
|
||||
continue
|
||||
perms := lib.ChannelPermissionsOf(*guild, *channel, *member)
|
||||
private = !perms.Has(discord.PermissionViewChannel)
|
||||
}
|
||||
|
||||
length := utf8.RuneCountInString(member.User.Username) + 3
|
||||
|
|
|
@ -54,23 +54,21 @@ func SendMode() {
|
|||
return
|
||||
}
|
||||
|
||||
perms := lib.CalcPermissionsFixed(*guild, *channel, *selfMember)
|
||||
cannotSend := !perms.Has(discord.PermissionSendMessages)
|
||||
if perms == 0 {
|
||||
if channel.ParentID.IsValid() {
|
||||
category, err := client.ChannelStore.Channel(channel.ParentID)
|
||||
if err == nil {
|
||||
perms := lib.CalcPermissionsFixed(*guild, *category, *selfMember)
|
||||
cannotSend = perms.Has(discord.PermissionSendMessages)
|
||||
if perms == 0 {
|
||||
cannotSend = false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cannotSend = false
|
||||
cannotSend := false
|
||||
|
||||
if channel.ParentID.IsValid() {
|
||||
category, err := client.ChannelStore.Channel(channel.ParentID)
|
||||
if err == nil {
|
||||
perms := lib.ChannelPermissionsOf(*guild, *category, *selfMember)
|
||||
cannotSend = !perms.Has(discord.PermissionSendMessages)
|
||||
}
|
||||
}
|
||||
|
||||
if cannotSend {
|
||||
perms := lib.ChannelPermissionsOf(*guild, *channel, *selfMember)
|
||||
cannotSend = !perms.Has(discord.PermissionSendMessages)
|
||||
}
|
||||
|
||||
if cannotSend {
|
||||
fmt.Print("<you do not have permission to send messages here>\n\r")
|
||||
return
|
||||
|
|
16
lib/util.go
16
lib/util.go
|
@ -2,7 +2,7 @@ package lib
|
|||
|
||||
import "github.com/diamondburned/arikawa/v3/discord"
|
||||
|
||||
func CalcPermissionsFixed(guild discord.Guild, channel discord.Channel, member discord.Member) discord.Permissions {
|
||||
func GuildPermissionsOf(guild discord.Guild, member discord.Member) discord.Permissions {
|
||||
if guild.OwnerID == member.User.ID {
|
||||
return discord.PermissionAll
|
||||
}
|
||||
|
@ -16,6 +16,10 @@ func CalcPermissionsFixed(guild discord.Guild, channel discord.Channel, member d
|
|||
}
|
||||
}
|
||||
|
||||
if perm.Has(discord.PermissionAdministrator) {
|
||||
return discord.PermissionAll
|
||||
}
|
||||
|
||||
for _, role := range guild.Roles {
|
||||
for _, id := range member.RoleIDs {
|
||||
if id == role.ID {
|
||||
|
@ -28,6 +32,16 @@ func CalcPermissionsFixed(guild discord.Guild, channel discord.Channel, member d
|
|||
return discord.PermissionAll
|
||||
}
|
||||
|
||||
return perm
|
||||
}
|
||||
|
||||
func ChannelPermissionsOf(guild discord.Guild, channel discord.Channel, member discord.Member) discord.Permissions {
|
||||
perm := GuildPermissionsOf(guild, member)
|
||||
|
||||
if perm.Has(discord.PermissionAdministrator) {
|
||||
return discord.PermissionAll
|
||||
}
|
||||
|
||||
for _, overwrite := range channel.Overwrites {
|
||||
if discord.GuildID(overwrite.ID) == guild.ID {
|
||||
perm &= ^overwrite.Deny
|
||||
|
|
Loading…
Reference in a new issue