本文整理汇总了C#中Discord.Channel.InvalidatePermissionsCache方法的典型用法代码示例。如果您正苦于以下问题:C# Channel.InvalidatePermissionsCache方法的具体用法?C# Channel.InvalidatePermissionsCache怎么用?C# Channel.InvalidatePermissionsCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discord.Channel
的用法示例。
在下文中一共展示了Channel.InvalidatePermissionsCache方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveChannelPermissions
private async Task RemoveChannelPermissions(Channel channel, string userOrRoleId, string idType)
{
CheckReady();
if (channel == null) throw new NullReferenceException(nameof(channel));
if (userOrRoleId == null) throw new NullReferenceException(nameof(userOrRoleId));
if (idType == null) throw new NullReferenceException(nameof(idType));
try
{
var perms = channel.PermissionOverwrites.Where(x => x.TargetType != idType || x.TargetId != userOrRoleId).FirstOrDefault();
await _api.DeleteChannelPermissions(channel.Id, userOrRoleId).ConfigureAwait(false);
if (perms != null)
{
channel.PermissionOverwrites.Where(x => x.TargetType != idType || x.TargetId != userOrRoleId).ToArray();
if (idType == PermissionTarget.Role)
channel.InvalidatePermissionsCache();
else if (idType == PermissionTarget.Member)
channel.InvalidatePermissionsCache(userOrRoleId);
}
}
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
}
示例2: SetChannelPermissions
private async Task SetChannelPermissions(Channel channel, string targetId, string targetType, PackedChannelPermissions allow = null, PackedChannelPermissions deny = null)
{
CheckReady();
if (channel == null) throw new NullReferenceException(nameof(channel));
if (targetId == null) throw new NullReferenceException(nameof(targetId));
if (targetType == null) throw new NullReferenceException(nameof(targetType));
uint allowValue = allow?.RawValue ?? 0;
uint denyValue = deny?.RawValue ?? 0;
bool changed = false;
var perms = channel.PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != targetId).FirstOrDefault();
if (allowValue != 0 || denyValue != 0)
{
await _api.SetChannelPermissions(channel.Id, targetId, targetType, allowValue, denyValue);
if (perms != null)
{
perms.Allow.SetRawValueInternal(allowValue);
perms.Deny.SetRawValueInternal(denyValue);
}
else
{
var oldPerms = channel._permissionOverwrites;
var newPerms = new Channel.PermissionOverwrite[oldPerms.Length + 1];
Array.Copy(oldPerms, newPerms, oldPerms.Length);
newPerms[oldPerms.Length] = new Channel.PermissionOverwrite(targetType, targetId, allowValue, denyValue);
channel._permissionOverwrites = newPerms;
}
changed = true;
}
else
{
try
{
await _api.DeleteChannelPermissions(channel.Id, targetId);
if (perms != null)
{
channel._permissionOverwrites = channel.PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != targetId).ToArray();
changed = true;
}
}
catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
}
if (changed)
{
if (targetType == PermissionTarget.Role)
channel.InvalidatePermissionsCache();
else if (targetType == PermissionTarget.Member)
channel.InvalidatePermissionsCache(targetId);
}
}