diff --git a/src/Discord.Net.Core/API/Rest/BlockUserParams.cs b/src/Discord.Net.Core/API/Rest/BlockUserParams.cs deleted file mode 100644 index c169a6097..000000000 --- a/src/Discord.Net.Core/API/Rest/BlockUserParams.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Newtonsoft.Json; - -namespace Discord.API.Rest -{ - [JsonObject(MemberSerialization = MemberSerialization.OptIn)] - public class BlockUserParams - { - [JsonProperty("type")] - public RelationshipType Type { get; } = RelationshipType.Blocked; - } -} diff --git a/src/Discord.Net.Core/Discord.Net.Core.csproj b/src/Discord.Net.Core/Discord.Net.Core.csproj index 9f75d7327..d78840281 100644 --- a/src/Discord.Net.Core/Discord.Net.Core.csproj +++ b/src/Discord.Net.Core/Discord.Net.Core.csproj @@ -1,4 +1,4 @@ - + 1.0.0 rc-dev diff --git a/src/Discord.Net.Core/Entities/Users/IRelationship.cs b/src/Discord.Net.Core/Entities/Users/IRelationship.cs new file mode 100644 index 000000000..6403184e7 --- /dev/null +++ b/src/Discord.Net.Core/Entities/Users/IRelationship.cs @@ -0,0 +1,9 @@ +namespace Discord +{ + public interface IRelationship + { + RelationshipType Type { get; } + + IUser User { get; } + } +} diff --git a/src/Discord.Net.Core/Entities/Users/IUser.cs b/src/Discord.Net.Core/Entities/Users/IUser.cs index b7e807d8e..6196630a5 100644 --- a/src/Discord.Net.Core/Entities/Users/IUser.cs +++ b/src/Discord.Net.Core/Entities/Users/IUser.cs @@ -21,5 +21,12 @@ namespace Discord Task GetDMChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); /// Returns a private message channel to this user, creating one if it does not already exist. Task CreateDMChannelAsync(RequestOptions options = null); + + /// Adds this user as a friend, this will remove a block + Task AddFriendAsync(RequestOptions options = null); + /// Blocks this user, and removes friend relation + Task BlockUserAsync(RequestOptions options = null); + /// Removes the relationship of this user + Task RemoveRelationshipAsync(RequestOptions options = null); } } diff --git a/src/Discord.Net.Core/Entities/Users/RelationshipType.cs b/src/Discord.Net.Core/Entities/Users/RelationshipType.cs new file mode 100644 index 000000000..71dd3eb3c --- /dev/null +++ b/src/Discord.Net.Core/Entities/Users/RelationshipType.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Discord +{ + public enum RelationshipType + { + Friend = 1, + Blocked = 2, + IncomingPending = 3, + OutgoingPending = 4 + } +} diff --git a/src/Discord.Net.Core/IDiscordClient.cs b/src/Discord.Net.Core/IDiscordClient.cs index 620f5bde8..1d3bf3df7 100644 --- a/src/Discord.Net.Core/IDiscordClient.cs +++ b/src/Discord.Net.Core/IDiscordClient.cs @@ -31,10 +31,7 @@ namespace Discord Task GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); Task GetUserAsync(string username, string discriminator); - Task> GetRelationshipsAsync(); - Task RemoveRelationshipAsync(ulong userId); - Task AddFriendAsync(ulong userId); - Task BlockUserAsync(ulong userId); + Task> GetRelationshipsAsync(); Task> GetVoiceRegionsAsync(); Task GetVoiceRegionAsync(string id); diff --git a/src/Discord.Net.Rest/BaseDiscordClient.cs b/src/Discord.Net.Rest/BaseDiscordClient.cs index a9d71e440..f151bfab1 100644 --- a/src/Discord.Net.Rest/BaseDiscordClient.cs +++ b/src/Discord.Net.Rest/BaseDiscordClient.cs @@ -122,10 +122,7 @@ namespace Discord.Rest /// public void Dispose() => Dispose(true); - public Task> GetRelationshipsAsync() => ApiClient.GetRelationshipsAsync(); - public Task AddFriendAsync(ulong userId) => ApiClient.AddFriendAsync(userId); - public Task BlockUserAsync(ulong userId) => ApiClient.BlockUserAsync(userId); - public Task RemoveRelationshipAsync(ulong userId) => ApiClient.RemoveRelationshipAsync(userId); + public Task> GetRelationshipsAsync() => ApiClient.GetRelationshipsAsync(); //IDiscordClient ConnectionState IDiscordClient.ConnectionState => ConnectionState.Disconnected; diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 3c837da6e..05dc8a6fc 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -1030,10 +1030,10 @@ namespace Discord.API } //Relationships - public async Task> GetRelationshipsAsync(RequestOptions options = null) + public async Task> GetRelationshipsAsync(RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); - return await SendAsync>("GET", () => "users/@me/relationships", new BucketIds(), options: options).ConfigureAwait(false); + return await SendAsync>("GET", () => "users/@me/relationships", new BucketIds(), options: options).ConfigureAwait(false); } public async Task AddFriendAsync(ulong userId, RequestOptions options = null) { @@ -1047,7 +1047,7 @@ namespace Discord.API Preconditions.NotEqual(userId, 0, nameof(userId)); options = RequestOptions.CreateOrClone(options); - await SendJsonAsync("PUT", () => $"users/@me/relationships/{userId}", new BlockUserParams(), new BucketIds(), options: options).ConfigureAwait(false); + await SendJsonAsync("PUT", () => $"users/@me/relationships/{userId}", new { value = 2 }, new BucketIds(), options: options).ConfigureAwait(false); } public async Task RemoveRelationshipAsync(ulong userId, RequestOptions options = null) { diff --git a/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs b/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs index ab5ec4a3b..4ebe8ee8f 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs @@ -49,5 +49,14 @@ namespace Discord.Rest var model = await UserHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false); Update(model); } + + Task IUser.AddFriendAsync(RequestOptions options) => + throw new InvalidOperationException("You can't friend yourself!"); + + Task IUser.BlockUserAsync(RequestOptions options) => + throw new InvalidOperationException("You can't block yourself!"); + + Task IUser.RemoveRelationshipAsync(RequestOptions options) => + throw new InvalidOperationException("You don't have any relations with yourself!"); } } diff --git a/src/Discord.Net.Rest/Entities/Users/RestUser.cs b/src/Discord.Net.Rest/Entities/Users/RestUser.cs index b439fb886..c98f0c703 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestUser.cs @@ -59,5 +59,20 @@ namespace Discord.Rest => Task.FromResult(null); async Task IUser.CreateDMChannelAsync(RequestOptions options) => await CreateDMChannelAsync(options).ConfigureAwait(false); + + public Task AddFriendAsync(RequestOptions options = null) + { + throw new NotImplementedException(); + } + + public Task BlockUserAsync(RequestOptions options = null) + { + throw new NotImplementedException(); + } + + public Task RemoveRelationshipAsync(RequestOptions options = null) + { + throw new NotImplementedException(); + } } } diff --git a/src/Discord.Net.Rpc/Entities/Users/RpcUser.cs b/src/Discord.Net.Rpc/Entities/Users/RpcUser.cs index e78aee008..e091d5c5e 100644 --- a/src/Discord.Net.Rpc/Entities/Users/RpcUser.cs +++ b/src/Discord.Net.Rpc/Entities/Users/RpcUser.cs @@ -54,5 +54,20 @@ namespace Discord.Rpc => Task.FromResult(null); async Task IUser.CreateDMChannelAsync(RequestOptions options) => await CreateDMChannelAsync(options).ConfigureAwait(false); + + public Task AddFriendAsync(RequestOptions options = null) + { + throw new NotImplementedException(); + } + + public Task BlockUserAsync(RequestOptions options = null) + { + throw new NotImplementedException(); + } + + public Task RemoveRelationshipAsync(RequestOptions options = null) + { + throw new NotImplementedException(); + } } } diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketRelationship.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketRelationship.cs new file mode 100644 index 000000000..1fed00801 --- /dev/null +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketRelationship.cs @@ -0,0 +1,11 @@ +using System; + +namespace Discord.WebSocket +{ + public class SocketRelationship : IRelationship + { + public RelationshipType Type { get; private set; } + + public IUser User { get; private set; } + } +} diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs index 0f6d4e4f1..b7531ffc6 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs @@ -46,6 +46,15 @@ namespace Discord.WebSocket public Task ModifyAsync(Action func, RequestOptions options = null) => UserHelper.ModifyAsync(this, Discord, func, options); + Task IUser.AddFriendAsync(RequestOptions options) => + throw new InvalidOperationException("You can't friend yourself!"); + + Task IUser.BlockUserAsync(RequestOptions options) => + throw new InvalidOperationException("You can't block yourself!"); + + Task IUser.RemoveRelationshipAsync(RequestOptions options) => + throw new InvalidOperationException("You don't have any relations with yourself!"); + internal new SocketSelfUser Clone() => MemberwiseClone() as SocketSelfUser; } } diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs index 574e79b6e..5b47a1ad4 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs @@ -55,5 +55,20 @@ namespace Discord.WebSocket => Task.FromResult(GlobalUser.DMChannel); async Task IUser.CreateDMChannelAsync(RequestOptions options) => await CreateDMChannelAsync(options).ConfigureAwait(false); + + public Task AddFriendAsync(RequestOptions options = null) + { + throw new NotImplementedException(); + } + + public Task BlockUserAsync(RequestOptions options = null) + { + throw new NotImplementedException(); + } + + public Task RemoveRelationshipAsync(RequestOptions options = null) + { + throw new NotImplementedException(); + } } }