From e0bd3d5557c92d0b3eda7e5483dde30add2f5430 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Mon, 21 Nov 2016 10:53:44 -0600 Subject: [PATCH 01/13] Added Relation functions: * GetRelationshipsAsync() * AddFriendAsync(ulong) * BlockUserAsync(ulong) * RemoveRelationshipAsync(ulong) --- Discord.Net.sln | 36 ++++++++--------- .../API/DiscordRestApiClient.cs | 40 ++++++++++++++++--- .../API/Rest/BlockUserParams.cs | 11 +++++ src/Discord.Net.Core/IDiscordClient.cs | 7 +++- src/Discord.Net.Rest/BaseDiscordClient.cs | 5 +++ 5 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 src/Discord.Net.Core/API/Rest/BlockUserParams.cs diff --git a/Discord.Net.sln b/Discord.Net.sln index 206c5b54a..7a12f8c75 100644 --- a/Discord.Net.sln +++ b/Discord.Net.sln @@ -47,16 +47,16 @@ Global {496DB20A-A455-4D01-B6BC-90FE6D7C6B81}.Release|x86.Build.0 = Debug|Any CPU {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x64.ActiveCfg = Debug|x64 - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x64.Build.0 = Debug|x64 - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x86.ActiveCfg = Debug|x86 - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x86.Build.0 = Debug|x86 + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x64.ActiveCfg = Debug|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x64.Build.0 = Debug|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x86.ActiveCfg = Debug|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x86.Build.0 = Debug|Any CPU {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|Any CPU.ActiveCfg = Debug|Any CPU {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|Any CPU.Build.0 = Debug|Any CPU - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x64.ActiveCfg = Release|x64 - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x64.Build.0 = Release|x64 - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x86.ActiveCfg = Release|x86 - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x86.Build.0 = Release|x86 + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x64.ActiveCfg = Debug|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x64.Build.0 = Debug|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x86.ActiveCfg = Debug|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x86.Build.0 = Debug|Any CPU {BFC6DC28-0351-4573-926A-D4124244C04F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BFC6DC28-0351-4573-926A-D4124244C04F}.Debug|Any CPU.Build.0 = Debug|Any CPU {BFC6DC28-0351-4573-926A-D4124244C04F}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -95,16 +95,16 @@ Global {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Release|x86.Build.0 = Debug|Any CPU {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x64.ActiveCfg = Debug|x64 - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x64.Build.0 = Debug|x64 - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x86.ActiveCfg = Debug|x86 - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x86.Build.0 = Debug|x86 - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|Any CPU.Build.0 = Release|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x64.ActiveCfg = Release|x64 - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x64.Build.0 = Release|x64 - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x86.ActiveCfg = Release|x86 - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x86.Build.0 = Release|x86 + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x64.ActiveCfg = Debug|Any CPU + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x64.Build.0 = Debug|Any CPU + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x86.ActiveCfg = Debug|Any CPU + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x86.Build.0 = Debug|Any CPU + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|Any CPU.ActiveCfg = Debug|Any CPU + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|Any CPU.Build.0 = Debug|Any CPU + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x64.ActiveCfg = Debug|Any CPU + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x64.Build.0 = Debug|Any CPU + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x86.ActiveCfg = Debug|Any CPU + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x86.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Discord.Net.Core/API/DiscordRestApiClient.cs b/src/Discord.Net.Core/API/DiscordRestApiClient.cs index d050f12a4..02b52ec21 100644 --- a/src/Discord.Net.Core/API/DiscordRestApiClient.cs +++ b/src/Discord.Net.Core/API/DiscordRestApiClient.cs @@ -242,7 +242,7 @@ namespace Discord.API internal Task SendMultipartAsync(string method, Expression> endpointExpr, IReadOnlyDictionary multipartArgs, BucketIds ids, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) => SendMultipartAsync(method, GetEndpoint(endpointExpr), multipartArgs, GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucket, options); - public async Task SendMultipartAsync(string method, string endpoint, IReadOnlyDictionary multipartArgs, + public async Task SendMultipartAsync(string method, string endpoint, IReadOnlyDictionary multipartArgs, string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) { options = options ?? new RequestOptions(); @@ -386,7 +386,7 @@ namespace Discord.API break; } } - + //Channel Messages public async Task GetChannelMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) { @@ -622,7 +622,7 @@ namespace Discord.API Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); Preconditions.NotNullOrWhitespace(args.RegionId, nameof(args.RegionId)); options = RequestOptions.CreateOrClone(options); - + return await SendJsonAsync("POST", () => "guilds", args, new BucketIds(), options: options).ConfigureAwait(false); } public async Task DeleteGuildAsync(ulong guildId, RequestOptions options = null) @@ -830,14 +830,14 @@ namespace Discord.API { Preconditions.NotNullOrEmpty(inviteId, nameof(inviteId)); options = RequestOptions.CreateOrClone(options); - + return await SendAsync("DELETE", () => $"invites/{inviteId}", new BucketIds(), options: options).ConfigureAwait(false); } public async Task AcceptInviteAsync(string inviteId, RequestOptions options = null) { Preconditions.NotNullOrEmpty(inviteId, nameof(inviteId)); options = RequestOptions.CreateOrClone(options); - + await SendAsync("POST", () => $"invites/{inviteId}", new BucketIds(), options: options).ConfigureAwait(false); } @@ -972,6 +972,34 @@ namespace Discord.API } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } } + + //Relationships + public async Task> GetRelationshipsAsync(RequestOptions options = null) + { + options = RequestOptions.CreateOrClone(options); + return await SendAsync>("GET", () => "users/@me/relationships", new BucketIds(), options: options).ConfigureAwait(false); + } + public async Task AddFriendAsync(ulong userId, RequestOptions options = null) + { + Preconditions.NotEqual(userId, 0, nameof(userId)); + options = RequestOptions.CreateOrClone(options); + + await SendJsonAsync("PUT", () => $"users/@me/relationships/{userId}", new object(), new BucketIds(), options: options).ConfigureAwait(false); + } + public async Task BlockUserAsync(ulong userId, RequestOptions options = null) + { + 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); + } + public async Task RemoveRelationshipAsync(ulong userId, RequestOptions options = null) + { + Preconditions.NotEqual(userId, 0, nameof(userId)); + options = RequestOptions.CreateOrClone(options); + + await SendAsync("DELETE", () => $"users/@me/relationships/{userId}", new BucketIds(), options: options).ConfigureAwait(false); + } //Current User/DMs public async Task GetMyUserAsync(RequestOptions options = null) @@ -1137,7 +1165,7 @@ namespace Discord.API int argId = int.Parse(format.Substring(leftIndex + 1, rightIndex - leftIndex - 1)); string fieldName = GetFieldName(methodArgs[argId + 1]); int? mappedId; - + mappedId = BucketIds.GetIndex(fieldName); if(!mappedId.HasValue && rightIndex != endIndex && format.Length > rightIndex + 1 && format[rightIndex + 1] == '/') //Ignore the next slash rightIndex++; diff --git a/src/Discord.Net.Core/API/Rest/BlockUserParams.cs b/src/Discord.Net.Core/API/Rest/BlockUserParams.cs new file mode 100644 index 000000000..c169a6097 --- /dev/null +++ b/src/Discord.Net.Core/API/Rest/BlockUserParams.cs @@ -0,0 +1,11 @@ +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/IDiscordClient.cs b/src/Discord.Net.Core/IDiscordClient.cs index 4131b1796..21491341f 100644 --- a/src/Discord.Net.Core/IDiscordClient.cs +++ b/src/Discord.Net.Core/IDiscordClient.cs @@ -25,12 +25,17 @@ namespace Discord Task GetGuildAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); Task> GetGuildsAsync(CacheMode mode = CacheMode.AllowDownload); Task CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null); - + Task GetInviteAsync(string inviteId); 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> GetVoiceRegionsAsync(); Task GetVoiceRegionAsync(string id); } diff --git a/src/Discord.Net.Rest/BaseDiscordClient.cs b/src/Discord.Net.Rest/BaseDiscordClient.cs index 4ed019dfb..84731dace 100644 --- a/src/Discord.Net.Rest/BaseDiscordClient.cs +++ b/src/Discord.Net.Rest/BaseDiscordClient.cs @@ -124,6 +124,11 @@ namespace Discord.Rest /// public void Dispose() => Dispose(true); + Task> IDiscordClient.GetRelationshipsAsync() => ApiClient.GetRelationshipsAsync(); + Task IDiscordClient.AddFriendAsync(ulong userId) => ApiClient.AddFriendAsync(userId); + Task IDiscordClient.BlockUserAsync(ulong userId) => ApiClient.BlockUserAsync(userId); + Task IDiscordClient.RemoveRelationshipAsync(ulong userId) => ApiClient.RemoveRelationshipAsync(userId); + //IDiscordClient ConnectionState IDiscordClient.ConnectionState => ConnectionState.Disconnected; ISelfUser IDiscordClient.CurrentUser => CurrentUser; From 5cf813992d4a7030cef707a608824fcaa022b474 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Mon, 21 Nov 2016 11:07:54 -0600 Subject: [PATCH 02/13] Woops --- src/Discord.Net.Rest/BaseDiscordClient.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.Rest/BaseDiscordClient.cs b/src/Discord.Net.Rest/BaseDiscordClient.cs index 84731dace..a92a44882 100644 --- a/src/Discord.Net.Rest/BaseDiscordClient.cs +++ b/src/Discord.Net.Rest/BaseDiscordClient.cs @@ -124,10 +124,10 @@ namespace Discord.Rest /// public void Dispose() => Dispose(true); - Task> IDiscordClient.GetRelationshipsAsync() => ApiClient.GetRelationshipsAsync(); - Task IDiscordClient.AddFriendAsync(ulong userId) => ApiClient.AddFriendAsync(userId); - Task IDiscordClient.BlockUserAsync(ulong userId) => ApiClient.BlockUserAsync(userId); - Task IDiscordClient.RemoveRelationshipAsync(ulong userId) => ApiClient.RemoveRelationshipAsync(userId); + 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); //IDiscordClient ConnectionState IDiscordClient.ConnectionState => ConnectionState.Disconnected; From eea383a9d421ff74f9cc14f94118234131b2e360 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Mon, 21 Nov 2016 11:10:55 -0600 Subject: [PATCH 03/13] Reapplied old solution settings --- Discord.Net.sln | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/Discord.Net.sln b/Discord.Net.sln index 7a12f8c75..5ad44de92 100644 --- a/Discord.Net.sln +++ b/Discord.Net.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.25914.0 @@ -47,16 +47,16 @@ Global {496DB20A-A455-4D01-B6BC-90FE6D7C6B81}.Release|x86.Build.0 = Debug|Any CPU {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x64.ActiveCfg = Debug|Any CPU - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x64.Build.0 = Debug|Any CPU - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x86.ActiveCfg = Debug|Any CPU - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x86.Build.0 = Debug|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x64.ActiveCfg = Debug|x64 + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x64.Build.0 = Debug|x64 + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x86.ActiveCfg = Debug|x86 + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Debug|x86.Build.0 = Debug|x86 {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|Any CPU.ActiveCfg = Debug|Any CPU {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|Any CPU.Build.0 = Debug|Any CPU - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x64.ActiveCfg = Debug|Any CPU - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x64.Build.0 = Debug|Any CPU - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x86.ActiveCfg = Debug|Any CPU - {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x86.Build.0 = Debug|Any CPU + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x64.ActiveCfg = Release|x64 + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x64.Build.0 = Release|x64 + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x86.ActiveCfg = Release|x86 + {91E9E7BD-75C9-4E98-84AA-2C271922E5C2}.Release|x86.Build.0 = Release|x86 {BFC6DC28-0351-4573-926A-D4124244C04F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {BFC6DC28-0351-4573-926A-D4124244C04F}.Debug|Any CPU.Build.0 = Debug|Any CPU {BFC6DC28-0351-4573-926A-D4124244C04F}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -95,16 +95,16 @@ Global {078DD7E6-943D-4D09-AFC2-D2BA58B76C9C}.Release|x86.Build.0 = Debug|Any CPU {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x64.ActiveCfg = Debug|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x64.Build.0 = Debug|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x86.ActiveCfg = Debug|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x86.Build.0 = Debug|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|Any CPU.ActiveCfg = Debug|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|Any CPU.Build.0 = Debug|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x64.ActiveCfg = Debug|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x64.Build.0 = Debug|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x86.ActiveCfg = Debug|Any CPU - {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x86.Build.0 = Debug|Any CPU + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x64.ActiveCfg = Debug|x64 + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x64.Build.0 = Debug|x64 + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x86.ActiveCfg = Debug|x86 + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Debug|x86.Build.0 = Debug|x86 + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|Any CPU.Build.0 = Release|Any CPU + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x64.ActiveCfg = Release|x64 + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x64.Build.0 = Release|x64 + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x86.ActiveCfg = Release|x86 + {688FD1D8-7F01-4539-B2E9-F473C5D699C7}.Release|x86.Build.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From be26adc2e79ed355bc37e1db39e03f908f20a069 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Fri, 3 Mar 2017 19:29:10 -0600 Subject: [PATCH 04/13] Working on redoing relations because the original version was shit --- src/Discord.Net.Core/API/Rest/BlockUserParams.cs | 11 ----------- src/Discord.Net.Core/Discord.Net.Core.csproj | 2 +- .../Entities/Users/IRelationship.cs | 9 +++++++++ src/Discord.Net.Core/Entities/Users/IUser.cs | 7 +++++++ .../Entities/Users/RelationshipType.cs | 14 ++++++++++++++ src/Discord.Net.Core/IDiscordClient.cs | 5 +---- src/Discord.Net.Rest/BaseDiscordClient.cs | 5 +---- src/Discord.Net.Rest/DiscordRestApiClient.cs | 6 +++--- .../Entities/Users/RestSelfUser.cs | 9 +++++++++ src/Discord.Net.Rest/Entities/Users/RestUser.cs | 15 +++++++++++++++ src/Discord.Net.Rpc/Entities/Users/RpcUser.cs | 15 +++++++++++++++ .../Entities/Users/SocketRelationship.cs | 11 +++++++++++ .../Entities/Users/SocketSelfUser.cs | 9 +++++++++ .../Entities/Users/SocketUser.cs | 15 +++++++++++++++ 14 files changed, 110 insertions(+), 23 deletions(-) delete mode 100644 src/Discord.Net.Core/API/Rest/BlockUserParams.cs create mode 100644 src/Discord.Net.Core/Entities/Users/IRelationship.cs create mode 100644 src/Discord.Net.Core/Entities/Users/RelationshipType.cs create mode 100644 src/Discord.Net.WebSocket/Entities/Users/SocketRelationship.cs 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(); + } } } From 44fa72c8bf24afbcc903cbd742afd3a3a13f9ee6 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Fri, 3 Mar 2017 22:19:12 -0600 Subject: [PATCH 05/13] Finished web socket implementation --- .../Entities/Users/RelationshipType.cs | 15 +++---- .../API/Common/RelationshipType.cs | 11 ----- src/Discord.Net.Rest/BaseDiscordClient.cs | 9 +++-- src/Discord.Net.Rest/DiscordRestApiClient.cs | 4 +- src/Discord.Net.WebSocket/ClientState.cs | 21 ++++++++++ .../DiscordSocketClient.Events.cs | 14 +++++++ .../DiscordSocketClient.cs | 40 ++++++++++++++++++- .../Entities/Users/SocketRelationship.cs | 18 +++++++-- .../Entities/Users/SocketUser.cs | 18 +++------ 9 files changed, 108 insertions(+), 42 deletions(-) delete mode 100644 src/Discord.Net.Rest/API/Common/RelationshipType.cs diff --git a/src/Discord.Net.Core/Entities/Users/RelationshipType.cs b/src/Discord.Net.Core/Entities/Users/RelationshipType.cs index 71dd3eb3c..dc5129aa1 100644 --- a/src/Discord.Net.Core/Entities/Users/RelationshipType.cs +++ b/src/Discord.Net.Core/Entities/Users/RelationshipType.cs @@ -1,14 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Discord +namespace Discord { public enum RelationshipType { - Friend = 1, - Blocked = 2, - IncomingPending = 3, - OutgoingPending = 4 + None, + Friend, + Blocked, + IncomingPending, + OutgoingPending } } diff --git a/src/Discord.Net.Rest/API/Common/RelationshipType.cs b/src/Discord.Net.Rest/API/Common/RelationshipType.cs deleted file mode 100644 index 0ed99f396..000000000 --- a/src/Discord.Net.Rest/API/Common/RelationshipType.cs +++ /dev/null @@ -1,11 +0,0 @@ -#pragma warning disable CS1591 -namespace Discord.API -{ - internal enum RelationshipType - { - Friend = 1, - Blocked = 2, - IncomingPending = 3, - OutgoingPending = 4 - } -} diff --git a/src/Discord.Net.Rest/BaseDiscordClient.cs b/src/Discord.Net.Rest/BaseDiscordClient.cs index f151bfab1..f38b9506d 100644 --- a/src/Discord.Net.Rest/BaseDiscordClient.cs +++ b/src/Discord.Net.Rest/BaseDiscordClient.cs @@ -121,13 +121,14 @@ namespace Discord.Rest } /// public void Dispose() => Dispose(true); - - public Task> GetRelationshipsAsync() => ApiClient.GetRelationshipsAsync(); - + //IDiscordClient ConnectionState IDiscordClient.ConnectionState => ConnectionState.Disconnected; ISelfUser IDiscordClient.CurrentUser => CurrentUser; - + + Task> IDiscordClient.GetRelationshipsAsync() + => Task.FromResult>(null); + Task IDiscordClient.GetApplicationInfoAsync() { throw new NotSupportedException(); } Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode) diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 05dc8a6fc..b730745cb 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) { diff --git a/src/Discord.Net.WebSocket/ClientState.cs b/src/Discord.Net.WebSocket/ClientState.cs index a452113e2..392791f62 100644 --- a/src/Discord.Net.WebSocket/ClientState.cs +++ b/src/Discord.Net.WebSocket/ClientState.cs @@ -10,11 +10,13 @@ namespace Discord.WebSocket private const double AverageChannelsPerGuild = 10.22; //Source: Googie2149 private const double AverageUsersPerGuild = 47.78; //Source: Googie2149 private const double CollectionMultiplier = 1.05; //Add 5% buffer to handle growth + private const double AverageRelationshipsPerUser = 30; private readonly ConcurrentDictionary _channels; private readonly ConcurrentDictionary _dmChannels; private readonly ConcurrentDictionary _guilds; private readonly ConcurrentDictionary _users; + private readonly ConcurrentDictionary _relations; private readonly ConcurrentHashSet _groupChannels; internal IReadOnlyCollection Channels => _channels.ToReadOnlyCollection(); @@ -22,6 +24,7 @@ namespace Discord.WebSocket internal IReadOnlyCollection GroupChannels => _groupChannels.Select(x => GetChannel(x) as SocketGroupChannel).ToReadOnlyCollection(_groupChannels); internal IReadOnlyCollection Guilds => _guilds.ToReadOnlyCollection(); internal IReadOnlyCollection Users => _users.ToReadOnlyCollection(); + internal IReadOnlyCollection Relationships => _relations.ToReadOnlyCollection(); internal IReadOnlyCollection PrivateChannels => _dmChannels.Select(x => x.Value as ISocketPrivateChannel).Concat( @@ -36,6 +39,7 @@ namespace Discord.WebSocket _dmChannels = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(dmChannelCount * CollectionMultiplier)); _guilds = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(guildCount * CollectionMultiplier)); _users = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(estimatedUsersCount * CollectionMultiplier)); + _relations = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)AverageRelationshipsPerUser); _groupChannels = new ConcurrentHashSet(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(10 * CollectionMultiplier)); } @@ -126,5 +130,22 @@ namespace Discord.WebSocket return user; return null; } + + internal SocketRelationship GetRelationship(ulong id) + { + if (_relations.TryGetValue(id, out SocketRelationship value)) + return value; + return null; + } + internal void AddRelationship(SocketRelationship relation) + { + _relations[relation.User.Id] = relation; + } + internal SocketRelationship RemoveRelationship(ulong id) + { + if (_relations.TryRemove(id, out SocketRelationship value)) + return value; + return null; + } } } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.Events.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.Events.cs index 313e661f3..d731e390a 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.Events.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.Events.cs @@ -221,5 +221,19 @@ namespace Discord.WebSocket remove { _recipientRemovedEvent.Remove(value); } } private readonly AsyncEvent> _recipientRemovedEvent = new AsyncEvent>(); + + // relationships + public event Func RelationshipAdd + { + add { _relationshipAddedEvent.Add(value); } + remove { _relationshipAddedEvent.Remove(value); } + } + private readonly AsyncEvent> _relationshipAddedEvent = new AsyncEvent>(); + public event Func RelationshipRemoved + { + add { _relationshipRemovedEvent.Add(value); } + remove { _relationshipRemovedEvent.Remove(value); } + } + private readonly AsyncEvent> _relationshipRemovedEvent = new AsyncEvent>(); } } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 66c25e5f6..c3db1b379 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -70,6 +70,7 @@ namespace Discord.WebSocket public IReadOnlyCollection GroupChannels => State.PrivateChannels.Select(x => x as SocketGroupChannel).Where(x => x != null).ToImmutableArray(); public IReadOnlyCollection VoiceRegions => _voiceRegions.ToReadOnlyCollection(); + public IReadOnlyCollection Relationships => State.Relationships; /// Creates a new REST/WebSocket discord client. public DiscordSocketClient() : this(new DiscordSocketConfig()) { } @@ -270,7 +271,7 @@ namespace Discord.WebSocket /// public Task GetInviteAsync(string inviteId) => ClientHelper.GetInviteAsync(this, inviteId); - + /// public SocketUser GetUser(ulong id) { @@ -484,6 +485,8 @@ namespace Discord.WebSocket } for (int i = 0; i < data.PrivateChannels.Length; i++) AddPrivateChannel(data.PrivateChannels[i], state); + for (int i = 0; i < data.Relationships.Length; i++) + AddRelationship(data.Relationships[i], state); _sessionId = data.SessionId; _unavailableGuilds = unavailableGuilds; @@ -1499,6 +1502,29 @@ namespace Discord.WebSocket } } return; + + //Relationships + case "RELATIONSHIP_ADD": + { + await _gatewayLogger.DebugAsync("Received Dispatch (RELATIONSHIP_ADD)").ConfigureAwait(false); + + var addedModel = (payload as JToken).ToObject(_serializer); + var before = State.GetRelationship(addedModel.Id); + var after = AddRelationship(addedModel, State); + + await _relationshipAddedEvent.InvokeAsync(before, after); + return; + } + case "RELATIONSHIP_REMOVE": + { + await _gatewayLogger.DebugAsync("Received Dispatch (RELATIONSHIP_REMOVE)").ConfigureAwait(false); + + var removedModel = (payload as JToken).ToObject(_serializer); + var removed = RemoveRelationship(removedModel.Id); + + await _relationshipRemovedEvent.InvokeAsync(removed); + return; + } //Ignored (User only) case "CHANNEL_PINS_ACK": @@ -1650,6 +1676,18 @@ namespace Discord.WebSocket return channel; } + internal SocketRelationship AddRelationship(Relationship model, ClientState state) + { + var relation = SocketRelationship.Create(this, state, model); + State.AddRelationship(relation); + return relation; + } + internal SocketRelationship RemoveRelationship(ulong id) + { + var relation = State.RemoveRelationship(id); + return relation; + } + //IDiscordClient ConnectionState IDiscordClient.ConnectionState => _connection.State; diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketRelationship.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketRelationship.cs index 1fed00801..a7bbcb805 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketRelationship.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketRelationship.cs @@ -1,11 +1,23 @@ -using System; +using Model = Discord.API.Relationship; namespace Discord.WebSocket { public class SocketRelationship : IRelationship { - public RelationshipType Type { get; private set; } + public RelationshipType Type { get; internal set; } - public IUser User { get; private set; } + public IUser User { get; internal set; } + + public SocketRelationship(RelationshipType type, IUser user) + { + Type = type; + User = user; + } + + internal static SocketRelationship Create(DiscordSocketClient discord, ClientState state, Model model) + { + SocketSimpleUser user = SocketSimpleUser.Create(discord, state, model.User); + return new SocketRelationship(model.Type, user); + } } } diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs index 5b47a1ad4..452f7f50e 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs @@ -56,19 +56,13 @@ namespace Discord.WebSocket async Task IUser.CreateDMChannelAsync(RequestOptions options) => await CreateDMChannelAsync(options).ConfigureAwait(false); - public Task AddFriendAsync(RequestOptions options = null) - { - throw new NotImplementedException(); - } + public async Task AddFriendAsync(RequestOptions options = null) + => await Discord.ApiClient.AddFriendAsync(Id, options); - public Task BlockUserAsync(RequestOptions options = null) - { - throw new NotImplementedException(); - } + public async Task BlockUserAsync(RequestOptions options = null) + => await Discord.ApiClient.BlockUserAsync(Id, options); - public Task RemoveRelationshipAsync(RequestOptions options = null) - { - throw new NotImplementedException(); - } + public async Task RemoveRelationshipAsync(RequestOptions options = null) + => await Discord.ApiClient.RemoveRelationshipAsync(Id, options); } } From f84172e30a5de02e9259a9e28b0609de28b3ebd5 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Fri, 3 Mar 2017 23:42:15 -0600 Subject: [PATCH 06/13] 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 07/13] 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(); } } From e5023b2b03bafb988f3861c894fc793ba1591748 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Sat, 4 Mar 2017 11:16:56 -0600 Subject: [PATCH 08/13] Added property to socket user to get relationship, I also fucked up on the "AddRelationship" internal method. --- src/Discord.Net.Core/Entities/Users/IUser.cs | 2 +- src/Discord.Net.WebSocket/ClientState.cs | 2 +- src/Discord.Net.WebSocket/DiscordSocketClient.cs | 2 +- src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Users/IUser.cs b/src/Discord.Net.Core/Entities/Users/IUser.cs index 6196630a5..a92f96f7e 100644 --- a/src/Discord.Net.Core/Entities/Users/IUser.cs +++ b/src/Discord.Net.Core/Entities/Users/IUser.cs @@ -21,7 +21,7 @@ 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 diff --git a/src/Discord.Net.WebSocket/ClientState.cs b/src/Discord.Net.WebSocket/ClientState.cs index 392791f62..5586577d6 100644 --- a/src/Discord.Net.WebSocket/ClientState.cs +++ b/src/Discord.Net.WebSocket/ClientState.cs @@ -39,7 +39,7 @@ namespace Discord.WebSocket _dmChannels = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(dmChannelCount * CollectionMultiplier)); _guilds = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(guildCount * CollectionMultiplier)); _users = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(estimatedUsersCount * CollectionMultiplier)); - _relations = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)AverageRelationshipsPerUser); + _relations = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(AverageRelationshipsPerUser * CollectionMultiplier)); _groupChannels = new ConcurrentHashSet(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(10 * CollectionMultiplier)); } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index c3db1b379..f791e55b1 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -1679,7 +1679,7 @@ namespace Discord.WebSocket internal SocketRelationship AddRelationship(Relationship model, ClientState state) { var relation = SocketRelationship.Create(this, state, model); - State.AddRelationship(relation); + state.AddRelationship(relation); return relation; } internal SocketRelationship RemoveRelationship(ulong id) diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs index 452f7f50e..0acbdb32c 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs @@ -1,5 +1,6 @@ using Discord.Rest; using System; +using System.Linq; using System.Threading.Tasks; using Model = Discord.API.User; using PresenceModel = Discord.API.Presence; @@ -21,6 +22,7 @@ namespace Discord.WebSocket public string Mention => MentionUtils.MentionUser(Id); public Game? Game => Presence.Game; public UserStatus Status => Presence.Status; + public RelationshipType Relationship => Discord.Relationships.FirstOrDefault(r => r.User.Id == Id)?.Type ?? RelationshipType.None; internal SocketUser(DiscordSocketClient discord, ulong id) : base(discord, id) @@ -55,13 +57,11 @@ namespace Discord.WebSocket => Task.FromResult(GlobalUser.DMChannel); async Task IUser.CreateDMChannelAsync(RequestOptions options) => await CreateDMChannelAsync(options).ConfigureAwait(false); - + public async Task AddFriendAsync(RequestOptions options = null) => await Discord.ApiClient.AddFriendAsync(Id, options); - public async Task BlockUserAsync(RequestOptions options = null) => await Discord.ApiClient.BlockUserAsync(Id, options); - public async Task RemoveRelationshipAsync(RequestOptions options = null) => await Discord.ApiClient.RemoveRelationshipAsync(Id, options); } From 1f8067f8c804deb2ee97580d30ba50bcfca52012 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Sat, 4 Mar 2017 11:30:50 -0600 Subject: [PATCH 09/13] wrong value property name in anonymous type for block user --- src/Discord.Net.Rest/DiscordRestApiClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index b730745cb..3587d95f8 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -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 { value = 2 }, new BucketIds(), options: options).ConfigureAwait(false); + await SendJsonAsync("PUT", () => $"users/@me/relationships/{userId}", new { type = 2 }, new BucketIds(), options: options).ConfigureAwait(false); } public async Task RemoveRelationshipAsync(ulong userId, RequestOptions options = null) { From f8af992bdbea95d738c95a29c7aa16b7da7e424a Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Sat, 4 Mar 2017 22:28:46 -0600 Subject: [PATCH 10/13] Minor edit to Relationship property in SocketUser --- src/Discord.Net.WebSocket/DiscordSocketClient.cs | 9 ++++++--- src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 59cb70503..ed1053d58 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -1679,16 +1679,19 @@ namespace Discord.WebSocket return channel; } + internal SocketRelationship GetRelationship(ulong id) + { + return State.GetRelationship(id); + } internal SocketRelationship AddRelationship(Relationship model, ClientState state) { var relation = SocketRelationship.Create(this, state, model); - state.AddRelationship(relation); + state.AddRelationship(SocketRelationship.Create(this, state, model)); return relation; } internal SocketRelationship RemoveRelationship(ulong id) { - var relation = State.RemoveRelationship(id); - return relation; + return State.RemoveRelationship(id); } //IDiscordClient diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs index 0acbdb32c..3b92141d7 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs @@ -22,7 +22,7 @@ namespace Discord.WebSocket public string Mention => MentionUtils.MentionUser(Id); public Game? Game => Presence.Game; public UserStatus Status => Presence.Status; - public RelationshipType Relationship => Discord.Relationships.FirstOrDefault(r => r.User.Id == Id)?.Type ?? RelationshipType.None; + public RelationshipType Relationship => Discord.GetRelationship(Id)?.Type ?? RelationshipType.None; internal SocketUser(DiscordSocketClient discord, ulong id) : base(discord, id) From 8e5fb3857734c3408abbb2e255d79f1783a17fa8 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Sat, 4 Mar 2017 22:28:46 -0600 Subject: [PATCH 11/13] Minor edit to Relationship property in SocketUser --- src/Discord.Net.WebSocket/DiscordSocketClient.cs | 9 ++++++--- src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 59cb70503..ed1053d58 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -1679,16 +1679,19 @@ namespace Discord.WebSocket return channel; } + internal SocketRelationship GetRelationship(ulong id) + { + return State.GetRelationship(id); + } internal SocketRelationship AddRelationship(Relationship model, ClientState state) { var relation = SocketRelationship.Create(this, state, model); - state.AddRelationship(relation); + state.AddRelationship(SocketRelationship.Create(this, state, model)); return relation; } internal SocketRelationship RemoveRelationship(ulong id) { - var relation = State.RemoveRelationship(id); - return relation; + return State.RemoveRelationship(id); } //IDiscordClient diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs index 0acbdb32c..3b92141d7 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs @@ -22,7 +22,7 @@ namespace Discord.WebSocket public string Mention => MentionUtils.MentionUser(Id); public Game? Game => Presence.Game; public UserStatus Status => Presence.Status; - public RelationshipType Relationship => Discord.Relationships.FirstOrDefault(r => r.User.Id == Id)?.Type ?? RelationshipType.None; + public RelationshipType Relationship => Discord.GetRelationship(Id)?.Type ?? RelationshipType.None; internal SocketUser(DiscordSocketClient discord, ulong id) : base(discord, id) From 4d6d08f0d69bd41a6285b682fc321658d56ff674 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Tue, 7 Mar 2017 09:46:17 -0600 Subject: [PATCH 12/13] Made variable and field names consistent --- src/Discord.Net.Core/Entities/Users/IUser.cs | 2 +- src/Discord.Net.WebSocket/ClientState.cs | 14 +++++++------- src/Discord.Net.WebSocket/DiscordSocketClient.cs | 4 ++-- .../Entities/Users/SocketUser.cs | 1 - 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Discord.Net.Core/Entities/Users/IUser.cs b/src/Discord.Net.Core/Entities/Users/IUser.cs index a92f96f7e..aeb65aa9c 100644 --- a/src/Discord.Net.Core/Entities/Users/IUser.cs +++ b/src/Discord.Net.Core/Entities/Users/IUser.cs @@ -24,7 +24,7 @@ namespace Discord /// Adds this user as a friend, this will remove a block Task AddFriendAsync(RequestOptions options = null); - /// Blocks this user, and removes friend relation + /// Blocks this user, and removes the user as a friend Task BlockUserAsync(RequestOptions options = null); /// Removes the relationship of this user Task RemoveRelationshipAsync(RequestOptions options = null); diff --git a/src/Discord.Net.WebSocket/ClientState.cs b/src/Discord.Net.WebSocket/ClientState.cs index 5586577d6..09a273386 100644 --- a/src/Discord.Net.WebSocket/ClientState.cs +++ b/src/Discord.Net.WebSocket/ClientState.cs @@ -16,7 +16,7 @@ namespace Discord.WebSocket private readonly ConcurrentDictionary _dmChannels; private readonly ConcurrentDictionary _guilds; private readonly ConcurrentDictionary _users; - private readonly ConcurrentDictionary _relations; + private readonly ConcurrentDictionary _relationships; private readonly ConcurrentHashSet _groupChannels; internal IReadOnlyCollection Channels => _channels.ToReadOnlyCollection(); @@ -24,7 +24,7 @@ namespace Discord.WebSocket internal IReadOnlyCollection GroupChannels => _groupChannels.Select(x => GetChannel(x) as SocketGroupChannel).ToReadOnlyCollection(_groupChannels); internal IReadOnlyCollection Guilds => _guilds.ToReadOnlyCollection(); internal IReadOnlyCollection Users => _users.ToReadOnlyCollection(); - internal IReadOnlyCollection Relationships => _relations.ToReadOnlyCollection(); + internal IReadOnlyCollection Relationships => _relationships.ToReadOnlyCollection(); internal IReadOnlyCollection PrivateChannels => _dmChannels.Select(x => x.Value as ISocketPrivateChannel).Concat( @@ -39,7 +39,7 @@ namespace Discord.WebSocket _dmChannels = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(dmChannelCount * CollectionMultiplier)); _guilds = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(guildCount * CollectionMultiplier)); _users = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(estimatedUsersCount * CollectionMultiplier)); - _relations = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(AverageRelationshipsPerUser * CollectionMultiplier)); + _relationships = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(AverageRelationshipsPerUser * CollectionMultiplier)); _groupChannels = new ConcurrentHashSet(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(10 * CollectionMultiplier)); } @@ -133,17 +133,17 @@ namespace Discord.WebSocket internal SocketRelationship GetRelationship(ulong id) { - if (_relations.TryGetValue(id, out SocketRelationship value)) + if (_relationships.TryGetValue(id, out SocketRelationship value)) return value; return null; } - internal void AddRelationship(SocketRelationship relation) + internal void AddRelationship(SocketRelationship relationship) { - _relations[relation.User.Id] = relation; + _relationships[relationship.User.Id] = relationship; } internal SocketRelationship RemoveRelationship(ulong id) { - if (_relations.TryRemove(id, out SocketRelationship value)) + if (_relationships.TryRemove(id, out SocketRelationship value)) return value; return null; } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index ed1053d58..393e29a20 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -1685,9 +1685,9 @@ namespace Discord.WebSocket } internal SocketRelationship AddRelationship(Relationship model, ClientState state) { - var relation = SocketRelationship.Create(this, state, model); + var relationship = SocketRelationship.Create(this, state, model); state.AddRelationship(SocketRelationship.Create(this, state, model)); - return relation; + return relationship; } internal SocketRelationship RemoveRelationship(ulong id) { diff --git a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs index 3b92141d7..2b29311ff 100644 --- a/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs +++ b/src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs @@ -1,6 +1,5 @@ using Discord.Rest; using System; -using System.Linq; using System.Threading.Tasks; using Model = Discord.API.User; using PresenceModel = Discord.API.Presence; From bfd0d8df2dae2556da69045660c1e88b479f1a32 Mon Sep 17 00:00:00 2001 From: ObsidianMinor Date: Tue, 7 Mar 2017 22:15:43 -0600 Subject: [PATCH 13/13] The initial value didn't matter anyway --- src/Discord.Net.WebSocket/ClientState.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Discord.Net.WebSocket/ClientState.cs b/src/Discord.Net.WebSocket/ClientState.cs index 09a273386..ce61a0ba5 100644 --- a/src/Discord.Net.WebSocket/ClientState.cs +++ b/src/Discord.Net.WebSocket/ClientState.cs @@ -10,7 +10,6 @@ namespace Discord.WebSocket private const double AverageChannelsPerGuild = 10.22; //Source: Googie2149 private const double AverageUsersPerGuild = 47.78; //Source: Googie2149 private const double CollectionMultiplier = 1.05; //Add 5% buffer to handle growth - private const double AverageRelationshipsPerUser = 30; private readonly ConcurrentDictionary _channels; private readonly ConcurrentDictionary _dmChannels; @@ -39,7 +38,7 @@ namespace Discord.WebSocket _dmChannels = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(dmChannelCount * CollectionMultiplier)); _guilds = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(guildCount * CollectionMultiplier)); _users = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(estimatedUsersCount * CollectionMultiplier)); - _relationships = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(AverageRelationshipsPerUser * CollectionMultiplier)); + _relationships = new ConcurrentDictionary(ConcurrentHashSet.DefaultConcurrencyLevel, 35); _groupChannels = new ConcurrentHashSet(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(10 * CollectionMultiplier)); }