Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3: Inconsistent channel permission values for large guilds between sessions #413

Open
Cynosphere opened this issue Nov 20, 2023 · 9 comments

Comments

@Cynosphere
Copy link

Every other session ends up with channels in a specific large guild not having permissions (returning 0). The three other smaller guilds the account is in do not have this issue.

I have triaged with another one of my bot accounts in that guild running Dysnomia, targeting that account to check permissions across all channels and it shows correct values.

Additional context: ningen is used

@diamondburned
Copy link
Owner

How are you getting channel permissions? What's your code?

@Cynosphere
Copy link
Author

for _, channel := range guildChannels {
  if channel.Type != discord.GuildText && channel.Type != discord.GuildAnnouncement {
    continue
  }

  private := false

  if channel.ParentID.IsValid() {
    category, err := client.ChannelStore.Channel(channel.ParentID)
    if err == nil {
      perms := discord.CalcOverwrites(*guild, *category, *selfMember)
      private = !perms.Has(discord.PermissionViewChannel)
    }
  }

  if private {
    perms := discord.CalcOverwrites(*guild, channel, *selfMember)
    private = !perms.Has(discord.PermissionViewChannel)
  }

  if private && !withPrivate {
    continue
  }

  // ...
}

@diamondburned
Copy link
Owner

CalcOverwrites will not try to fetch missing permissions from the given channel. You must use client.Permissions to fetch that. Ideally, CalcOverwrites should not even be used at all.

@Cynosphere
Copy link
Author

client.Permissions is consistently returning 0 now when it should be returning 401295005309505 for most of the channels.

@diamondburned
Copy link
Owner

What does client.Client.Permissions return? (Make sure that client.Client is specifically of type *api.Client.)

@Cynosphere
Copy link
Author

*api.Client does not seem to have a Permissions function

@diamondburned
Copy link
Owner

Sorry, try client.Client.Channel and check its permissions. Also note that these functions don't handle carrying over category permissions.

@Cynosphere
Copy link
Author

The permission results seems to be inverted with using !channel.SelfPermissions.Has(discord.PermissionViewChannel), where it thinks the private channels are the ones that the account can see. This is also way too slow for my liking.

I did make my own version of client.Permissions to debug with, and the root cause seems to be guild.Roles being empty.

@diamondburned
Copy link
Owner

diamondburned commented Nov 20, 2023

Hmm, so https://github.com/diamondburned/arikawa/blob/v3.3.3/state/state.go#L310 should probably error out when Roles == nil then, which makes sense. (Not the function itself, but this particular branch.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants