effectivePermissionForRole method

Future<Permissions> effectivePermissionForRole(
  1. Role role
)

Returns effective permissions for role to this channel including channel overrides.

Implementation

Future<Permissions> effectivePermissionForRole(Role role) async {
  if (role.guild != this.guild) {
    return Permissions.empty();
  }

  final guildInstance = await this.guild.getOrDownload();

  var permissions = role.permissions.raw | guildInstance.everyoneRole.permissions.raw;

  // TODO: NNBD: try-catch in where
  try {
    final overEveryone = this.permissionOverrides.firstWhere((f) => f.id == guildInstance.everyoneRole.id);

    permissions &= ~overEveryone.deny;
    permissions |= overEveryone.allow;
    // ignore: avoid_catches_without_on_clauses, empty_catches
  } on Exception {}

  try {
    final overRole = this.permissionOverrides.firstWhere((f) => f.id == role.id);

    permissions &= ~overRole.deny;
    permissions |= overRole.allow;
    // ignore: avoid_catches_without_on_clauses, empty_catches
  } on Exception {}

  return Permissions.fromInt(permissions);
}