static PackedServerPermissions()
		{
			None = new PackedServerPermissions();
			None.Lock();
			All = new PackedServerPermissions(Convert.ToUInt32("00000011111100111111110000111111", 2));
			All.Lock();
		}
Exemple #2
0
		internal Role(DiscordClient client, string id, string serverId, bool isEveryone)
		{
			_client = client;
			Id = id;
			ServerId = serverId;
			IsEveryone = isEveryone;
			Permissions = new PackedServerPermissions(0);
			Permissions.Lock();
			Color = new PackedColor(0);
			Color.Lock();

			if (isEveryone)
				Position = int.MinValue;
        }
		public async Task EditRole(string serverId, string roleId, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null)
		{
			CheckReady();
			if (serverId == null) throw new NullReferenceException(nameof(serverId));
			if (roleId == null) throw new NullReferenceException(nameof(roleId));
			
			var response = await _api.EditRole(serverId, roleId, name: name, 
				permissions: permissions?.RawValue, color: color?.RawValue, hoist: hoist);

			var role = _roles[response.Id];
			if (role != null)
				role.Update(response);

			if (position != null)
			{
				int oldPos = role.Position;
				int newPos = position.Value;
				int minPos;
				Role[] roles = role.Server.Roles.OrderBy(x => x.Position).ToArray();

				if (oldPos < newPos) //Moving Down
				{
					minPos = oldPos;
					for (int i = oldPos; i < newPos; i++)
						roles[i] = roles[i + 1];
					roles[newPos] = role;
				}
				else //(oldPos > newPos) Moving Up
				{
					minPos = newPos;
					for (int i = oldPos; i > newPos; i--)
						roles[i] = roles[i - 1];
					roles[newPos] = role;
				}
				await _api.ReorderRoles(role.ServerId, roles.Skip(minPos).Select(x => x.Id), minPos);
			}
		}
		public Task EditRole(Role role, string name = null, PackedServerPermissions permissions = null, PackedColor color = null, bool? hoist = null, int? position = null)
			=> EditRole(role.ServerId, role.Id, name: name, permissions: permissions, color: color, hoist: hoist, position: position);