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