From f84172e30a5de02e9259a9e28b0609de28b3ebd5 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Fri, 3 Mar 2017 23:42:15 -0600 Subject: [PATCH 1/2] Minor edit to socket client, finished rest implementation --- src/Discord.Net.Rest/ClientHelper.cs | 6 +++++ src/Discord.Net.Rest/DiscordRestClient.cs | 3 +++ .../Entities/Users/RestRelationship.cs | 26 +++++++++++++++++++ .../Entities/Users/RestUser.cs | 22 +++++----------- .../DiscordSocketClient.cs | 6 +++++ 5 files changed, 48 insertions(+), 15 deletions(-) create mode 100644 src/Discord.Net.Rest/Entities/Users/RestRelationship.cs diff --git a/src/Discord.Net.Rest/ClientHelper.cs b/src/Discord.Net.Rest/ClientHelper.cs index 456362be6..25a84802e 100644 --- a/src/Discord.Net.Rest/ClientHelper.cs +++ b/src/Discord.Net.Rest/ClientHelper.cs @@ -128,5 +128,11 @@ namespace Discord.Rest var models = await client.ApiClient.GetVoiceRegionsAsync().ConfigureAwait(false); return models.Select(x => RestVoiceRegion.Create(client, x)).Where(x => x.Id == id).FirstOrDefault(); } + + public static async Task> GetRelationshipsAsync(BaseDiscordClient client) + { + var models = await client.ApiClient.GetRelationshipsAsync().ConfigureAwait(false); + return models.Select(r => RestRelationship.Create(client, r)).ToImmutableArray(); + } } } diff --git a/src/Discord.Net.Rest/DiscordRestClient.cs b/src/Discord.Net.Rest/DiscordRestClient.cs index 0ff1a4821..5163e7613 100644 --- a/src/Discord.Net.Rest/DiscordRestClient.cs +++ b/src/Discord.Net.Rest/DiscordRestClient.cs @@ -89,6 +89,9 @@ namespace Discord.Rest public Task GetVoiceRegionAsync(string id) => ClientHelper.GetVoiceRegionAsync(this, id); + public Task> GetRelationshipsAsync() + => ClientHelper.GetRelationshipsAsync(this); + //IDiscordClient async Task IDiscordClient.GetApplicationInfoAsync() => await GetApplicationInfoAsync().ConfigureAwait(false); diff --git a/src/Discord.Net.Rest/Entities/Users/RestRelationship.cs b/src/Discord.Net.Rest/Entities/Users/RestRelationship.cs new file mode 100644 index 000000000..7061969fe --- /dev/null +++ b/src/Discord.Net.Rest/Entities/Users/RestRelationship.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Model = Discord.API.Relationship; + +namespace Discord.Rest +{ + public class RestRelationship : IRelationship + { + public RelationshipType Type { get; internal set; } + + public IUser User { get; internal set; } + + internal RestRelationship(RelationshipType type, IUser user) + { + Type = type; + User = user; + } + + internal static RestRelationship Create(BaseDiscordClient discord, Model model) + { + RestUser user = RestUser.Create(discord, model.User); + return new RestRelationship(model.Type, user); + } + } +} diff --git a/src/Discord.Net.Rest/Entities/Users/RestUser.cs b/src/Discord.Net.Rest/Entities/Users/RestUser.cs index c98f0c703..7e3cdb4fd 100644 --- a/src/Discord.Net.Rest/Entities/Users/RestUser.cs +++ b/src/Discord.Net.Rest/Entities/Users/RestUser.cs @@ -53,26 +53,18 @@ namespace Discord.Rest public override string ToString() => $"{Username}#{Discriminator}"; private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; + + public Task AddFriendAsync(RequestOptions options = null) + => Discord.ApiClient.AddFriendAsync(Id, options); + public Task BlockUserAsync(RequestOptions options = null) + => Discord.ApiClient.BlockUserAsync(Id, options); + public Task RemoveRelationshipAsync(RequestOptions options = null) + => Discord.ApiClient.RemoveRelationshipAsync(Id, options); //IUser Task IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) => 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/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index c3db1b379..de4e7c6f4 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -272,6 +272,9 @@ namespace Discord.WebSocket public Task GetInviteAsync(string inviteId) => ClientHelper.GetInviteAsync(this, inviteId); + public Task> GetRelationshipsAsync() + => Task.FromResult(State.Relationships); + /// public SocketUser GetUser(ulong id) { @@ -1730,5 +1733,8 @@ namespace Discord.WebSocket => await StartAsync().ConfigureAwait(false); async Task IDiscordClient.StopAsync() => await StopAsync().ConfigureAwait(false); + + async Task> IDiscordClient.GetRelationshipsAsync() + => await GetRelationshipsAsync(); } } From ed71305113b0057143005ca65450318c6a755fd6 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Fri, 3 Mar 2017 23:53:12 -0600 Subject: [PATCH 2/2] Rpc users can't be friends :( Or at least I don't think... --- src/Discord.Net.Rpc/Entities/Users/RpcUser.cs | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/Discord.Net.Rpc/Entities/Users/RpcUser.cs b/src/Discord.Net.Rpc/Entities/Users/RpcUser.cs index e091d5c5e..86524b721 100644 --- a/src/Discord.Net.Rpc/Entities/Users/RpcUser.cs +++ b/src/Discord.Net.Rpc/Entities/Users/RpcUser.cs @@ -55,19 +55,11 @@ namespace Discord.Rpc 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(); - } + Task IUser.AddFriendAsync(RequestOptions options) + => throw new NotSupportedException(); + Task IUser.BlockUserAsync(RequestOptions options) + => throw new NotSupportedException(); + Task IUser.RemoveRelationshipAsync(RequestOptions options) + => throw new NotSupportedException(); } }