コード例 #1
0
 internal PermissionOverwrite(PermissionTarget targetType, ulong targetId, uint allow, uint deny)
 {
     TargetType  = targetType;
     TargetId    = targetId;
     Permissions = new DualChannelPermissions(allow, deny);
     Permissions.Lock();
 }
コード例 #2
0
ファイル: Channel.cs プロジェクト: vasyaabr/Discord.Net
        internal void Update(APIChannel model)
        {
            if (!IsPrivate && model.Name != null)
            {
                Name = model.Name;
            }
            if (model.Type != null)
            {
                Type = model.Type;
            }
            if (model.Position != null)
            {
                Position = model.Position.Value;
            }
            if (model.Topic != null)
            {
                Topic = model.Topic;
            }
            if (model.Recipient != null)
            {
                Recipient.Update(model.Recipient);
                Name = $"@{Recipient}";
            }

            if (model.PermissionOverwrites != null)
            {
                _permissionOverwrites = model.PermissionOverwrites
                                        .Select(x => new PermissionOverwrite(PermissionTarget.FromString(x.Type), x.Id, x.Allow, x.Deny))
                                        .ToDictionary(x => x.TargetId);
                UpdatePermissions();
            }
        }
コード例 #3
0
ファイル: Channel.cs プロジェクト: ElAfroNinja/Discord.Net
 internal PermissionOverwrite(PermissionTarget targetType, ulong targetId, uint allow, uint deny)
 {
     TargetType = targetType;
     TargetId = targetId;
     Permissions = new DualChannelPermissions(allow, deny);
     Permissions.Lock();
 }
コード例 #4
0
		private async Task RemoveChannelPermissions(Channel channel, string userOrRoleId, PermissionTarget targetType)
		{
			try
			{
				var perms = channel.PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != userOrRoleId).FirstOrDefault();
				await _api.DeleteChannelPermissions(channel.Id, userOrRoleId).ConfigureAwait(false);
			}
			catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
		}
コード例 #5
0
ファイル: Channel.cs プロジェクト: hermanocabral/Discord.Net
			internal PermissionOverwrite(PermissionTarget targetType, string targetId, uint allow, uint deny)
			{
				TargetType = targetType;
				TargetId = targetId;
				Allow = new ChannelPermissions(allow);
				Allow.Lock();
				Deny = new ChannelPermissions(deny);
				Deny.Lock();
			}
コード例 #6
0
ファイル: Channel.cs プロジェクト: hermanocabral/Discord.Net
 internal PermissionOverwrite(PermissionTarget targetType, string targetId, uint allow, uint deny)
 {
     TargetType = targetType;
     TargetId   = targetId;
     Allow      = new ChannelPermissions(allow);
     Allow.Lock();
     Deny = new ChannelPermissions(deny);
     Deny.Lock();
 }
コード例 #7
0
        public static string ToString(PermissionTarget value)
        {
            switch (value)
            {
            case PermissionTarget.User: return("member");

            case PermissionTarget.Role: return("role");

            default: throw new ArgumentException("Invalid permission target", nameof(value));
            }
        }
コード例 #8
0
ファイル: Channel.cs プロジェクト: vasyaabr/Discord.Net
 private async Task RemovePermissionsRule(ulong userOrRoleId, PermissionTarget targetType)
 {
     try
     {
         var perms = PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != userOrRoleId).FirstOrDefault();
         await Client.ClientAPI.Send(new RemoveChannelPermissionsRequest(Id, userOrRoleId)).ConfigureAwait(false);
     }
     catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
     {
     }
 }
コード例 #9
0
ファイル: Channel.cs プロジェクト: vasyaabr/Discord.Net
        private Task AddPermissionsRule(ulong targetId, PermissionTarget targetType, uint allow, uint deny)
        {
            var request = new AddChannelPermissionsRequest(Id)
            {
                TargetId   = targetId,
                TargetType = targetType.Value,
                Allow      = allow,
                Deny       = deny
            };

            return(Client.ClientAPI.Send(request));
        }
コード例 #10
0
        private Task AddPermissionsRule(ulong targetId, PermissionTarget targetType, ChannelPermissions allow = null, ChannelPermissions deny = null)
        {
            var request = new AddChannelPermissionsRequest(Id)
            {
                TargetId   = targetId,
                TargetType = targetType.Value,
                Allow      = allow?.RawValue ?? 0,
                Deny       = deny?.RawValue ?? 0
            };

            return(Client.ClientAPI.Send(request));
        }
コード例 #11
0
        private Task AddOrUpdateOverwrite(ulong id, PermissionTarget type, ChannelTriStatePermissions permissions)
        {
            var request = new AddOrUpdateChannelPermissionsRequest(id)
            {
                TargetId   = id,
                TargetType = EnumConverters.ToString(type),
                Allow      = permissions.AllowValue,
                Deny       = permissions.DenyValue
            };

            return(_channel.Client.ClientAPI.Send(request));
        }
コード例 #12
0
ファイル: Channel.cs プロジェクト: hermanocabral/Discord.Net
        internal void Update(ChannelInfo model)
        {
            Update(model as ChannelReference);

            if (model.Position != null)
            {
                Position = model.Position.Value;
            }
            if (model.Topic != null)
            {
                Topic = model.Topic;
            }

            if (model.PermissionOverwrites != null)
            {
                _permissionOverwrites = model.PermissionOverwrites
                                        .Select(x => new PermissionOverwrite(PermissionTarget.FromString(x.Type), x.Id, x.Allow, x.Deny))
                                        .ToArray();
                InvalidatePermissionsCache();
            }
        }
コード例 #13
0
ファイル: Channel.cs プロジェクト: ElAfroNinja/Discord.Net
 private async Task RemovePermissionsRule(ulong userOrRoleId, PermissionTarget targetType)
 {
     try
     {
         var perms = PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != userOrRoleId).FirstOrDefault();
         await Client.ClientAPI.Send(new RemoveChannelPermissionsRequest(Id, userOrRoleId)).ConfigureAwait(false);
     }
     catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
 }
コード例 #14
0
ファイル: Channel.cs プロジェクト: ElAfroNinja/Discord.Net
 private Task AddPermissionsRule(ulong targetId, PermissionTarget targetType, ChannelPermissions allow = null, ChannelPermissions deny = null)
 {
     var request = new AddChannelPermissionsRequest(Id)
     {
         TargetId = targetId,
         TargetType = targetType.Value,
         Allow = allow?.RawValue ?? 0,
         Deny = deny?.RawValue ?? 0
     };
     return Client.ClientAPI.Send(request);
 }
コード例 #15
0
 private Task SetChannelPermissions(Channel channel, string targetId, PermissionTarget targetType, ChannelPermissions allow = null, ChannelPermissions deny = null)
 => _api.SetChannelPermissions(channel.Id, targetId, targetType.Value, allow?.RawValue ?? 0, deny?.RawValue ?? 0);
コード例 #16
0
 private async Task RemoveChannelPermissions(Channel channel, string userOrRoleId, PermissionTarget targetType)
 {
     try
     {
         var perms = channel.PermissionOverwrites.Where(x => x.TargetType != targetType || x.TargetId != userOrRoleId).FirstOrDefault();
         await _api.DeleteChannelPermissions(channel.Id, userOrRoleId).ConfigureAwait(false);
     }
     catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
     {
     }
 }
コード例 #17
0
		private Task SetChannelPermissions(Channel channel, string targetId, PermissionTarget targetType, ChannelPermissions allow = null, ChannelPermissions deny = null)
			=> _api.SetChannelPermissions(channel.Id, targetId, targetType.Value, allow?.RawValue ?? 0, deny?.RawValue ?? 0);
コード例 #18
0
ファイル: Channel.cs プロジェクト: Carbonitex/Discord.Net
 private Task AddPermissionsRule(ulong targetId, PermissionTarget targetType, uint allow, uint deny)
 {
     var request = new AddChannelPermissionsRequest(Id)
     {
         TargetId = targetId,
         TargetType = targetType.Value,
         Allow = allow,
         Deny = deny
     };
     return Client.ClientAPI.Send(request);
 }
コード例 #19
0
ファイル: Channel.cs プロジェクト: aadarshasubedi/Discord.Net
 internal PermissionRule(PermissionTarget targetType, ulong targetId, uint allow, uint deny)
 {
     TargetType  = targetType;
     TargetId    = targetId;
     Permissions = new ChannelTriStatePermissions(allow, deny);
 }
コード例 #20
0
 /// <summary> Creates a new Overwrite with provided target information and modified permissions. </summary>
 public Overwrite(ulong targetId, PermissionTarget targetType, OverwritePermissions permissions)
 {
     TargetId    = targetId;
     TargetType  = targetType;
     Permissions = permissions;
 }