当前位置: 首页>>代码示例>>C#>>正文


C# Channel.InvalidatePermissionsCache方法代码示例

本文整理汇总了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) { }
		}
开发者ID:cillas,项目名称:Discord.Net,代码行数:23,代码来源:DiscordClient.API.cs

示例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);
			}
		}
开发者ID:cillas,项目名称:Discord.Net,代码行数:52,代码来源:DiscordClient.API.cs


注:本文中的Discord.Channel.InvalidatePermissionsCache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。