diff --git a/Discord.Net.sln b/Discord.Net.sln
index bfcda2fab..05bfbe216 100644
--- a/Discord.Net.sln
+++ b/Discord.Net.sln
@@ -1,61 +1,22 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25123.0
+# Visual Studio 15
+VisualStudioVersion = 15.0.25123.0
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{8D7989F0-66CE-4DBB-8230-D8C811E9B1D7}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "netplatform", "netplatform", "{EA68EBE2-51C8-4440-9EF7-D633C90A5D35}"
-EndProject
-Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net", "src\Discord.Net\Discord.Net.xproj", "{2C91BDD7-621D-460F-B768-EAD106D9BA62}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6317A2E6-8E36-4C3E-949B-3F10EC888AB9}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Tests", "test\Discord.Net.Tests\Discord.Net.Tests.csproj", "{855D6B1D-847B-42DA-BE6A-23683EA89511}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1BE8AF3F-3CFD-433F-A380-D294A4F617C1}"
- ProjectSection(SolutionItems) = preProject
- global.json = global.json
- EndProjectSection
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "net45", "net45", "{628A40F4-2D06-4BCE-82EF-0EE70DD5C1CA}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net.Net45", "src\Discord.Net\Discord.Net.Net45.csproj", "{C6A50D24-CBD3-4E76-852C-4DCA60BBD608}"
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Discord.Net", "src\Discord.Net.csproj", "{18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
- FullDebug|Any CPU = FullDebug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {2C91BDD7-621D-460F-B768-EAD106D9BA62}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {2C91BDD7-621D-460F-B768-EAD106D9BA62}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {2C91BDD7-621D-460F-B768-EAD106D9BA62}.FullDebug|Any CPU.ActiveCfg = Debug|Any CPU
- {2C91BDD7-621D-460F-B768-EAD106D9BA62}.FullDebug|Any CPU.Build.0 = Debug|Any CPU
- {2C91BDD7-621D-460F-B768-EAD106D9BA62}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {2C91BDD7-621D-460F-B768-EAD106D9BA62}.Release|Any CPU.Build.0 = Release|Any CPU
- {855D6B1D-847B-42DA-BE6A-23683EA89511}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {855D6B1D-847B-42DA-BE6A-23683EA89511}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {855D6B1D-847B-42DA-BE6A-23683EA89511}.FullDebug|Any CPU.ActiveCfg = Debug|Any CPU
- {855D6B1D-847B-42DA-BE6A-23683EA89511}.FullDebug|Any CPU.Build.0 = Debug|Any CPU
- {855D6B1D-847B-42DA-BE6A-23683EA89511}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {855D6B1D-847B-42DA-BE6A-23683EA89511}.Release|Any CPU.Build.0 = Release|Any CPU
- {C6A50D24-CBD3-4E76-852C-4DCA60BBD608}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {C6A50D24-CBD3-4E76-852C-4DCA60BBD608}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {C6A50D24-CBD3-4E76-852C-4DCA60BBD608}.FullDebug|Any CPU.ActiveCfg = Debug|Any CPU
- {C6A50D24-CBD3-4E76-852C-4DCA60BBD608}.FullDebug|Any CPU.Build.0 = Debug|Any CPU
- {C6A50D24-CBD3-4E76-852C-4DCA60BBD608}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {C6A50D24-CBD3-4E76-852C-4DCA60BBD608}.Release|Any CPU.Build.0 = Release|Any CPU
+ {18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
- GlobalSection(NestedProjects) = preSolution
- {EA68EBE2-51C8-4440-9EF7-D633C90A5D35} = {8D7989F0-66CE-4DBB-8230-D8C811E9B1D7}
- {2C91BDD7-621D-460F-B768-EAD106D9BA62} = {EA68EBE2-51C8-4440-9EF7-D633C90A5D35}
- {855D6B1D-847B-42DA-BE6A-23683EA89511} = {6317A2E6-8E36-4C3E-949B-3F10EC888AB9}
- {628A40F4-2D06-4BCE-82EF-0EE70DD5C1CA} = {8D7989F0-66CE-4DBB-8230-D8C811E9B1D7}
- {C6A50D24-CBD3-4E76-852C-4DCA60BBD608} = {628A40F4-2D06-4BCE-82EF-0EE70DD5C1CA}
- EndGlobalSection
EndGlobal
diff --git a/NuGet.config b/NuGet.config
deleted file mode 100644
index 91bc2845a..000000000
--- a/NuGet.config
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/global.json b/global.json
deleted file mode 100644
index 7f3ac9f7e..000000000
--- a/global.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "projects": [ "src" ],
- "sdk": {
- "version": "1.0.0-rc2-20221"
- }
-}
\ No newline at end of file
diff --git a/src/Discord.Net/CDN.cs b/src/Discord.Net/API/CDN.cs
similarity index 94%
rename from src/Discord.Net/CDN.cs
rename to src/Discord.Net/API/CDN.cs
index 11786436b..260feba75 100644
--- a/src/Discord.Net/CDN.cs
+++ b/src/Discord.Net/API/CDN.cs
@@ -1,8 +1,8 @@
-namespace Discord
+namespace Discord.API
{
internal static class CDN
{
- public static string GetUserAvatarUrl(ulong userId, string avatarId)
+ public static string GetUserAvatarUrl(ulong userId, string avatarId)
=> avatarId != null ? $"{DiscordConfig.ClientAPIUrl}users/{userId}/avatars/{avatarId}.jpg" : null;
public static string GetGuildIconUrl(ulong guildId, string iconId)
=> iconId != null ? $"{DiscordConfig.ClientAPIUrl}guilds/{guildId}/icons/{iconId}.jpg" : null;
diff --git a/src/Discord.Net/API/Common/Channel.cs b/src/Discord.Net/API/Common/Channel.cs
index eb521444c..6dda88944 100644
--- a/src/Discord.Net/API/Common/Channel.cs
+++ b/src/Discord.Net/API/Common/Channel.cs
@@ -14,11 +14,11 @@ namespace Discord.API
//GuildChannel
[JsonProperty("guild_id")]
- public ulong GuildId { get; set; }
+ public ulong? GuildId { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("type")]
- public string Type { get; set; }
+ public ChannelType Type { get; set; }
[JsonProperty("position")]
public int Position { get; set; }
[JsonProperty("permission_overwrites")]
diff --git a/src/Discord.Net/API/Common/Unconfirmed/Connection.cs b/src/Discord.Net/API/Common/Connection.cs
similarity index 81%
rename from src/Discord.Net/API/Common/Unconfirmed/Connection.cs
rename to src/Discord.Net/API/Common/Connection.cs
index a51903273..8022e0314 100644
--- a/src/Discord.Net/API/Common/Unconfirmed/Connection.cs
+++ b/src/Discord.Net/API/Common/Connection.cs
@@ -1,18 +1,20 @@
using Newtonsoft.Json;
+using System.Collections.Generic;
namespace Discord.API
{
public class Connection
{
- [JsonProperty("integrations")]
- public Integration[] Integrations { get; set; }
- [JsonProperty("revoked")]
- public bool Revoked { get; set; }
- [JsonProperty("type")]
- public string Type { get; set; }
[JsonProperty("id")]
public string Id { get; set; }
+ [JsonProperty("type")]
+ public string Type { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
+ [JsonProperty("revoked")]
+ public bool Revoked { get; set; }
+
+ [JsonProperty("integrations")]
+ public IEnumerable Integrations { get; set; }
}
}
diff --git a/src/Discord.Net/API/Common/Guild.cs b/src/Discord.Net/API/Common/Guild.cs
index cbd50e390..b4dfcdc11 100644
--- a/src/Discord.Net/API/Common/Guild.cs
+++ b/src/Discord.Net/API/Common/Guild.cs
@@ -26,6 +26,8 @@ namespace Discord.API
public ulong? EmbedChannelId { get; set; }
[JsonProperty("verification_level")]
public int VerificationLevel { get; set; }
+ [JsonProperty("voice_states")]
+ public VoiceState[] VoiceStates { get; set; }
[JsonProperty("roles")]
public Role[] Roles { get; set; }
[JsonProperty("emojis")]
diff --git a/src/Discord.Net/API/Common/GuildMember.cs b/src/Discord.Net/API/Common/GuildMember.cs
index c28d47d34..03da0d5bf 100644
--- a/src/Discord.Net/API/Common/GuildMember.cs
+++ b/src/Discord.Net/API/Common/GuildMember.cs
@@ -7,6 +7,8 @@ namespace Discord.API
{
[JsonProperty("user")]
public User User { get; set; }
+ [JsonProperty("nick")]
+ public string Nick { get; set; }
[JsonProperty("roles")]
public ulong[] Roles { get; set; }
[JsonProperty("joined_at")]
diff --git a/src/Discord.Net/API/Common/Unconfirmed/Overwrite.cs b/src/Discord.Net/API/Common/Overwrite.cs
similarity index 100%
rename from src/Discord.Net/API/Common/Unconfirmed/Overwrite.cs
rename to src/Discord.Net/API/Common/Overwrite.cs
diff --git a/src/Discord.Net/API/Common/Unconfirmed/ExtendedGuild.cs b/src/Discord.Net/API/Common/Unconfirmed/ExtendedGuild.cs
deleted file mode 100644
index 00aaeb7b9..000000000
--- a/src/Discord.Net/API/Common/Unconfirmed/ExtendedGuild.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API
-{
- public class ExtendedGuild : Guild
- {
- [JsonProperty("member_count")]
- public int? MemberCount { get; set; }
- [JsonProperty("large")]
- public bool IsLarge { get; set; }
- [JsonProperty("unavailable")]
- public bool? Unavailable { get; set; }
-
- [JsonProperty("channels")]
- public Channel[] Channels { get; set; }
- [JsonProperty("members")]
- public ExtendedMember[] Members { get; set; }
- [JsonProperty("presences")]
- public MemberPresence[] Presences { get; set; }
- [JsonProperty("voice_states")]
- public MemberVoiceState[] VoiceStates { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/Common/Unconfirmed/ExtendedMember.cs b/src/Discord.Net/API/Common/Unconfirmed/ExtendedMember.cs
deleted file mode 100644
index f09c12e0c..000000000
--- a/src/Discord.Net/API/Common/Unconfirmed/ExtendedMember.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API
-{
- public class ExtendedMember : GuildMember
- {
- [JsonProperty("mute")]
- public bool? IsMuted { get; set; }
- [JsonProperty("deaf")]
- public bool? IsDeafened { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/Common/Unconfirmed/MemberPresence.cs b/src/Discord.Net/API/Common/Unconfirmed/MemberPresence.cs
deleted file mode 100644
index 8148e9b15..000000000
--- a/src/Discord.Net/API/Common/Unconfirmed/MemberPresence.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API
-{
- public class MemberPresence : MemberReference
- {
- [JsonProperty("game")]
- public MemberPresenceGame Game { get; set; }
- [JsonProperty("status")]
- public UserStatus Status { get; set; }
- [JsonProperty("roles")]
- public ulong[] Roles { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/Common/Unconfirmed/MemberPresenceGame.cs b/src/Discord.Net/API/Common/Unconfirmed/MemberPresenceGame.cs
deleted file mode 100644
index acd805548..000000000
--- a/src/Discord.Net/API/Common/Unconfirmed/MemberPresenceGame.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API
-{
- public class MemberPresenceGame
- {
- [JsonProperty("name")]
- public string Name { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/Common/Unconfirmed/MemberReference.cs b/src/Discord.Net/API/Common/Unconfirmed/MemberReference.cs
deleted file mode 100644
index edc41f688..000000000
--- a/src/Discord.Net/API/Common/Unconfirmed/MemberReference.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API
-{
- public class MemberReference
- {
- [JsonProperty("guild_id")]
- public ulong? GuildId { get; set; }
- [JsonProperty("user")]
- public User User { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/Common/Unconfirmed/MessageReference.cs b/src/Discord.Net/API/Common/Unconfirmed/MessageReference.cs
deleted file mode 100644
index d2c1dd268..000000000
--- a/src/Discord.Net/API/Common/Unconfirmed/MessageReference.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API
-{
- public class MessageReference
- {
- [JsonProperty("id")]
- public ulong Id { get; set; }
- [JsonProperty("message_id")] //Only used in MESSAGE_ACK
- public ulong MessageId { get { return Id; } set { Id = value; } }
- [JsonProperty("channel_id")]
- public ulong ChannelId { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/Common/Unconfirmed/RoleReference.cs b/src/Discord.Net/API/Common/Unconfirmed/RoleReference.cs
deleted file mode 100644
index bf516faaa..000000000
--- a/src/Discord.Net/API/Common/Unconfirmed/RoleReference.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API
-{
- public class RoleReference
- {
- [JsonProperty("guild_id")]
- public ulong GuildId { get; set; }
- [JsonProperty("role_id")]
- public ulong RoleId { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/Common/UserGuild.cs b/src/Discord.Net/API/Common/UserGuild.cs
index 9b0819395..124f64688 100644
--- a/src/Discord.Net/API/Common/UserGuild.cs
+++ b/src/Discord.Net/API/Common/UserGuild.cs
@@ -12,5 +12,7 @@ namespace Discord.API
public string Icon { get; set; }
[JsonProperty("owner")]
public bool Owner { get; set; }
+ [JsonProperty("permissions")]
+ public uint Permissions { get; set; }
}
}
diff --git a/src/Discord.Net/API/Rest/GetVoiceRegions.cs b/src/Discord.Net/API/Common/VoiceRegion.cs
similarity index 56%
rename from src/Discord.Net/API/Rest/GetVoiceRegions.cs
rename to src/Discord.Net/API/Common/VoiceRegion.cs
index 5fdbccfd8..83a473142 100644
--- a/src/Discord.Net/API/Rest/GetVoiceRegions.cs
+++ b/src/Discord.Net/API/Common/VoiceRegion.cs
@@ -1,16 +1,8 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
+using Newtonsoft.Json;
-namespace Discord.API.Rest
+namespace Discord.API
{
- public class GetVoiceRegionsRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"voice/regions";
- object IRestRequest.Payload => null;
- }
-
- public class GetVoiceRegionsResponse
+ public class VoiceRegion
{
[JsonProperty("id")]
public string Id { get; set; }
diff --git a/src/Discord.Net/API/Common/Unconfirmed/MemberVoiceState.cs b/src/Discord.Net/API/Common/VoiceState.cs
similarity index 51%
rename from src/Discord.Net/API/Common/Unconfirmed/MemberVoiceState.cs
rename to src/Discord.Net/API/Common/VoiceState.cs
index b79df1790..f584468af 100644
--- a/src/Discord.Net/API/Common/Unconfirmed/MemberVoiceState.cs
+++ b/src/Discord.Net/API/Common/VoiceState.cs
@@ -2,29 +2,25 @@
namespace Discord.API
{
- public class MemberVoiceState
+ public class VoiceState
{
[JsonProperty("guild_id")]
- public ulong GuildId { get; set; }
+ public ulong? GuildId { get; set; }
+ [JsonProperty("channel_id")]
+ public ulong ChannelId { get; set; }
[JsonProperty("user_id")]
public ulong UserId { get; set; }
-
- [JsonProperty("channel_id")]
- public ulong? ChannelId { get; set; }
[JsonProperty("session_id")]
public string SessionId { get; set; }
- [JsonProperty("token")]
- public string Token { get; set; }
-
- [JsonProperty("self_mute")]
- public bool? IsSelfMuted { get; set; }
- [JsonProperty("self_deaf")]
- public bool? IsSelfDeafened { get; set; }
- [JsonProperty("mute")]
- public bool? IsMuted { get; set; }
[JsonProperty("deaf")]
- public bool? IsDeafened { get; set; }
+ public bool Deaf { get; set; }
+ [JsonProperty("mute")]
+ public bool Mute { get; set; }
+ [JsonProperty("self_deaf")]
+ public bool SelfDeaf { get; set; }
+ [JsonProperty("self_mute")]
+ public bool SelfMute { get; set; }
[JsonProperty("suppress")]
- public bool? IsSuppressed { get; set; }
+ public bool Suppress { get; set; }
}
}
diff --git a/src/Discord.Net/API/DiscordRawClient.cs b/src/Discord.Net/API/DiscordRawClient.cs
new file mode 100644
index 000000000..575ece0c8
--- /dev/null
+++ b/src/Discord.Net/API/DiscordRawClient.cs
@@ -0,0 +1,785 @@
+using Discord.API.Rest;
+using Discord.Net;
+using Discord.Net.Converters;
+using Discord.Net.Rest;
+using Newtonsoft.Json;
+using System;
+using System.Collections.Generic;
+using System.Collections.Immutable;
+using System.Diagnostics;
+using System.Globalization;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Discord.API
+{
+ public class DiscordRawClient
+ {
+ internal event EventHandler SentRequest;
+
+ private readonly IRestClient _restClient;
+ private readonly CancellationToken _cancelToken;
+ private readonly JsonSerializer _serializer;
+
+ internal DiscordRawClient(RestClientProvider restClientProvider, CancellationToken cancelToken, TokenType authTokenType, string authToken)
+ {
+ _cancelToken = cancelToken;
+
+ switch (authTokenType)
+ {
+ case TokenType.Bot:
+ authToken = $"Bot {authToken}";
+ break;
+ case TokenType.Bearer:
+ authToken = $"Bearer {authToken}";
+ break;
+ case TokenType.User:
+ break;
+ default:
+ throw new ArgumentException("Unknown oauth token type", nameof(authTokenType));
+ }
+
+ _restClient = restClientProvider(DiscordConfig.ClientAPIUrl, cancelToken);
+ _restClient.SetHeader("authorization", authToken);
+ _restClient.SetHeader("user-agent", DiscordConfig.UserAgent);
+
+ _serializer = new JsonSerializer();
+ _serializer.Converters.Add(new ChannelTypeConverter());
+ _serializer.Converters.Add(new ImageConverter());
+ _serializer.Converters.Add(new NullableUInt64Converter());
+ _serializer.Converters.Add(new PermissionTargetConverter());
+ _serializer.Converters.Add(new StringEntityConverter());
+ _serializer.Converters.Add(new UInt64ArrayConverter());
+ _serializer.Converters.Add(new UInt64Converter());
+ _serializer.Converters.Add(new UInt64EntityConverter());
+ _serializer.Converters.Add(new UserStatusConverter());
+ }
+
+ //Core
+ public async Task Send(string method, string endpoint)
+ where TResponse : class
+ {
+ var stopwatch = Stopwatch.StartNew();
+ Stream responseStream;
+ try
+ {
+ responseStream = await _restClient.Send(method, endpoint, (string)null).ConfigureAwait(false);
+ }
+ catch (HttpException ex)
+ {
+ if (!HandleException(ex))
+ throw;
+ return null;
+ }
+ int bytes = (int)responseStream.Length;
+ stopwatch.Stop();
+ var response = Deserialize(responseStream);
+
+ double milliseconds = ToMilliseconds(stopwatch);
+ SentRequest(this, new SentRequestEventArgs(method, endpoint, bytes, milliseconds));
+
+ return response;
+ }
+ public async Task Send(string method, string endpoint)
+ {
+ var stopwatch = Stopwatch.StartNew();
+ try
+ {
+ await _restClient.Send(method, endpoint, (string)null).ConfigureAwait(false);
+ }
+ catch (HttpException ex)
+ {
+ if (!HandleException(ex))
+ throw;
+ return;
+ }
+ stopwatch.Stop();
+
+ double milliseconds = ToMilliseconds(stopwatch);
+ SentRequest(this, new SentRequestEventArgs(method, endpoint, 0, milliseconds));
+ }
+ public async Task Send(string method, string endpoint, object payload)
+ where TResponse : class
+ {
+ string requestStream = Serialize(payload);
+ var stopwatch = Stopwatch.StartNew();
+ Stream responseStream;
+ try
+ {
+ responseStream = await _restClient.Send(method, endpoint, requestStream).ConfigureAwait(false);
+ }
+ catch (HttpException ex)
+ {
+ if (!HandleException(ex))
+ throw;
+ return null;
+ }
+ int bytes = (int)responseStream.Length;
+ stopwatch.Stop();
+ var response = Deserialize(responseStream);
+
+ double milliseconds = ToMilliseconds(stopwatch);
+ SentRequest(this, new SentRequestEventArgs(method, endpoint, bytes, milliseconds));
+
+ return response;
+ }
+ public async Task Send(string method, string endpoint, object payload)
+ {
+ string requestStream = Serialize(payload);
+ var stopwatch = Stopwatch.StartNew();
+ try
+ {
+ await _restClient.Send(method, endpoint, requestStream).ConfigureAwait(false);
+ }
+ catch (HttpException ex)
+ {
+ if (!HandleException(ex))
+ throw;
+ return;
+ }
+ stopwatch.Stop();
+
+ double milliseconds = ToMilliseconds(stopwatch);
+ SentRequest(this, new SentRequestEventArgs(method, endpoint, 0, milliseconds));
+ }
+ public async Task Send(string method, string endpoint, Stream file, IReadOnlyDictionary multipartArgs)
+ where TResponse : class
+ {
+ var stopwatch = Stopwatch.StartNew();
+ var responseStream = await _restClient.Send(method, endpoint).ConfigureAwait(false);
+ stopwatch.Stop();
+ var response = Deserialize(responseStream);
+
+ double milliseconds = ToMilliseconds(stopwatch);
+ SentRequest(this, new SentRequestEventArgs(method, endpoint, (int)responseStream.Length, milliseconds));
+
+ return response;
+ }
+ public async Task Send(string method, string endpoint, Stream file, IReadOnlyDictionary multipartArgs)
+ {
+ var stopwatch = Stopwatch.StartNew();
+ await _restClient.Send(method, endpoint).ConfigureAwait(false);
+ stopwatch.Stop();
+
+ double milliseconds = ToMilliseconds(stopwatch);
+ SentRequest(this, new SentRequestEventArgs(method, endpoint, 0, milliseconds));
+ }
+
+ //Gateway
+ public async Task GetGateway()
+ {
+ return await Send("GET", "gateway").ConfigureAwait(false);
+ }
+
+ //Channels
+ public async Task GetChannel(ulong channelId)
+ {
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+
+ try
+ {
+ return await Send("GET", $"channels/{channelId}").ConfigureAwait(false);
+ }
+ catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; }
+ }
+ public async Task GetChannel(ulong guildId, ulong channelId)
+ {
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+
+ try
+ {
+ var model = await Send("GET", $"channels/{channelId}").ConfigureAwait(false);
+ if (model.GuildId != guildId)
+ return null;
+ return model;
+ }
+ catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; }
+ }
+ public async Task> GetGuildChannels(ulong guildId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ return await Send>("GET", $"guild/{guildId}/channels").ConfigureAwait(false);
+ }
+ public async Task CreateGuildChannel(ulong guildId, CreateGuildChannelParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (args.Bitrate <= 0) throw new ArgumentOutOfRangeException(nameof(args.Bitrate));
+ if (args.Name == "") throw new ArgumentOutOfRangeException(nameof(args.Name));
+
+ return await Send("POST", $"guilds/{guildId}/channels", args).ConfigureAwait(false);
+ }
+ public async Task DeleteChannel(ulong channelId)
+ {
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+
+ return await Send("DELETE", $"channels/{channelId}").ConfigureAwait(false);
+ }
+ public async Task ModifyGuildChannel(ulong channelId, ModifyGuildChannelParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+ if (args.Name == "") throw new ArgumentOutOfRangeException(nameof(args.Name));
+ if (args.Position < 0) throw new ArgumentOutOfRangeException(nameof(args.Position));
+
+ return await Send("PATCH", $"channels/{channelId}", args).ConfigureAwait(false);
+ }
+ public async Task ModifyGuildChannel(ulong channelId, ModifyTextChannelParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+ if (args.Name == "") throw new ArgumentOutOfRangeException(nameof(args.Name));
+ if (args.Position < 0) throw new ArgumentOutOfRangeException(nameof(args.Position));
+
+ return await Send("PATCH", $"channels/{channelId}", args).ConfigureAwait(false);
+ }
+ public async Task ModifyGuildChannel(ulong channelId, ModifyVoiceChannelParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+ if (args.Bitrate <= 0) throw new ArgumentOutOfRangeException(nameof(args.Bitrate));
+ if (args.Name == "") throw new ArgumentOutOfRangeException(nameof(args.Name));
+ if (args.Position < 0) throw new ArgumentOutOfRangeException(nameof(args.Position));
+
+ return await Send("PATCH", $"channels/{channelId}", args).ConfigureAwait(false);
+ }
+ public async Task ModifyGuildChannels(ulong guildId, IEnumerable args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ var channels = args.ToArray();
+ switch (channels.Length)
+ {
+ case 0:
+ throw new ArgumentOutOfRangeException(nameof(args));
+ case 1:
+ await ModifyGuildChannel(channels[0].Id, new ModifyGuildChannelParams { Position = channels[0].Position }).ConfigureAwait(false);
+ break;
+ default:
+ await Send("PATCH", $"guilds/{guildId}/channels", channels).ConfigureAwait(false);
+ break;
+ }
+ }
+
+ //Channel Permissions
+ public async Task ModifyChannelPermissions(ulong channelId, ulong targetId, ModifyChannelPermissionsParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ await Send("PUT", $"channels/{channelId}/permissions/{targetId}", args).ConfigureAwait(false);
+ }
+ public async Task DeleteChannelPermission(ulong channelId, ulong targetId)
+ {
+ await Send("DELETE", $"channels/{channelId}/permissions/{targetId}").ConfigureAwait(false);
+ }
+
+ //Guilds
+ public async Task GetGuild(ulong guildId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ try
+ {
+ return await Send("GET", $"guilds/{guildId}").ConfigureAwait(false);
+ }
+ catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; }
+ }
+ public async Task CreateGuild(CreateGuildParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (string.IsNullOrEmpty(args.Name)) throw new ArgumentNullException(nameof(args.Name));
+ if (string.IsNullOrEmpty(args.Region)) throw new ArgumentNullException(nameof(args.Region));
+
+ return await Send("POST", "guilds", args).ConfigureAwait(false);
+ }
+ public async Task DeleteGuild(ulong guildId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ return await Send("DELETE", $"guilds/{guildId}").ConfigureAwait(false);
+ }
+ public async Task LeaveGuild(ulong guildId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ return await Send("DELETE", $"users/@me/guilds/{guildId}").ConfigureAwait(false);
+ }
+ public async Task ModifyGuild(ulong guildId, ModifyGuildParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (args.AFKChannelId == 0) throw new ArgumentOutOfRangeException(nameof(args.AFKChannelId));
+ if (args.AFKTimeout < 0) throw new ArgumentOutOfRangeException(nameof(args.AFKTimeout));
+ if (args.Name == "") throw new ArgumentOutOfRangeException(nameof(args.Name));
+ //if (args.OwnerId == 0) throw new ArgumentOutOfRangeException(nameof(args.OwnerId));
+ //if (args.Region == "") throw new ArgumentOutOfRangeException(nameof(args.Region));
+ if (args.VerificationLevel < 0) throw new ArgumentOutOfRangeException(nameof(args.VerificationLevel));
+
+ return await Send("PATCH", $"guilds/{guildId}", args).ConfigureAwait(false);
+ }
+ public async Task BeginGuildPrune(ulong guildId, GuildPruneParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (args.Days < 0) throw new ArgumentOutOfRangeException(nameof(args.Days));
+
+ return await Send("POST", $"guilds/{guildId}/prune", args).ConfigureAwait(false);
+ }
+ public async Task GetGuildPruneCount(ulong guildId, GuildPruneParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (args.Days < 0) throw new ArgumentOutOfRangeException(nameof(args.Days));
+
+ return await Send("GET", $"guilds/{guildId}/prune", args).ConfigureAwait(false);
+ }
+
+ //Guild Bans
+ public async Task> GetGuildBans(ulong guildId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ return await Send>("GET", $"guilds/{guildId}/bans").ConfigureAwait(false);
+ }
+ public async Task CreateGuildBan(ulong guildId, ulong userId, CreateGuildBanParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (userId == 0) throw new ArgumentOutOfRangeException(nameof(userId));
+ if (args.PruneDays < 0) throw new ArgumentOutOfRangeException(nameof(args.PruneDays));
+
+ await Send("PUT", $"guilds/{guildId}/bans/{userId}", args).ConfigureAwait(false);
+ }
+ public async Task RemoveGuildBan(ulong guildId, ulong userId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (userId == 0) throw new ArgumentOutOfRangeException(nameof(userId));
+
+ await Send("DELETE", $"guilds/{guildId}/bans/{userId}").ConfigureAwait(false);
+ }
+
+ //Guild Embeds
+ public async Task GetGuildEmbed(ulong guildId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ try
+ {
+ return await Send("GET", $"guilds/{guildId}/embed").ConfigureAwait(false);
+ }
+ catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; }
+ }
+ public async Task ModifyGuildEmbed(ulong guildId, ModifyGuildEmbedParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ return await Send("PATCH", $"guilds/{guildId}/embed", args).ConfigureAwait(false);
+ }
+
+ //Guild Integrations
+ public async Task> GetGuildIntegrations(ulong guildId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ return await Send>("GET", $"guilds/{guildId}/integrations").ConfigureAwait(false);
+ }
+ public async Task CreateGuildIntegration(ulong guildId, CreateGuildIntegrationParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (args.Id == 0) throw new ArgumentOutOfRangeException(nameof(args.Id));
+
+ return await Send("POST", $"guilds/{guildId}/integrations").ConfigureAwait(false);
+ }
+ public async Task DeleteGuildIntegration(ulong guildId, ulong integrationId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (integrationId == 0) throw new ArgumentOutOfRangeException(nameof(integrationId));
+
+ return await Send("DELETE", $"guilds/{guildId}/integrations/{integrationId}").ConfigureAwait(false);
+ }
+ public async Task ModifyGuildIntegration(ulong guildId, ulong integrationId, ModifyGuildIntegrationParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (integrationId == 0) throw new ArgumentOutOfRangeException(nameof(integrationId));
+ if (args.ExpireBehavior < 0) throw new ArgumentOutOfRangeException(nameof(args.ExpireBehavior));
+ if (args.ExpireGracePeriod < 0) throw new ArgumentOutOfRangeException(nameof(args.ExpireGracePeriod));
+
+ return await Send("PATCH", $"guilds/{guildId}/integrations/{integrationId}", args).ConfigureAwait(false);
+ }
+ public async Task SyncGuildIntegration(ulong guildId, ulong integrationId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (integrationId == 0) throw new ArgumentOutOfRangeException(nameof(integrationId));
+
+ return await Send("POST", $"guilds/{guildId}/integrations/{integrationId}/sync").ConfigureAwait(false);
+ }
+
+ //Guild Invites
+ public async Task GetInvite(string inviteIdOrXkcd)
+ {
+ if (string.IsNullOrEmpty(inviteIdOrXkcd)) throw new ArgumentOutOfRangeException(nameof(inviteIdOrXkcd));
+
+ try
+ {
+ return await Send("GET", $"invites/{inviteIdOrXkcd}").ConfigureAwait(false);
+ }
+ catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; }
+ }
+ public async Task> GetGuildInvites(ulong guildId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ return await Send>("GET", $"guilds/{guildId}/invites").ConfigureAwait(false);
+ }
+ public async Task GetChannelInvites(ulong channelId)
+ {
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+
+ return await Send("GET", $"channels/{channelId}/invites").ConfigureAwait(false);
+ }
+ public async Task CreateChannelInvite(ulong channelId, CreateChannelInviteParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+ if (args.MaxAge < 0) throw new ArgumentOutOfRangeException(nameof(args.MaxAge));
+ if (args.MaxUses < 0) throw new ArgumentOutOfRangeException(nameof(args.MaxUses));
+
+ return await Send("POST", $"channels/{channelId}/invites", args).ConfigureAwait(false);
+ }
+ public async Task DeleteInvite(string inviteCode)
+ {
+ if (string.IsNullOrEmpty(inviteCode)) throw new ArgumentOutOfRangeException(nameof(inviteCode));
+
+ return await Send("DELETE", $"invites/{inviteCode}").ConfigureAwait(false);
+ }
+ public async Task AcceptInvite(string inviteCode)
+ {
+ if (string.IsNullOrEmpty(inviteCode)) throw new ArgumentOutOfRangeException(nameof(inviteCode));
+
+ await Send("POST", $"invites/{inviteCode}").ConfigureAwait(false);
+ }
+
+ //Guild Members
+ public async Task GetGuildMember(ulong guildId, ulong userId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (userId == 0) throw new ArgumentOutOfRangeException(nameof(userId));
+
+ try
+ {
+ return await Send("GET", $"guilds/{guildId}/members/{userId}").ConfigureAwait(false);
+ }
+ catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; }
+ }
+ public async Task> GetGuildMembers(ulong guildId, GetGuildMembersParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (args.Limit <= 0) throw new ArgumentOutOfRangeException(nameof(args.Limit));
+ if (args.Offset < 0) throw new ArgumentOutOfRangeException(nameof(args.Offset));
+
+ int limit = args.Limit ?? int.MaxValue;
+ int offset = args.Offset;
+
+ List result;
+ if (args.Limit != null)
+ result = new List((limit + DiscordConfig.MaxUsersPerBatch - 1) / DiscordConfig.MaxUsersPerBatch);
+ else
+ result = new List();
+
+ while (true)
+ {
+ int runLimit = (limit >= DiscordConfig.MaxUsersPerBatch) ? DiscordConfig.MaxUsersPerBatch : limit;
+ string endpoint = $"guild/{guildId}/members?limit={limit}&offset={offset}";
+ var models = await Send("GET", endpoint).ConfigureAwait(false);
+
+ //Was this an empty batch?
+ if (models.Length == 0) break;
+
+ result.Add(models);
+
+ limit -= DiscordConfig.MaxUsersPerBatch;
+
+ //Was this an incomplete (the last) batch?
+ if (models.Length != DiscordConfig.MaxUsersPerBatch) break;
+ }
+
+ if (result.Count > 1)
+ return result.SelectMany(x => x);
+ else
+ return result[0];
+ }
+ public async Task RemoveGuildMember(ulong guildId, ulong userId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (userId == 0) throw new ArgumentOutOfRangeException(nameof(userId));
+
+ await Send("DELETE", $"guilds/{guildId}/members/{userId}").ConfigureAwait(false);
+ }
+ public async Task ModifyGuildMember(ulong guildId, ulong userId, ModifyGuildMemberParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (userId == 0) throw new ArgumentOutOfRangeException(nameof(userId));
+
+ return await Send("PATCH", $"guilds/{guildId}/members/{userId}", args).ConfigureAwait(false);
+ }
+
+ //Guild Roles
+ public async Task> GetGuildRoles(ulong guildId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ return await Send>("GET", $"guild/{guildId}/roles").ConfigureAwait(false);
+ }
+ public async Task CreateGuildRole(ulong guildId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ return await Send("POST", $"guilds/{guildId}/roles").ConfigureAwait(false);
+ }
+ public async Task DeleteGuildRole(ulong guildId, ulong roleId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (roleId == 0) throw new ArgumentOutOfRangeException(nameof(roleId));
+
+ await Send("DELETE", $"guilds/{guildId}/roles/{roleId}").ConfigureAwait(false);
+ }
+ public async Task ModifyGuildRole(ulong guildId, ulong roleId, ModifyGuildRoleParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+ if (roleId == 0) throw new ArgumentOutOfRangeException(nameof(roleId));
+ if (args.Color < 0) throw new ArgumentOutOfRangeException(nameof(args.Color));
+ if (args.Name == "") throw new ArgumentOutOfRangeException(nameof(args.Name));
+ if (args.Position < 0) throw new ArgumentOutOfRangeException(nameof(args.Position));
+
+ return await Send("PATCH", $"guilds/{guildId}/roles/{roleId}", args).ConfigureAwait(false);
+ }
+ public async Task> ModifyGuildRoles(ulong guildId, IEnumerable args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ var roles = args.ToArray();
+ switch (roles.Length)
+ {
+ case 0:
+ throw new ArgumentOutOfRangeException(nameof(args));
+ case 1:
+ return ImmutableArray.Create(await ModifyGuildRole(guildId, roles[0].Id, roles[0]).ConfigureAwait(false));
+ default:
+ return await Send>("PATCH", $"guilds/{guildId}/roles", args).ConfigureAwait(false);
+ }
+ }
+
+ //Messages
+ public async Task> GetChannelMessages(ulong channelId, GetChannelMessagesParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+ if (args.Limit <= 0) throw new ArgumentOutOfRangeException(nameof(args.Limit));
+
+ int limit = args.Limit;
+ ulong? relativeId = args.RelativeMessageId;
+ string relativeDir = args.RelativeDirection == Direction.After ? "after" : "before";
+
+ int runs = limit / DiscordConfig.MaxMessagesPerBatch;
+ int lastRunCount = limit - runs * DiscordConfig.MaxMessagesPerBatch;
+ var result = new API.Message[runs][];
+
+ int i = 0;
+ for (; i < runs; i++)
+ {
+ string endpoint;
+ if (relativeId != null)
+ endpoint = $"channels/{channelId}/messages?limit={limit}&{relativeDir}={relativeId}";
+ else
+ endpoint = $"channels/{channelId}/messages?limit={limit}";
+ var models = await Send("GET", endpoint).ConfigureAwait(false);
+
+ //Was this an empty batch?
+ if (models.Length == 0) break;
+
+ result[i] = models;
+
+ limit = (i == runs - 1) ? lastRunCount : DiscordConfig.MaxMessagesPerBatch;
+ relativeId = args.RelativeDirection == Direction.Before ? models[0].Id : models[models.Length - 1].Id;
+
+ //Was this an incomplete (the last) batch?
+ if (models.Length != DiscordConfig.MaxMessagesPerBatch) { i++; break; }
+ }
+
+ if (runs > 1)
+ return result.Take(runs).SelectMany(x => x);
+ else
+ return result[0];
+ }
+ public async Task CreateMessage(ulong channelId, CreateMessageParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+
+ return await Send("POST", $"channels/{channelId}/messages", args).ConfigureAwait(false);
+ }
+ public async Task UploadFile(ulong channelId, Stream file, UploadFileParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+
+ return await Send("POST", $"channels/{channelId}/messages", file, args.ToDictionary()).ConfigureAwait(false);
+ }
+ public async Task DeleteMessage(ulong channelId, ulong messageId)
+ {
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+ if (messageId == 0) throw new ArgumentOutOfRangeException(nameof(messageId));
+
+ await Send("DELETE", $"channels/{channelId}/messages/{messageId}").ConfigureAwait(false);
+ }
+ public async Task DeleteMessages(ulong channelId, DeleteMessagesParam args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (args.MessageIds == null) throw new ArgumentNullException(nameof(args.MessageIds));
+
+ var messageIds = args.MessageIds.ToArray();
+ switch (messageIds.Length)
+ {
+ case 0:
+ throw new ArgumentOutOfRangeException(nameof(args.MessageIds));
+ case 1:
+ await DeleteMessage(channelId, messageIds[0]).ConfigureAwait(false);
+ break;
+ default:
+ await Send("POST", $"channels/{channelId}/messages/bulk_delete", args).ConfigureAwait(false);
+ break;
+ }
+ }
+ public async Task ModifyMessage(ulong channelId, ulong messageId, ModifyMessageParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+ if (messageId == 0) throw new ArgumentOutOfRangeException(nameof(messageId));
+
+ return await Send("PATCH", $"channels/{channelId}/messages/{messageId}", args).ConfigureAwait(false);
+ }
+ public async Task AckMessage(ulong channelId, ulong messageId)
+ {
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+ if (messageId == 0) throw new ArgumentOutOfRangeException(nameof(messageId));
+
+ await Send("POST", $"channels/{channelId}/messages/{messageId}/ack").ConfigureAwait(false);
+ }
+ public async Task TriggerTypingIndicator(ulong channelId)
+ {
+ if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId));
+
+ await Send("POST", $"channels/{channelId}/typing").ConfigureAwait(false);
+ }
+
+ //Users
+ public async Task GetUser(ulong userId)
+ {
+ if (userId == 0) throw new ArgumentOutOfRangeException(nameof(userId));
+
+ try
+ {
+ return await Send("GET", $"users/{userId}").ConfigureAwait(false);
+ }
+ catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; }
+ }
+ public async Task GetUser(string username, ushort discriminator)
+ {
+ if (string.IsNullOrEmpty(username)) throw new ArgumentOutOfRangeException(nameof(username));
+
+ try
+ {
+ var models = await QueryUsers($"{username}#{discriminator}", 1).ConfigureAwait(false);
+ return models.FirstOrDefault();
+ }
+ catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; }
+ }
+ public async Task> QueryUsers(string query, int limit)
+ {
+ if (string.IsNullOrEmpty(query)) throw new ArgumentOutOfRangeException(nameof(query));
+ if (limit <= 0) throw new ArgumentOutOfRangeException(nameof(limit));
+
+ return await Send>("GET", $"users?q={Uri.EscapeDataString(query)}&limit={limit}").ConfigureAwait(false);
+ }
+
+ //Current User/DMs
+ public async Task GetCurrentUser()
+ {
+ return await Send("GET", "users/@me").ConfigureAwait(false);
+ }
+ public async Task> GetCurrentUserConnections()
+ {
+ return await Send>("GET", "users/@me/connections").ConfigureAwait(false);
+ }
+ public async Task> GetCurrentUserDMs()
+ {
+ return await Send>("GET", "users/@me/channels").ConfigureAwait(false);
+ }
+ public async Task> GetCurrentUserGuilds()
+ {
+ return await Send>("GET", "users/@me/guilds").ConfigureAwait(false);
+ }
+ public async Task ModifyCurrentUser(ModifyCurrentUserParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (args.Email == "") throw new ArgumentOutOfRangeException(nameof(args.Email));
+ if (args.Username == "") throw new ArgumentOutOfRangeException(nameof(args.Username));
+
+ return await Send("PATCH", "users/@me", args).ConfigureAwait(false);
+ }
+ public async Task CreateDMChannel(CreateDMChannelParams args)
+ {
+ if (args == null) throw new ArgumentNullException(nameof(args));
+ if (args.RecipientId == 0) throw new ArgumentOutOfRangeException(nameof(args.RecipientId));
+
+ return await Send("POST", $"users/@me/channels", args).ConfigureAwait(false);
+ }
+
+ //Voice Regions
+ public async Task> GetVoiceRegions()
+ {
+ return await Send>("GET", "voice/regions").ConfigureAwait(false);
+ }
+ public async Task> GetGuildVoiceRegions(ulong guildId)
+ {
+ if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId));
+
+ return await Send>("GET", $"guilds/{guildId}/regions").ConfigureAwait(false);
+ }
+
+ //Helpers
+ private static double ToMilliseconds(Stopwatch stopwatch) => Math.Round((double)stopwatch.ElapsedTicks / (double)Stopwatch.Frequency * 1000.0, 2);
+ private string Serialize(object value)
+ {
+ var sb = new StringBuilder(256);
+ using (TextWriter text = new StringWriter(sb, CultureInfo.InvariantCulture))
+ using (JsonWriter writer = new JsonTextWriter(text))
+ _serializer.Serialize(writer, value);
+ return sb.ToString();
+ }
+ private T Deserialize(Stream jsonStream)
+ {
+ using (TextReader text = new StreamReader(jsonStream))
+ using (JsonReader reader = new JsonTextReader(text))
+ return _serializer.Deserialize(reader);
+ }
+
+ private bool HandleException(Exception ex)
+ {
+ //TODO: Implement... maybe via SentRequest? Need to bubble this up to DiscordClient or a MessageQueue
+ return false;
+ }
+ }
+}
diff --git a/src/Discord.Net/API/GatewaySocket/OpCode.cs b/src/Discord.Net/API/GatewaySocket/OpCode.cs
deleted file mode 100644
index cf8e142ef..000000000
--- a/src/Discord.Net/API/GatewaySocket/OpCode.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public enum OpCode : byte
- {
- /// C←S - Used to send most events.
- Dispatch = 0,
- /// C↔S - Used to keep the connection alive and measure latency.
- Heartbeat = 1,
- /// C→S - Used to associate a connection with a token and specify configuration.
- Identify = 2,
- /// C→S - Used to update client's status and current game id.
- StatusUpdate = 3,
- /// C→S - Used to join a particular voice channel.
- VoiceStateUpdate = 4,
- /// C→S - Used to ensure the guild's voice server is alive. Only send this if voice connection fails or suddenly drops.
- VoiceServerPing = 5,
- /// C→S - Used to resume a connection after a redirect occurs.
- Resume = 6,
- /// C←S - Used to notify a client that they must reconnect to another gateway.
- Reconnect = 7,
- /// C→S - Used to request all members that were withheld by large_threshold.
- RequestGuildMembers = 8,
- /// C←S - Used to notify the client of an invalid session id.
- InvalidSession = 9
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/Heartbeat.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/Heartbeat.cs
deleted file mode 100644
index 5dac73ec5..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/Heartbeat.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using Newtonsoft.Json;
-using System;
-
-namespace Discord.API.GatewaySocket
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class HeartbeatCommand : IWebSocketMessage
- {
- int IWebSocketMessage.OpCode => (int)OpCode.Heartbeat;
- object IWebSocketMessage.Payload => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/Identify.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/Identify.cs
deleted file mode 100644
index 235f615ef..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/Identify.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using Newtonsoft.Json;
-using System.Collections.Generic;
-
-namespace Discord.API.GatewaySocket
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class IdentifyCommand : IWebSocketMessage
- {
- int IWebSocketMessage.OpCode => (int)OpCode.Identify;
- object IWebSocketMessage.Payload => this;
-
- [JsonProperty("v")]
- public int Version { get; set; }
- [JsonProperty("token")]
- public string Token { get; set; }
- [JsonProperty("properties")]
- public IReadOnlyDictionary Properties { get; set; }
- [JsonProperty("large_threshold", NullValueHandling = NullValueHandling.Ignore)]
- public int LargeThreshold { get; set; }
- [JsonProperty("compress")]
- public bool UseCompression { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/RequestMembers.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/RequestMembers.cs
deleted file mode 100644
index c4614284d..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/RequestMembers.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.GatewaySocket
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class RequestMembersCommand : IWebSocketMessage
- {
- int IWebSocketMessage.OpCode => (int)OpCode.RequestGuildMembers;
- object IWebSocketMessage.Payload => this;
-
- [JsonProperty("guild_id")]
- public ulong[] GuildId { get; set; }
- [JsonProperty("query")]
- public string Query { get; set; }
- [JsonProperty("limit")]
- public int Limit { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/Resume.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/Resume.cs
deleted file mode 100644
index 1525c6b6a..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/Resume.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.GatewaySocket
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class ResumeCommand : IWebSocketMessage
- {
- int IWebSocketMessage.OpCode => (int)OpCode.Resume;
- object IWebSocketMessage.Payload => this;
-
- [JsonProperty("session_id")]
- public string SessionId { get; set; }
- [JsonProperty("seq")]
- public uint Sequence { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/UpdateStatus.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/UpdateStatus.cs
deleted file mode 100644
index 8aa22ede5..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/UpdateStatus.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.GatewaySocket
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class UpdateStatusCommand : IWebSocketMessage
- {
- int IWebSocketMessage.OpCode => (int)OpCode.StatusUpdate;
- object IWebSocketMessage.Payload => this;
-
- public class GameInfo
- {
- [JsonProperty("name")]
- public string Name { get; set; }
- }
-
- [JsonProperty("idle_since")]
- public long? IdleSince { get; set; }
- [JsonProperty("game")]
- public GameInfo Game { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/UpdateVoice.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/UpdateVoice.cs
deleted file mode 100644
index d7befa41e..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Commands/UpdateVoice.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.GatewaySocket
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class UpdateVoiceCommand : IWebSocketMessage
- {
- int IWebSocketMessage.OpCode => (int)OpCode.VoiceStateUpdate;
- object IWebSocketMessage.Payload => this;
-
- [JsonProperty("guild_id")]
- public ulong? GuildId { get; set; }
- [JsonProperty("channel_id")]
- public ulong? ChannelId { get; set; }
- [JsonProperty("self_mute")]
- public bool IsSelfMuted { get; set; }
- [JsonProperty("self_deaf")]
- public bool IsSelfDeafened { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/ChannelCreate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/ChannelCreate.cs
deleted file mode 100644
index 1e2769036..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/ChannelCreate.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class ChannelCreateEvent : Channel { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/ChannelDelete.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/ChannelDelete.cs
deleted file mode 100644
index 91c57d640..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/ChannelDelete.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class ChannelDeleteEvent : Channel { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/ChannelUpdate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/ChannelUpdate.cs
deleted file mode 100644
index 227124291..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/ChannelUpdate.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class ChannelUpdateEvent : Channel { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildBanAdd.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildBanAdd.cs
deleted file mode 100644
index c1149ee15..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildBanAdd.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class GuildBanAddEvent : MemberReference { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildBanRemove.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildBanRemove.cs
deleted file mode 100644
index 5474146a7..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildBanRemove.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class GuildBanRemoveEvent : MemberReference { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildCreate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildCreate.cs
deleted file mode 100644
index f07adaed3..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildCreate.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class GuildCreateEvent : ExtendedGuild { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildDelete.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildDelete.cs
deleted file mode 100644
index 3408183ad..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildDelete.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class GuildDeleteEvent : ExtendedGuild { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildMemberAdd.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildMemberAdd.cs
deleted file mode 100644
index 098a2ea3b..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildMemberAdd.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class GuildMemberAddEvent : ExtendedMember { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildMemberRemove.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildMemberRemove.cs
deleted file mode 100644
index 686af9511..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildMemberRemove.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class GuildMemberRemoveEvent : MemberReference { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildMemberUpdate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildMemberUpdate.cs
deleted file mode 100644
index 339489f76..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildMemberUpdate.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class GuildMemberUpdateEvent : GuildMember { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildMembersChunk.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildMembersChunk.cs
deleted file mode 100644
index 72936dd16..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildMembersChunk.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.GatewaySocket
-{
- public class GuildMembersChunkEvent
- {
- [JsonProperty("guild_id")]
- public ulong GuildId { get; set; }
- [JsonProperty("members")]
- public ExtendedMember[] Members { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildRoleCreate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildRoleCreate.cs
deleted file mode 100644
index 2740546dc..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildRoleCreate.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.GatewaySocket
-{
- public class GuildRoleCreateEvent
- {
- [JsonProperty("guild_id")]
- public ulong GuildId { get; set; }
- [JsonProperty("role")]
- public Role Data { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildRoleDelete.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildRoleDelete.cs
deleted file mode 100644
index 4986f6193..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildRoleDelete.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class GuildRoleDeleteEvent : RoleReference { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildRoleUpdate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildRoleUpdate.cs
deleted file mode 100644
index 56c232d06..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildRoleUpdate.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.GatewaySocket
-{
- public class GuildRoleUpdateEvent
- {
- [JsonProperty("guild_id")]
- public ulong GuildId { get; set; }
- [JsonProperty("role")]
- public Role Data { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildUpdate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildUpdate.cs
deleted file mode 100644
index b292c54e6..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/GuildUpdate.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class GuildUpdateEvent : Guild { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/MessageAck.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/MessageAck.cs
deleted file mode 100644
index c8379d369..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/MessageAck.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class MessageAckEvent : MessageReference { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/MessageCreate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/MessageCreate.cs
deleted file mode 100644
index 6b0e1e024..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/MessageCreate.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class MessageCreateEvent : Message { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/MessageDelete.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/MessageDelete.cs
deleted file mode 100644
index d932960ba..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/MessageDelete.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class MessageDeleteEvent : MessageReference { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/MessageUpdate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/MessageUpdate.cs
deleted file mode 100644
index 39ef7e1ba..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/MessageUpdate.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class MessageUpdateEvent : Message { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/PresenceUpdate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/PresenceUpdate.cs
deleted file mode 100644
index 59d915354..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/PresenceUpdate.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class PresenceUpdateEvent : MemberPresence { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/Ready.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/Ready.cs
deleted file mode 100644
index 51e0f3c8c..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/Ready.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.GatewaySocket
-{
- public class ReadyEvent
- {
- public class ReadState
- {
- [JsonProperty("id")]
- public string ChannelId { get; set; }
- [JsonProperty("mention_count")]
- public int MentionCount { get; set; }
- [JsonProperty("last_message_id")]
- public string LastMessageId { get; set; }
- }
-
- [JsonProperty("v")]
- public int Version { get; set; }
- [JsonProperty("user")]
- public User User { get; set; }
- [JsonProperty("session_id")]
- public string SessionId { get; set; }
- [JsonProperty("read_state")]
- public ReadState[] ReadStates { get; set; }
- [JsonProperty("guilds")]
- public ExtendedGuild[] Guilds { get; set; }
- [JsonProperty("private_channels")]
- public Channel[] PrivateChannels { get; set; }
- [JsonProperty("heartbeat_interval")]
- public int HeartbeatInterval { get; set; }
-
- //Ignored
- [JsonProperty("user_settings")]
- public object UserSettings { get; set; }
- [JsonProperty("user_guild_settings")]
- public object UserGuildSettings { get; set; }
- [JsonProperty("tutorial")]
- public object Tutorial { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/Resumed.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/Resumed.cs
deleted file mode 100644
index 3f98b1f35..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/Resumed.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.GatewaySocket
-{
- public class ResumedEvent
- {
- [JsonProperty("heartbeat_interval")]
- public int HeartbeatInterval { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/TypingStart.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/TypingStart.cs
deleted file mode 100644
index 063011bbb..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/TypingStart.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.GatewaySocket
-{
- public class TypingStartEvent
- {
- [JsonProperty("user_id")]
- public ulong UserId { get; set; }
- [JsonProperty("channel_id")]
- public ulong ChannelId { get; set; }
- [JsonProperty("timestamp")]
- public int Timestamp { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/UserUpdate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/UserUpdate.cs
deleted file mode 100644
index e49f8b292..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/UserUpdate.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class UserUpdateEvent : User { }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/VoiceServerUpdate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/VoiceServerUpdate.cs
deleted file mode 100644
index 75936bb93..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/VoiceServerUpdate.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.GatewaySocket
-{
- public class VoiceServerUpdateEvent
- {
- [JsonProperty("guild_id")]
- public ulong GuildId { get; set; }
- [JsonProperty("endpoint")]
- public string Endpoint { get; set; }
- [JsonProperty("token")]
- public string Token { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/VoiceStateUpdate.cs b/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/VoiceStateUpdate.cs
deleted file mode 100644
index c0b99c710..000000000
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/VoiceStateUpdate.cs
+++ /dev/null
@@ -1,4 +0,0 @@
-namespace Discord.API.GatewaySocket
-{
- public class VoiceStateUpdateEvent : MemberVoiceState { }
-}
diff --git a/src/Discord.Net/API/IWebSocketMessage.cs b/src/Discord.Net/API/IWebSocketMessage.cs
deleted file mode 100644
index 06c51bf77..000000000
--- a/src/Discord.Net/API/IWebSocketMessage.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API
-{
- public interface IWebSocketMessage
- {
- int OpCode { get; }
- object Payload { get; }
- }
- public class WebSocketMessage
- {
- [JsonProperty("op")]
- public int? Operation { get; set; }
- [JsonProperty("t", NullValueHandling = NullValueHandling.Ignore)]
- public string Type { get; set; }
- [JsonProperty("s", NullValueHandling = NullValueHandling.Ignore)]
- public uint? Sequence { get; set; }
- [JsonProperty("d")]
- public object Payload { get; set; }
-
- public WebSocketMessage() { }
- public WebSocketMessage(IWebSocketMessage msg)
- {
- Operation = msg.OpCode;
- Payload = msg.Payload;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/AcceptInvite.cs b/src/Discord.Net/API/Rest/AcceptInvite.cs
deleted file mode 100644
index 72350253f..000000000
--- a/src/Discord.Net/API/Rest/AcceptInvite.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class AcceptInviteRequest : IRestRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"invites/{InviteCode}";
- object IRestRequest.Payload => null;
-
- public string InviteCode { get; }
-
- public AcceptInviteRequest(string inviteCode)
- {
- InviteCode = inviteCode;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/AckMessage.cs b/src/Discord.Net/API/Rest/AckMessage.cs
deleted file mode 100644
index 387215624..000000000
--- a/src/Discord.Net/API/Rest/AckMessage.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class AckMessageRequest : IRestRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"channels/{ChannelId}/messages/{MessageId}/ack";
- object IRestRequest.Payload => null;
-
- public ulong ChannelId { get; }
- public ulong MessageId { get; }
-
- public AckMessageRequest(ulong channelId, ulong messageId)
- {
- ChannelId = channelId;
- MessageId = messageId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/BeginGuildPrune.cs b/src/Discord.Net/API/Rest/BeginGuildPrune.cs
deleted file mode 100644
index 0a35bdc80..000000000
--- a/src/Discord.Net/API/Rest/BeginGuildPrune.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class BeginGuildPruneRequest : IRestRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/prune";
- object IRestRequest.Payload => this;
-
- public ulong GuildId { get; }
-
- [JsonProperty("days")]
- public int Days { get; set; } = 30;
-
- public BeginGuildPruneRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/CreateChannelInvite.cs b/src/Discord.Net/API/Rest/CreateChannelInvite.cs
deleted file mode 100644
index f60232f48..000000000
--- a/src/Discord.Net/API/Rest/CreateChannelInvite.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class CreateChannelInviteRequest : IRestRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"channels/{ChannelId}/invites";
- object IRestRequest.Payload => this;
-
- public ulong ChannelId { get; }
-
- [JsonProperty("max_age")]
- public int MaxAge { get; set; } = 86400; //24 Hours
- [JsonProperty("max_uses")]
- public int MaxUses { get; set; } = 0;
- [JsonProperty("temporary")]
- public bool IsTemporary { get; set; } = false;
- [JsonProperty("xkcdpass")]
- public bool WithXkcdPass { get; set; } = false;
-
- public CreateChannelInviteRequest(ulong channelId)
- {
- ChannelId = channelId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/CreateChannelInviteParams.cs b/src/Discord.Net/API/Rest/CreateChannelInviteParams.cs
new file mode 100644
index 000000000..570259867
--- /dev/null
+++ b/src/Discord.Net/API/Rest/CreateChannelInviteParams.cs
@@ -0,0 +1,16 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class CreateChannelInviteParams
+ {
+ [JsonProperty("max_age")]
+ public int MaxAge { get; set; } = 86400; //24 Hours
+ [JsonProperty("max_uses")]
+ public int MaxUses { get; set; } = 0;
+ [JsonProperty("temporary")]
+ public bool Temporary { get; set; } = false;
+ [JsonProperty("xkcdpass")]
+ public bool XkcdPass { get; set; } = false;
+ }
+}
diff --git a/src/Discord.Net/API/Rest/CreateDMChannel.cs b/src/Discord.Net/API/Rest/CreateDMChannel.cs
deleted file mode 100644
index 473ecc8e2..000000000
--- a/src/Discord.Net/API/Rest/CreateDMChannel.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class CreateDMChannelRequest : IRestRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"users/@me/channels";
- object IRestRequest.Payload => this;
-
- [JsonProperty("recipient_id")]
- public ulong RecipientId { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/Rest/CreateDMChannelParams.cs b/src/Discord.Net/API/Rest/CreateDMChannelParams.cs
new file mode 100644
index 000000000..9ce033783
--- /dev/null
+++ b/src/Discord.Net/API/Rest/CreateDMChannelParams.cs
@@ -0,0 +1,10 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class CreateDMChannelParams
+ {
+ [JsonProperty("recipient_id")]
+ public ulong RecipientId { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/CreateGuildBan.cs b/src/Discord.Net/API/Rest/CreateGuildBan.cs
deleted file mode 100644
index c76122c5f..000000000
--- a/src/Discord.Net/API/Rest/CreateGuildBan.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- public class CreateGuildBanRequest : IRestRequest
- {
- string IRestRequest.Method => "PUT";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/bans/{UserId}";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
- public ulong UserId { get; }
-
- [JsonProperty("delete-message-days")]
- public int PruneDays { get; set; } = 0;
-
- public CreateGuildBanRequest(ulong guildId, ulong userId)
- {
- GuildId = guildId;
- UserId = userId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/CreateGuildBanParams.cs b/src/Discord.Net/API/Rest/CreateGuildBanParams.cs
new file mode 100644
index 000000000..b8bf5b5cc
--- /dev/null
+++ b/src/Discord.Net/API/Rest/CreateGuildBanParams.cs
@@ -0,0 +1,10 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class CreateGuildBanParams
+ {
+ [JsonProperty("delete-message-days")]
+ public int PruneDays { get; set; } = 0;
+ }
+}
diff --git a/src/Discord.Net/API/Rest/CreateGuildChannel.cs b/src/Discord.Net/API/Rest/CreateGuildChannel.cs
deleted file mode 100644
index 73791825f..000000000
--- a/src/Discord.Net/API/Rest/CreateGuildChannel.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class CreateGuildChannelRequest : IRestRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/channels";
- object IRestRequest.Payload => this;
-
- public ulong GuildId { get; }
-
- [JsonProperty("name")]
- public string Name { get; set; }
- [JsonProperty("type")]
- public ChannelType Type { get; set; }
- [JsonProperty("bitrate")]
- public int Bitrate { get; set; }
-
- public CreateGuildChannelRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/CreateGuildChannelParams.cs b/src/Discord.Net/API/Rest/CreateGuildChannelParams.cs
new file mode 100644
index 000000000..2badcf27c
--- /dev/null
+++ b/src/Discord.Net/API/Rest/CreateGuildChannelParams.cs
@@ -0,0 +1,14 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class CreateGuildChannelParams
+ {
+ [JsonProperty("name")]
+ public string Name { get; set; }
+ [JsonProperty("type")]
+ public ChannelType Type { get; set; }
+ [JsonProperty("bitrate")]
+ public int Bitrate { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/CreateGuildIntegration.cs b/src/Discord.Net/API/Rest/CreateGuildIntegration.cs
deleted file mode 100644
index 7cf48397d..000000000
--- a/src/Discord.Net/API/Rest/CreateGuildIntegration.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class CreateGuildIntegrationRequest : IRestRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/integrations";
- object IRestRequest.Payload => this;
-
- public ulong GuildId { get; }
-
- [JsonProperty("id")]
- public ulong IntegrationId { get; set; }
- [JsonProperty("type")]
- public string Type { get; set; }
-
- public CreateGuildIntegrationRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/CreateGuildIntegrationParams.cs b/src/Discord.Net/API/Rest/CreateGuildIntegrationParams.cs
new file mode 100644
index 000000000..8107548ac
--- /dev/null
+++ b/src/Discord.Net/API/Rest/CreateGuildIntegrationParams.cs
@@ -0,0 +1,12 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class CreateGuildIntegrationParams
+ {
+ [JsonProperty("id")]
+ public ulong Id { get; set; }
+ [JsonProperty("type")]
+ public string Type { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/CreateGuild.cs b/src/Discord.Net/API/Rest/CreateGuildParams.cs
similarity index 52%
rename from src/Discord.Net/API/Rest/CreateGuild.cs
rename to src/Discord.Net/API/Rest/CreateGuildParams.cs
index c2c9532e0..d8563adbd 100644
--- a/src/Discord.Net/API/Rest/CreateGuild.cs
+++ b/src/Discord.Net/API/Rest/CreateGuildParams.cs
@@ -1,17 +1,11 @@
-using Discord.Net.JsonConverters;
-using Discord.Net.Rest;
+using Discord.Net.Converters;
using Newtonsoft.Json;
using System.IO;
namespace Discord.API.Rest
{
- [JsonObject(MemberSerialization.OptIn)]
- public class CreateGuildRequest : IRestRequest
+ public class CreateGuildParams
{
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"guilds";
- object IRestRequest.Payload => this;
-
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("region")]
diff --git a/src/Discord.Net/API/Rest/CreateGuildRole.cs b/src/Discord.Net/API/Rest/CreateGuildRole.cs
deleted file mode 100644
index 367c25465..000000000
--- a/src/Discord.Net/API/Rest/CreateGuildRole.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class CreateGuildRoleRequest : IRestRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/roles";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- public CreateGuildRoleRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/CreateMessage.cs b/src/Discord.Net/API/Rest/CreateMessage.cs
deleted file mode 100644
index 1018a8c66..000000000
--- a/src/Discord.Net/API/Rest/CreateMessage.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class CreateMessageRequest : IRestRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"channels/{ChannelId}/messages";
- object IRestRequest.Payload => this;
-
- public ulong ChannelId { get; }
-
- [JsonProperty("content")]
- public string Content { get; set; }
- [JsonProperty("nonce", NullValueHandling = NullValueHandling.Ignore)]
- public string Nonce { get; set; } = null;
- [JsonProperty("tts", DefaultValueHandling = DefaultValueHandling.Ignore)]
- public bool IsTTS { get; set; } = false;
-
- public CreateMessageRequest(ulong channelId)
- {
- ChannelId = channelId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/CreateMessageParams.cs b/src/Discord.Net/API/Rest/CreateMessageParams.cs
new file mode 100644
index 000000000..6fdc8c2ad
--- /dev/null
+++ b/src/Discord.Net/API/Rest/CreateMessageParams.cs
@@ -0,0 +1,14 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class CreateMessageParams
+ {
+ [JsonProperty("content")]
+ public string Content { get; set; } = "";
+ [JsonProperty("nonce", NullValueHandling = NullValueHandling.Ignore)]
+ public string Nonce { get; set; } = null;
+ [JsonProperty("tts", DefaultValueHandling = DefaultValueHandling.Ignore)]
+ public bool IsTTS { get; set; } = false;
+ }
+}
diff --git a/src/Discord.Net/API/Rest/DeleteChannel.cs b/src/Discord.Net/API/Rest/DeleteChannel.cs
deleted file mode 100644
index fa9b10c10..000000000
--- a/src/Discord.Net/API/Rest/DeleteChannel.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class DeleteChannelRequest : IRestRequest
- {
- string IRestRequest.Method => "DELETE";
- string IRestRequest.Endpoint => $"channels/{ChannelId}";
- object IRestRequest.Payload => null;
-
- public ulong ChannelId { get; }
-
- public DeleteChannelRequest(ulong channelId)
- {
- ChannelId = channelId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/DeleteChannelPermission.cs b/src/Discord.Net/API/Rest/DeleteChannelPermission.cs
deleted file mode 100644
index 658388641..000000000
--- a/src/Discord.Net/API/Rest/DeleteChannelPermission.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class DeleteChannelPermissionsRequest : IRestRequest
- {
- string IRestRequest.Method => "DELETE";
- string IRestRequest.Endpoint => $"channels/{ChannelId}/permissions/{TargetId}";
- object IRestRequest.Payload => null;
-
- public ulong ChannelId { get; }
- public ulong TargetId { get; }
-
- public DeleteChannelPermissionsRequest(ulong channelId, ulong targetId)
- {
- ChannelId = channelId;
- TargetId = targetId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/DeleteGuild.cs b/src/Discord.Net/API/Rest/DeleteGuild.cs
deleted file mode 100644
index d1a14fbc9..000000000
--- a/src/Discord.Net/API/Rest/DeleteGuild.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class DeleteGuildRequest : IRestRequest
- {
- string IRestRequest.Method => "DELETE";
- string IRestRequest.Endpoint => $"guilds/{GuildId}";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- public DeleteGuildRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/DeleteGuildIntegration.cs b/src/Discord.Net/API/Rest/DeleteGuildIntegration.cs
deleted file mode 100644
index b25418c1a..000000000
--- a/src/Discord.Net/API/Rest/DeleteGuildIntegration.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class DeleteGuildIntegrationRequest : IRestRequest
- {
- string IRestRequest.Method => "DELETE";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/integrations/{IntegrationId}";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
- public ulong IntegrationId { get; }
-
- public DeleteGuildIntegrationRequest(ulong guildId, ulong integrationId)
- {
- GuildId = guildId;
- IntegrationId = integrationId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/DeleteGuildRole.cs b/src/Discord.Net/API/Rest/DeleteGuildRole.cs
deleted file mode 100644
index cbb21eec3..000000000
--- a/src/Discord.Net/API/Rest/DeleteGuildRole.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class DeleteGuildRoleRequest : IRestRequest
- {
- string IRestRequest.Method => "DELETE";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/roles/{RoleId}";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
- public ulong RoleId { get; }
-
- public DeleteGuildRoleRequest(ulong guildId, ulong roleId)
- {
- GuildId = guildId;
- RoleId = roleId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/DeleteInvite.cs b/src/Discord.Net/API/Rest/DeleteInvite.cs
deleted file mode 100644
index 388255862..000000000
--- a/src/Discord.Net/API/Rest/DeleteInvite.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class DeleteInviteRequest : IRestRequest
- {
- string IRestRequest.Method => "DELETE";
- string IRestRequest.Endpoint => $"invites/{InviteCode}";
- object IRestRequest.Payload => null;
-
- public string InviteCode { get; }
-
- public DeleteInviteRequest(string inviteCode)
- {
- InviteCode = inviteCode;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/DeleteMessage.cs b/src/Discord.Net/API/Rest/DeleteMessage.cs
deleted file mode 100644
index c9d95deba..000000000
--- a/src/Discord.Net/API/Rest/DeleteMessage.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class DeleteMessageRequest : IRestRequest
- {
- string IRestRequest.Method => "DELETE";
- string IRestRequest.Endpoint => $"channels/{ChannelId}/messages/{MessageId}";
- object IRestRequest.Payload => null;
-
- public ulong ChannelId { get; }
- public ulong MessageId { get; }
-
- public DeleteMessageRequest(ulong channelId, ulong messageId)
- {
- ChannelId = channelId;
- MessageId = messageId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/DeleteMessagesParam.cs b/src/Discord.Net/API/Rest/DeleteMessagesParam.cs
new file mode 100644
index 000000000..8a794499c
--- /dev/null
+++ b/src/Discord.Net/API/Rest/DeleteMessagesParam.cs
@@ -0,0 +1,11 @@
+using Newtonsoft.Json;
+using System.Collections.Generic;
+
+namespace Discord.API.Rest
+{
+ public class DeleteMessagesParam
+ {
+ [JsonProperty("messages")]
+ public IEnumerable MessageIds { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/GetChannel.cs b/src/Discord.Net/API/Rest/GetChannel.cs
deleted file mode 100644
index 12d258836..000000000
--- a/src/Discord.Net/API/Rest/GetChannel.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetChannelRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"channels/{ChannelId}";
- object IRestRequest.Payload => null;
-
- public ulong ChannelId { get; }
-
- public GetChannelRequest(ulong channelId)
- {
- ChannelId = channelId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetChannelInvites.cs b/src/Discord.Net/API/Rest/GetChannelInvites.cs
deleted file mode 100644
index 7532fb64f..000000000
--- a/src/Discord.Net/API/Rest/GetChannelInvites.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class GetChannelInvitesRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"channels/{ChannelId}/invites";
- object IRestRequest.Payload => null;
-
- public ulong ChannelId { get; }
-
- public GetChannelInvitesRequest(ulong channelId)
- {
- ChannelId = channelId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetChannelMessages.cs b/src/Discord.Net/API/Rest/GetChannelMessages.cs
deleted file mode 100644
index a0e6b5afe..000000000
--- a/src/Discord.Net/API/Rest/GetChannelMessages.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class GetChannelMessagesRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"channels/{ChannelId}/messages?limit={Limit}&{RelativeDir}={RelativeId}";
- object IRestRequest.Payload => null;
-
- public ulong ChannelId { get; }
-
- public Relative RelativeDir { get; set; }
- public ulong RelativeId { get; set; } = 0;
-
- [JsonProperty("limit")]
- public int Limit { get; set; } = 100;
-
- [JsonProperty("before")]
- public ulong Before => RelativeId;
- private bool ShouldSerializeBefore => RelativeDir == Relative.Before;
-
- [JsonProperty("after")]
- public ulong After => RelativeId;
- private bool ShouldSerializeAfter => RelativeDir == Relative.After;
-
- public GetChannelMessagesRequest(ulong channelId)
- {
- ChannelId = channelId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetChannelMessagesParams.cs b/src/Discord.Net/API/Rest/GetChannelMessagesParams.cs
new file mode 100644
index 000000000..ec6e5fe79
--- /dev/null
+++ b/src/Discord.Net/API/Rest/GetChannelMessagesParams.cs
@@ -0,0 +1,9 @@
+namespace Discord.API.Rest
+{
+ public class GetChannelMessagesParams
+ {
+ public int Limit { get; set; } = DiscordConfig.MaxMessagesPerBatch;
+ public Direction RelativeDirection { get; set; } = Direction.Before;
+ public ulong? RelativeMessageId { get; set; } = null;
+ }
+}
diff --git a/src/Discord.Net/API/Rest/GetCurrentUser.cs b/src/Discord.Net/API/Rest/GetCurrentUser.cs
deleted file mode 100644
index 76bc3e838..000000000
--- a/src/Discord.Net/API/Rest/GetCurrentUser.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetCurrentUserRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"users/@me";
- object IRestRequest.Payload => null;
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetCurrentUserConnections.cs b/src/Discord.Net/API/Rest/GetCurrentUserConnections.cs
deleted file mode 100644
index 102affaa7..000000000
--- a/src/Discord.Net/API/Rest/GetCurrentUserConnections.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetCurrentUserConnectionsRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"users/@me/connections";
- object IRestRequest.Payload => null;
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetCurrentUserDMs.cs b/src/Discord.Net/API/Rest/GetCurrentUserDMs.cs
deleted file mode 100644
index 31cc1edeb..000000000
--- a/src/Discord.Net/API/Rest/GetCurrentUserDMs.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetCurrentUserDMsRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"users/@me/channels";
- object IRestRequest.Payload => null;
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetCurrentUserGuilds.cs b/src/Discord.Net/API/Rest/GetCurrentUserGuilds.cs
deleted file mode 100644
index e3423c3f8..000000000
--- a/src/Discord.Net/API/Rest/GetCurrentUserGuilds.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetCurrentUserGuildsRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"users/@me/guilds";
- object IRestRequest.Payload => null;
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetGateway.cs b/src/Discord.Net/API/Rest/GetGateway.cs
deleted file mode 100644
index 3581f9f00..000000000
--- a/src/Discord.Net/API/Rest/GetGateway.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- public class GetGatewayRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"gateway";
- object IRestRequest.Payload => null;
- }
-
- public class GetGatewayResponse
- {
- [JsonProperty("url")]
- public string Url { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/Redirect.cs b/src/Discord.Net/API/Rest/GetGatewayResponse.cs
similarity index 62%
rename from src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/Redirect.cs
rename to src/Discord.Net/API/Rest/GetGatewayResponse.cs
index 180bf574f..48ca524d3 100644
--- a/src/Discord.Net/API/GatewaySocket/Unconfirmed/Events/Redirect.cs
+++ b/src/Discord.Net/API/Rest/GetGatewayResponse.cs
@@ -1,8 +1,8 @@
using Newtonsoft.Json;
-namespace Discord.API.GatewaySocket
+namespace Discord.API.Rest
{
- public class RedirectEvent
+ public class GetGatewayResponse
{
[JsonProperty("url")]
public string Url { get; set; }
diff --git a/src/Discord.Net/API/Rest/GetGuild.cs b/src/Discord.Net/API/Rest/GetGuild.cs
deleted file mode 100644
index 2e83d261a..000000000
--- a/src/Discord.Net/API/Rest/GetGuild.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetGuildRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"guilds/{GuildId}";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- public GetGuildRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetGuildBans.cs b/src/Discord.Net/API/Rest/GetGuildBans.cs
deleted file mode 100644
index 73a02b43e..000000000
--- a/src/Discord.Net/API/Rest/GetGuildBans.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetGuildBansRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/bans";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- public GetGuildBansRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetGuildChannels.cs b/src/Discord.Net/API/Rest/GetGuildChannels.cs
deleted file mode 100644
index f20e9ec4f..000000000
--- a/src/Discord.Net/API/Rest/GetGuildChannels.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetGuildChannelsRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"guild/{GuildId}/channels";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- public GetGuildChannelsRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetGuildEmbed.cs b/src/Discord.Net/API/Rest/GetGuildEmbed.cs
deleted file mode 100644
index 0eb67e680..000000000
--- a/src/Discord.Net/API/Rest/GetGuildEmbed.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetGuildEmbedRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/embed";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- public GetGuildEmbedRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetGuildIntegrations.cs b/src/Discord.Net/API/Rest/GetGuildIntegrations.cs
deleted file mode 100644
index ba2b1ce2d..000000000
--- a/src/Discord.Net/API/Rest/GetGuildIntegrations.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetGuildIntegrationsRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/integrations";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- public GetGuildIntegrationsRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetGuildInvites.cs b/src/Discord.Net/API/Rest/GetGuildInvites.cs
deleted file mode 100644
index 4a20770b1..000000000
--- a/src/Discord.Net/API/Rest/GetGuildInvites.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetGuildInvitesRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/invites";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- public GetGuildInvitesRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetGuildMember.cs b/src/Discord.Net/API/Rest/GetGuildMember.cs
deleted file mode 100644
index 0dc1d8077..000000000
--- a/src/Discord.Net/API/Rest/GetGuildMember.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetGuildMemberRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/members/{UserId}";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
- public ulong UserId { get; }
-
- public GetGuildMemberRequest(ulong guildId, ulong userId)
- {
- GuildId = guildId;
- UserId = userId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetGuildMembersParams.cs b/src/Discord.Net/API/Rest/GetGuildMembersParams.cs
new file mode 100644
index 000000000..59931e934
--- /dev/null
+++ b/src/Discord.Net/API/Rest/GetGuildMembersParams.cs
@@ -0,0 +1,8 @@
+namespace Discord.API.Rest
+{
+ public class GetGuildMembersParams
+ {
+ public int? Limit { get; set; } = null;
+ public int Offset { get; set; } = 0;
+ }
+}
diff --git a/src/Discord.Net/API/Rest/GetGuildPruneCount.cs b/src/Discord.Net/API/Rest/GetGuildPruneCount.cs
deleted file mode 100644
index 469b5fa01..000000000
--- a/src/Discord.Net/API/Rest/GetGuildPruneCount.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class GetGuildPruneCountRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/prune";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- [JsonProperty("days")]
- public int Days { get; set; } = 30;
-
- public GetGuildPruneCountRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-
- public class GetGuildPruneCountResponse
- {
- [JsonProperty("pruned")]
- public int Pruned { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetGuildPruneCountResponse.cs b/src/Discord.Net/API/Rest/GetGuildPruneCountResponse.cs
new file mode 100644
index 000000000..9b757d14a
--- /dev/null
+++ b/src/Discord.Net/API/Rest/GetGuildPruneCountResponse.cs
@@ -0,0 +1,10 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class GetGuildPruneCountResponse
+ {
+ [JsonProperty("pruned")]
+ public int Pruned { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/GetGuildRoles.cs b/src/Discord.Net/API/Rest/GetGuildRoles.cs
deleted file mode 100644
index f8ff0a9b3..000000000
--- a/src/Discord.Net/API/Rest/GetGuildRoles.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetGuildRolesRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"guild/{GuildId}/roles";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- public GetGuildRolesRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetGuildVoiceRegions.cs b/src/Discord.Net/API/Rest/GetGuildVoiceRegions.cs
deleted file mode 100644
index ed631e7e2..000000000
--- a/src/Discord.Net/API/Rest/GetGuildVoiceRegions.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetGuildVoiceRegionsRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/regions";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- public GetGuildVoiceRegionsRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetInvite.cs b/src/Discord.Net/API/Rest/GetInvite.cs
deleted file mode 100644
index fccbc79c9..000000000
--- a/src/Discord.Net/API/Rest/GetInvite.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetInviteRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"invites/{InviteCode}";
- object IRestRequest.Payload => null;
-
- public string InviteCode { get; }
-
- public GetInviteRequest(string inviteCode)
- {
- InviteCode = inviteCode;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GetUser.cs b/src/Discord.Net/API/Rest/GetUser.cs
deleted file mode 100644
index 1cfeb82be..000000000
--- a/src/Discord.Net/API/Rest/GetUser.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class GetUserRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"users/{UserId}";
- object IRestRequest.Payload => null;
-
- public ulong UserId { get; }
-
- public GetUserRequest(ulong userId)
- {
- UserId = userId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/GuildPruneParams.cs b/src/Discord.Net/API/Rest/GuildPruneParams.cs
new file mode 100644
index 000000000..12a7a11da
--- /dev/null
+++ b/src/Discord.Net/API/Rest/GuildPruneParams.cs
@@ -0,0 +1,10 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class GuildPruneParams
+ {
+ [JsonProperty("days")]
+ public int Days = 30;
+ }
+}
diff --git a/src/Discord.Net/API/Rest/LeaveGuild.cs b/src/Discord.Net/API/Rest/LeaveGuild.cs
deleted file mode 100644
index a62fdd089..000000000
--- a/src/Discord.Net/API/Rest/LeaveGuild.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class LeaveGuildRequest : IRestRequest
- {
- string IRestRequest.Method => "DELETE";
- string IRestRequest.Endpoint => $"users/@me/guilds/{GuildId}";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- public LeaveGuildRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ListGuildMembers.cs b/src/Discord.Net/API/Rest/ListGuildMembers.cs
deleted file mode 100644
index 4577b8910..000000000
--- a/src/Discord.Net/API/Rest/ListGuildMembers.cs
+++ /dev/null
@@ -1,24 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- public class ListGuildMembersRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"guild/{GuildId}/members";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
-
- [JsonProperty("limit")]
- public int Limit { get; } = 1;
- [JsonProperty("offset")]
- public int Offset { get; } = 0;
-
- public ListGuildMembersRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ModifyChannelPermission.cs b/src/Discord.Net/API/Rest/ModifyChannelPermission.cs
deleted file mode 100644
index e38685bb7..000000000
--- a/src/Discord.Net/API/Rest/ModifyChannelPermission.cs
+++ /dev/null
@@ -1,27 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class ModifyChannelPermissionsRequest : IRestRequest
- {
- string IRestRequest.Method => "PUT";
- string IRestRequest.Endpoint => $"channels/{ChannelId}/permissions/{TargetId}";
- object IRestRequest.Payload => this;
-
- public ulong ChannelId { get; }
- public ulong TargetId { get; }
-
- [JsonProperty("allow")]
- public uint Allow { get; set; }
- [JsonProperty("deny")]
- public uint Deny { get; set; }
-
- public ModifyChannelPermissionsRequest(ulong channelId, ulong targetId)
- {
- ChannelId = channelId;
- TargetId = targetId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ModifyChannelPermissionsParams.cs b/src/Discord.Net/API/Rest/ModifyChannelPermissionsParams.cs
new file mode 100644
index 000000000..d02df347d
--- /dev/null
+++ b/src/Discord.Net/API/Rest/ModifyChannelPermissionsParams.cs
@@ -0,0 +1,12 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class ModifyChannelPermissionsParams
+ {
+ [JsonProperty("allow")]
+ public uint Allow { get; set; }
+ [JsonProperty("deny")]
+ public uint Deny { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/ModifyCurrentUser.cs b/src/Discord.Net/API/Rest/ModifyCurrentUserParams.cs
similarity index 62%
rename from src/Discord.Net/API/Rest/ModifyCurrentUser.cs
rename to src/Discord.Net/API/Rest/ModifyCurrentUserParams.cs
index afc1c3b74..f1512536f 100644
--- a/src/Discord.Net/API/Rest/ModifyCurrentUser.cs
+++ b/src/Discord.Net/API/Rest/ModifyCurrentUserParams.cs
@@ -1,17 +1,11 @@
-using Discord.Net.JsonConverters;
-using Discord.Net.Rest;
+using Discord.Net.Converters;
using Newtonsoft.Json;
using System.IO;
namespace Discord.API.Rest
{
- [JsonObject(MemberSerialization.OptIn)]
- public class ModifyCurrentUserRequest : IRestRequest
+ public class ModifyCurrentUserParams
{
- string IRestRequest.Method => "PATCH";
- string IRestRequest.Endpoint => $"users/@me";
- object IRestRequest.Payload => this;
-
[JsonProperty("username")]
public string Username { get; set; }
[JsonProperty("email")]
diff --git a/src/Discord.Net/API/Rest/ModifyGuildChannel.cs b/src/Discord.Net/API/Rest/ModifyGuildChannel.cs
deleted file mode 100644
index eeb909e84..000000000
--- a/src/Discord.Net/API/Rest/ModifyGuildChannel.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class ModifyGuildChannelRequest : IRestRequest
- {
- string IRestRequest.Method => "PATCH";
- string IRestRequest.Endpoint => $"channels/{ChannelId}";
- object IRestRequest.Payload => this;
-
- public ulong ChannelId { get; set; }
-
- [JsonProperty("name")]
- public string Name { get; set; }
- [JsonProperty("position")]
- public int Position { get; set; }
-
- public ModifyGuildChannelRequest(ulong channelId)
- {
- ChannelId = channelId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildChannelParams.cs b/src/Discord.Net/API/Rest/ModifyGuildChannelParams.cs
new file mode 100644
index 000000000..b82f7b8d2
--- /dev/null
+++ b/src/Discord.Net/API/Rest/ModifyGuildChannelParams.cs
@@ -0,0 +1,12 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class ModifyGuildChannelParams
+ {
+ [JsonProperty("name")]
+ public string Name { get; set; }
+ [JsonProperty("position")]
+ public int Position { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildChannels.cs b/src/Discord.Net/API/Rest/ModifyGuildChannels.cs
deleted file mode 100644
index de9b97b88..000000000
--- a/src/Discord.Net/API/Rest/ModifyGuildChannels.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-using System;
-
-namespace Discord.API.Rest
-{
- public class ModifyGuildChannelsRequest : IRestRequest
- {
- string IRestRequest.Method => "PATCH";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/channels";
- object IRestRequest.Payload => Requests;
-
- public ulong GuildId { get; }
-
- public ModifyGuildChannelRequest[] Requests { get; set; } = Array.Empty();
-
- public ModifyGuildChannelsRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildChannelsParams.cs b/src/Discord.Net/API/Rest/ModifyGuildChannelsParams.cs
new file mode 100644
index 000000000..73ec46f7d
--- /dev/null
+++ b/src/Discord.Net/API/Rest/ModifyGuildChannelsParams.cs
@@ -0,0 +1,12 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class ModifyGuildChannelsParams
+ {
+ [JsonProperty("id")]
+ public ulong Id { get; set; }
+ [JsonProperty("position")]
+ public int Position { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildEmbed.cs b/src/Discord.Net/API/Rest/ModifyGuildEmbed.cs
deleted file mode 100644
index c896e5a34..000000000
--- a/src/Discord.Net/API/Rest/ModifyGuildEmbed.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class ModifyGuildEmbedRequest : IRestRequest
- {
- string IRestRequest.Method => "PATCH";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/embed";
- object IRestRequest.Payload => this;
-
- public ulong GuildId { get; }
-
- [JsonProperty("enabled")]
- public bool Enabled { get; set; }
- [JsonProperty("channel_id")]
- public ulong? ChannelId { get; set; }
-
- public ModifyGuildEmbedRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildEmbedParams.cs b/src/Discord.Net/API/Rest/ModifyGuildEmbedParams.cs
new file mode 100644
index 000000000..731497223
--- /dev/null
+++ b/src/Discord.Net/API/Rest/ModifyGuildEmbedParams.cs
@@ -0,0 +1,13 @@
+using Discord.Net.Converters;
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class ModifyGuildEmbedParams
+ {
+ [JsonProperty("enabled")]
+ public bool Enabled { get; set; }
+ [JsonProperty("channel"), JsonConverter(typeof(UInt64EntityConverter))]
+ public IVoiceChannel Channel { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildIntegration.cs b/src/Discord.Net/API/Rest/ModifyGuildIntegration.cs
deleted file mode 100644
index b093888da..000000000
--- a/src/Discord.Net/API/Rest/ModifyGuildIntegration.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class ModifyGuildIntegrationRequest : IRestRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/integrations/{IntegrationId}";
- object IRestRequest.Payload => this;
-
- public ulong GuildId { get; }
- public ulong IntegrationId { get; }
-
- [JsonProperty("expire_behavior")]
- public int ExpireBehavior { get; set; }
- [JsonProperty("expire_grace_period")]
- public int ExpireGracePeriod { get; set; }
- [JsonProperty("enable_emoticons")]
- public bool EnableEmoticons { get; set; }
-
- public ModifyGuildIntegrationRequest(ulong guildId, ulong integrationId)
- {
- GuildId = guildId;
- IntegrationId = integrationId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildIntegrationParams.cs b/src/Discord.Net/API/Rest/ModifyGuildIntegrationParams.cs
new file mode 100644
index 000000000..9a5e9f81c
--- /dev/null
+++ b/src/Discord.Net/API/Rest/ModifyGuildIntegrationParams.cs
@@ -0,0 +1,14 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class ModifyGuildIntegrationParams
+ {
+ [JsonProperty("expire_behavior")]
+ public int ExpireBehavior { get; set; }
+ [JsonProperty("expire_grace_period")]
+ public int ExpireGracePeriod { get; set; }
+ [JsonProperty("enable_emoticons")]
+ public bool EnableEmoticons { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildMember.cs b/src/Discord.Net/API/Rest/ModifyGuildMember.cs
deleted file mode 100644
index cdbc1271f..000000000
--- a/src/Discord.Net/API/Rest/ModifyGuildMember.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class ModifyGuildMemberRequest : IRestRequest
- {
- string IRestRequest.Method => "PATCH";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/members/{UserId}";
- object IRestRequest.Payload => this;
-
- public ulong GuildId { get; }
- public ulong UserId { get; }
-
- [JsonProperty("roles")]
- public ulong[] Roles { get; set; }
- [JsonProperty("mute")]
- public bool Mute { get; set; }
- [JsonProperty("deaf")]
- public bool Deaf { get; set; }
- [JsonProperty("channel_id")]
- public ulong? ChannelId { get; set; }
-
- public ModifyGuildMemberRequest(ulong guildId, ulong userId)
- {
- GuildId = guildId;
- UserId = userId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildMemberParams.cs b/src/Discord.Net/API/Rest/ModifyGuildMemberParams.cs
new file mode 100644
index 000000000..396e0314d
--- /dev/null
+++ b/src/Discord.Net/API/Rest/ModifyGuildMemberParams.cs
@@ -0,0 +1,17 @@
+using Discord.Net.Converters;
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class ModifyGuildMemberParams
+ {
+ [JsonProperty("roles")]
+ public ulong[] Roles { get; set; }
+ [JsonProperty("mute")]
+ public bool Mute { get; set; }
+ [JsonProperty("deaf")]
+ public bool Deaf { get; set; }
+ [JsonProperty("channel_id"), JsonConverter(typeof(UInt64EntityConverter))]
+ public IVoiceChannel VoiceChannel { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/ModifyGuild.cs b/src/Discord.Net/API/Rest/ModifyGuildParams.cs
similarity index 56%
rename from src/Discord.Net/API/Rest/ModifyGuild.cs
rename to src/Discord.Net/API/Rest/ModifyGuildParams.cs
index 03bf58073..1d5969ab2 100644
--- a/src/Discord.Net/API/Rest/ModifyGuild.cs
+++ b/src/Discord.Net/API/Rest/ModifyGuildParams.cs
@@ -1,23 +1,15 @@
-using Discord.Net.JsonConverters;
-using Discord.Net.Rest;
+using Discord.Net.Converters;
using Newtonsoft.Json;
using System.IO;
namespace Discord.API.Rest
{
- [JsonObject(MemberSerialization.OptIn)]
- public class ModifyGuildRequest : IRestRequest
- {
- string IRestRequest.Method => "PATCH";
- string IRestRequest.Endpoint => $"guilds/{GuildId}";
- object IRestRequest.Payload => this;
-
- public ulong GuildId { get; }
-
+ public class ModifyGuildParams
+ {
[JsonProperty("name")]
public string Name { get; set; }
- [JsonProperty("region")]
- public VoiceRegion Region { get; set; }
+ [JsonProperty("region"), JsonConverterAttribute(typeof(StringEntityConverter))]
+ public IVoiceRegion Region { get; set; }
[JsonProperty("verification_level")]
public int VerificationLevel { get; set; }
[JsonProperty("afk_channel_id")]
@@ -30,10 +22,5 @@ namespace Discord.API.Rest
public GuildMember Owner { get; set; }
[JsonProperty("splash"), JsonConverter(typeof(ImageConverter))]
public Stream Splash { get; set; }
-
- public ModifyGuildRequest(ulong guildId)
- {
- GuildId = guildId;
- }
}
}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildRole.cs b/src/Discord.Net/API/Rest/ModifyGuildRole.cs
deleted file mode 100644
index 6d7e09c59..000000000
--- a/src/Discord.Net/API/Rest/ModifyGuildRole.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- public class ModifyGuildRoleRequest : IRestRequest
- {
- string IRestRequest.Method => "PATCH";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/roles/{RoleId}";
- object IRestRequest.Payload => this;
-
- public ulong GuildId { get; }
- public ulong RoleId { get; }
-
- [JsonProperty("name")]
- public string Name { get; set; }
- [JsonProperty("permissions")]
- public int Permissions { get; set; }
- [JsonProperty("position")]
- public int Position { get; set; }
- [JsonProperty("color")]
- public int Color { get; set; }
- [JsonProperty("hoist")]
- public bool Hoist { get; set; }
-
- public ModifyGuildRoleRequest(ulong guildId, ulong roleId)
- {
- GuildId = guildId;
- RoleId = roleId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildRoleParams.cs b/src/Discord.Net/API/Rest/ModifyGuildRoleParams.cs
new file mode 100644
index 000000000..171d9cabe
--- /dev/null
+++ b/src/Discord.Net/API/Rest/ModifyGuildRoleParams.cs
@@ -0,0 +1,18 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class ModifyGuildRoleParams
+ {
+ [JsonProperty("name")]
+ public string Name { get; set; }
+ [JsonProperty("permissions")]
+ public uint Permissions { get; set; }
+ [JsonProperty("position")]
+ public int Position { get; set; }
+ [JsonProperty("color")]
+ public uint Color { get; set; }
+ [JsonProperty("hoist")]
+ public bool Hoist { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildRoles.cs b/src/Discord.Net/API/Rest/ModifyGuildRoles.cs
deleted file mode 100644
index 905f51b11..000000000
--- a/src/Discord.Net/API/Rest/ModifyGuildRoles.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using Discord.Net.Rest;
-using System;
-
-namespace Discord.API.Rest
-{
- public class ModifyGuildRolesRequest : IRestRequest
- {
- string IRestRequest.Method => "PATCH";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/roles";
- object IRestRequest.Payload => Requests;
-
- public ulong GuildId { get; }
-
- public ModifyGuildRoleRequest[] Requests { get; set; } = Array.Empty();
-
- public ModifyGuildRolesRequest(ulong guildId)
- {
- GuildId = guildId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ModifyGuildRolesParams.cs b/src/Discord.Net/API/Rest/ModifyGuildRolesParams.cs
new file mode 100644
index 000000000..7002079d5
--- /dev/null
+++ b/src/Discord.Net/API/Rest/ModifyGuildRolesParams.cs
@@ -0,0 +1,10 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class ModifyGuildRolesParams : ModifyGuildRoleParams
+ {
+ [JsonProperty("id")]
+ public ulong Id { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/ModifyMessage.cs b/src/Discord.Net/API/Rest/ModifyMessage.cs
deleted file mode 100644
index 971c8026e..000000000
--- a/src/Discord.Net/API/Rest/ModifyMessage.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class ModifyMessageRequest : IRestRequest
- {
- string IRestRequest.Method => "PATCH";
- string IRestRequest.Endpoint => $"channels/{ChannelId}/messages/{MessageId}";
- object IRestRequest.Payload => this;
-
- public ulong ChannelId { get; }
- public ulong MessageId { get; }
-
- [JsonProperty("content")]
- public string Content { get; set; } = "";
-
- public ModifyMessageRequest(ulong channelId, ulong messageId)
- {
- ChannelId = channelId;
- MessageId = messageId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ModifyMessageParams.cs b/src/Discord.Net/API/Rest/ModifyMessageParams.cs
new file mode 100644
index 000000000..d3b90b903
--- /dev/null
+++ b/src/Discord.Net/API/Rest/ModifyMessageParams.cs
@@ -0,0 +1,10 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class ModifyMessageParams
+ {
+ [JsonProperty("content")]
+ public string Content { get; set; } = "";
+ }
+}
diff --git a/src/Discord.Net/API/Rest/ModifyTextChannel.cs b/src/Discord.Net/API/Rest/ModifyTextChannel.cs
deleted file mode 100644
index f3d672daf..000000000
--- a/src/Discord.Net/API/Rest/ModifyTextChannel.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class ModifyTextChannelRequest : ModifyGuildChannelRequest
- {
- [JsonProperty("topic")]
- public string Topic { get; set; }
-
- public ModifyTextChannelRequest(ulong channelId)
- : base(channelId)
- {
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ModifyTextChannelParams.cs b/src/Discord.Net/API/Rest/ModifyTextChannelParams.cs
new file mode 100644
index 000000000..cee07e7f1
--- /dev/null
+++ b/src/Discord.Net/API/Rest/ModifyTextChannelParams.cs
@@ -0,0 +1,10 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class ModifyTextChannelParams : ModifyGuildChannelParams
+ {
+ [JsonProperty("topic")]
+ public string Topic { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/ModifyVoiceChannel.cs b/src/Discord.Net/API/Rest/ModifyVoiceChannel.cs
deleted file mode 100644
index e8bdfac8f..000000000
--- a/src/Discord.Net/API/Rest/ModifyVoiceChannel.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- [JsonObject(MemberSerialization.OptIn)]
- public class ModifyVoiceChannelRequest : ModifyGuildChannelRequest
- {
- [JsonProperty("bitrate")]
- public int Bitrate { get; set; }
-
- public ModifyVoiceChannelRequest(ulong channelId)
- : base(channelId)
- {
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/ModifyVoiceChannelParams.cs b/src/Discord.Net/API/Rest/ModifyVoiceChannelParams.cs
new file mode 100644
index 000000000..1fbae95ac
--- /dev/null
+++ b/src/Discord.Net/API/Rest/ModifyVoiceChannelParams.cs
@@ -0,0 +1,10 @@
+using Newtonsoft.Json;
+
+namespace Discord.API.Rest
+{
+ public class ModifyVoiceChannelParams : ModifyGuildChannelParams
+ {
+ [JsonProperty("bitrate")]
+ public int Bitrate { get; set; }
+ }
+}
diff --git a/src/Discord.Net/API/Rest/QueryUser.cs b/src/Discord.Net/API/Rest/QueryUser.cs
deleted file mode 100644
index 45a194805..000000000
--- a/src/Discord.Net/API/Rest/QueryUser.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using Discord.Net.Rest;
-using System;
-
-namespace Discord.API.Rest
-{
- public class QueryUserRequest : IRestRequest
- {
- string IRestRequest.Method => "GET";
- string IRestRequest.Endpoint => $"users?q={Uri.EscapeDataString(Query)}&limit={Limit}";
- object IRestRequest.Payload => null;
-
- public string Query { get; set; }
- public int Limit { get; set; } = 25;
-
- public QueryUserRequest()
- {
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/RemoveGuildBan.cs b/src/Discord.Net/API/Rest/RemoveGuildBan.cs
deleted file mode 100644
index 4f5df1243..000000000
--- a/src/Discord.Net/API/Rest/RemoveGuildBan.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class RemoveGuildBanRequest : IRestRequest
- {
- string IRestRequest.Method => "DELETE";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/bans/{UserId}";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
- public ulong UserId { get; }
-
- public RemoveGuildBanRequest(ulong guildId, ulong userId)
- {
- GuildId = guildId;
- UserId = userId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/RemoveGuildMember.cs b/src/Discord.Net/API/Rest/RemoveGuildMember.cs
deleted file mode 100644
index a5b39b1db..000000000
--- a/src/Discord.Net/API/Rest/RemoveGuildMember.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class RemoveGuildMemberRequest : IRestRequest
- {
- string IRestRequest.Method => "DELETE";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/members/{UserId}";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
- public ulong UserId { get; }
-
- public RemoveGuildMemberRequest(ulong guildId, ulong userId)
- {
- GuildId = guildId;
- UserId = userId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/SyncGuildIntegration.cs b/src/Discord.Net/API/Rest/SyncGuildIntegration.cs
deleted file mode 100644
index 4c7f0acfa..000000000
--- a/src/Discord.Net/API/Rest/SyncGuildIntegration.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using Discord.Net.Rest;
-using Newtonsoft.Json;
-
-namespace Discord.API.Rest
-{
- public class SyncGuildIntegrationRequest : IRestRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"guilds/{GuildId}/integrations/{IntegrationId}/sync";
- object IRestRequest.Payload => null;
-
- public ulong GuildId { get; }
- public ulong IntegrationId { get; }
-
- public SyncGuildIntegrationRequest(ulong guildId, ulong integrationId)
- {
- GuildId = guildId;
- IntegrationId = integrationId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/TriggerTypingIndicator.cs b/src/Discord.Net/API/Rest/TriggerTypingIndicator.cs
deleted file mode 100644
index 3c0baa855..000000000
--- a/src/Discord.Net/API/Rest/TriggerTypingIndicator.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using Discord.Net.Rest;
-
-namespace Discord.API.Rest
-{
- public class TriggerTypingIndicatorRequest : IRestRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"channels/{ChannelId}/typing";
- object IRestRequest.Payload => null;
-
- public ulong ChannelId { get; }
-
- public TriggerTypingIndicatorRequest(ulong channelId)
- {
- ChannelId = channelId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/UploadFile.cs b/src/Discord.Net/API/Rest/UploadFile.cs
deleted file mode 100644
index a874eff32..000000000
--- a/src/Discord.Net/API/Rest/UploadFile.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using Discord.Net.Rest;
-using System.Collections.Generic;
-using System.Collections.Immutable;
-using System.IO;
-
-namespace Discord.API.Rest
-{
- public class UploadFileRequest : IRestFileRequest
- {
- string IRestRequest.Method => "POST";
- string IRestRequest.Endpoint => $"channels/{ChannelId}/messages";
- object IRestRequest.Payload => null;
-
- string IRestFileRequest.Filename => Filename;
- Stream IRestFileRequest.Stream => Stream;
- IReadOnlyList IRestFileRequest.MultipartParameters => ImmutableArray.Create(
- new RestParameter("content", Content),
- new RestParameter("nonce", Nonce),
- new RestParameter("tts", IsTTS)
- );
-
- public ulong ChannelId { get; }
-
- public string Content { get; set; }
- public string Nonce { get; set; }
- public bool IsTTS { get; set; }
- public Stream Stream { get; set; }
- public string Filename { get; set; }
-
- public UploadFileRequest(ulong channelId)
- {
- ChannelId = channelId;
- }
- }
-}
diff --git a/src/Discord.Net/API/Rest/UploadFileParams.cs b/src/Discord.Net/API/Rest/UploadFileParams.cs
new file mode 100644
index 000000000..2e1248633
--- /dev/null
+++ b/src/Discord.Net/API/Rest/UploadFileParams.cs
@@ -0,0 +1,24 @@
+using System.Collections.Generic;
+
+namespace Discord.API.Rest
+{
+ public class UploadFileParams
+ {
+ public string Content { get; set; } = "";
+ public string Nonce { get; set; } = null;
+ public bool IsTTS { get; set; } = false;
+ public string Filename { get; set; } = "unknown.dat";
+
+ public IReadOnlyDictionary ToDictionary()
+ {
+ var dic = new Dictionary
+ {
+ ["content"] = Content,
+ ["tts"] = IsTTS.ToString()
+ };
+ if (Nonce != null)
+ dic.Add("nonce", Nonce);
+ return dic;
+ }
+ }
+}
diff --git a/src/Discord.Net/API/VoiceSocket/OpCode.cs b/src/Discord.Net/API/VoiceSocket/OpCode.cs
deleted file mode 100644
index d9174be22..000000000
--- a/src/Discord.Net/API/VoiceSocket/OpCode.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-namespace Discord.API.VoiceSocket
-{
- public enum OpCode : byte
- {
- /// C→S - Used to associate a connection with a token.
- Identify = 0,
- /// C→S - Used to specify protocol configuration.
- SelectProtocol = 1,
- /// C←S - Used to notify that the voice connection was successful and informs the client of available protocols.
- Ready = 2,
- /// C↔S - Used to keep the connection alive and measure latency.
- Heartbeat = 3,
- /// C←S - Used to provide an encryption key to the client.
- SessionDescription = 4,
- /// C↔S - Used to inform that a certain user is speaking.
- Speaking = 5
- }
-}
diff --git a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Commands/Heartbeat.cs b/src/Discord.Net/API/VoiceSocket/Unconfirmed/Commands/Heartbeat.cs
deleted file mode 100644
index f2f356854..000000000
--- a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Commands/Heartbeat.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-using System;
-
-namespace Discord.API.VoiceSocket
-{
- public class HeartbeatCommand : IWebSocketMessage
- {
- int IWebSocketMessage.OpCode => (int)OpCode.Heartbeat;
- object IWebSocketMessage.Payload => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
- }
-}
diff --git a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Commands/Identify.cs b/src/Discord.Net/API/VoiceSocket/Unconfirmed/Commands/Identify.cs
deleted file mode 100644
index 06a63e3c2..000000000
--- a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Commands/Identify.cs
+++ /dev/null
@@ -1,19 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.VoiceSocket
-{
- public class IdentifyCommand : IWebSocketMessage
- {
- int IWebSocketMessage.OpCode => (int)OpCode.Identify;
- object IWebSocketMessage.Payload => this;
-
- [JsonProperty("server_id")]
- public ulong GuildId { get; set; }
- [JsonProperty("user_id")]
- public ulong UserId { get; set; }
- [JsonProperty("session_id")]
- public string SessionId { get; set; }
- [JsonProperty("token")]
- public string Token { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Commands/SelectProtocol.cs b/src/Discord.Net/API/VoiceSocket/Unconfirmed/Commands/SelectProtocol.cs
deleted file mode 100644
index 4aa71b4f3..000000000
--- a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Commands/SelectProtocol.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.VoiceSocket
-{
- public class SelectProtocolCommand : IWebSocketMessage
- {
- int IWebSocketMessage.OpCode => (int)OpCode.SelectProtocol;
- object IWebSocketMessage.Payload => this;
-
- public class ProtocolData
- {
- [JsonProperty("address")]
- public string Address { get; set; }
- [JsonProperty("port")]
- public int Port { get; set; }
- [JsonProperty("mode")]
- public string Mode { get; set; }
- }
- [JsonProperty("protocol")]
- public string Protocol { get; set; } = "udp";
- [JsonProperty("data")]
- private ProtocolData Data { get; } = new ProtocolData();
-
- public string ExternalAddress { get { return Data.Address; } set { Data.Address = value; } }
- public int ExternalPort { get { return Data.Port; } set { Data.Port = value; } }
- public string EncryptionMode { get { return Data.Mode; } set { Data.Mode = value; } }
- }
-}
diff --git a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Commands/SetSpeaking.cs b/src/Discord.Net/API/VoiceSocket/Unconfirmed/Commands/SetSpeaking.cs
deleted file mode 100644
index 0476b9a7d..000000000
--- a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Commands/SetSpeaking.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.VoiceSocket
-{
- public class SetSpeakingCommand : IWebSocketMessage
- {
- int IWebSocketMessage.OpCode => (int)OpCode.Speaking;
- object IWebSocketMessage.Payload => this;
-
- [JsonProperty("speaking")]
- public bool IsSpeaking { get; set; }
- [JsonProperty("delay")]
- public int Delay { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Events/Ready.cs b/src/Discord.Net/API/VoiceSocket/Unconfirmed/Events/Ready.cs
deleted file mode 100644
index 7ba700d96..000000000
--- a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Events/Ready.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.VoiceSocket
-{
- public class ReadyEvent
- {
- [JsonProperty("ssrc")]
- public uint SSRC { get; set; }
- [JsonProperty("port")]
- public ushort Port { get; set; }
- [JsonProperty("modes")]
- public string[] Modes { get; set; }
- [JsonProperty("heartbeat_interval")]
- public int HeartbeatInterval { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Events/SessionDescription.cs b/src/Discord.Net/API/VoiceSocket/Unconfirmed/Events/SessionDescription.cs
deleted file mode 100644
index 09bda01c1..000000000
--- a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Events/SessionDescription.cs
+++ /dev/null
@@ -1,12 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.VoiceSocket
-{
- public class SessionDescriptionEvent
- {
- [JsonProperty("secret_key")]
- public byte[] SecretKey { get; set; }
- [JsonProperty("mode")]
- public string Mode { get; set; }
- }
-}
diff --git a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Events/Speaking.cs b/src/Discord.Net/API/VoiceSocket/Unconfirmed/Events/Speaking.cs
deleted file mode 100644
index 0e1271f98..000000000
--- a/src/Discord.Net/API/VoiceSocket/Unconfirmed/Events/Speaking.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using Newtonsoft.Json;
-
-namespace Discord.API.VoiceSocket
-{
- public class SpeakingEvent
- {
- [JsonProperty("user_id")]
- public ulong UserId { get; set; }
- [JsonProperty("ssrc")]
- public uint SSRC { get; set; }
- [JsonProperty("speaking")]
- public bool IsSpeaking { get; set; }
- }
-}
diff --git a/src/Discord.Net/Discord.Net.Net45.csproj b/src/Discord.Net/Discord.Net.Net45.csproj
deleted file mode 100644
index 6a34e8609..000000000
--- a/src/Discord.Net/Discord.Net.Net45.csproj
+++ /dev/null
@@ -1,303 +0,0 @@
-
-
-
-
-
- Debug
- AnyCPU
- {C6A50D24-CBD3-4E76-852C-4DCA60BBD608}
- Library
- Properties
- Discord
- Discord.Net
- v4.6.1
- 512
-
-
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- MinimumRecommendedRules.ruleset
-
-
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.
-
-
-
-
-
\ No newline at end of file
diff --git a/src/Discord.Net/Discord.Net.Net45.project.json b/src/Discord.Net/Discord.Net.Net45.project.json
deleted file mode 100644
index 0d36751ed..000000000
--- a/src/Discord.Net/Discord.Net.Net45.project.json
+++ /dev/null
@@ -1,12 +0,0 @@
-{
- "dependencies": {
- "Newtonsoft.Json": "8.0.3",
- "System.Collections.Immutable": "1.2.0-rc2-23608"
- },
- "frameworks": {
- "net461": {}
- },
- "runtimes": {
- "win": {}
- }
-}
\ No newline at end of file
diff --git a/src/Discord.Net/Discord.Net.Net45.project.lock.json b/src/Discord.Net/Discord.Net.Net45.project.lock.json
deleted file mode 100644
index aad5884f0..000000000
--- a/src/Discord.Net/Discord.Net.Net45.project.lock.json
+++ /dev/null
@@ -1,88 +0,0 @@
-{
- "locked": false,
- "version": 2,
- "targets": {
- ".NETFramework,Version=v4.6.1": {
- "Newtonsoft.Json/8.0.3": {
- "type": "package",
- "compile": {
- "lib/net45/Newtonsoft.Json.dll": {}
- },
- "runtime": {
- "lib/net45/Newtonsoft.Json.dll": {}
- }
- },
- "System.Collections.Immutable/1.2.0-rc2-23608": {
- "type": "package",
- "compile": {
- "lib/dotnet5.1/System.Collections.Immutable.dll": {}
- },
- "runtime": {
- "lib/dotnet5.1/System.Collections.Immutable.dll": {}
- }
- }
- },
- ".NETFramework,Version=v4.6.1/win": {
- "Newtonsoft.Json/8.0.3": {
- "type": "package",
- "compile": {
- "lib/net45/Newtonsoft.Json.dll": {}
- },
- "runtime": {
- "lib/net45/Newtonsoft.Json.dll": {}
- }
- },
- "System.Collections.Immutable/1.2.0-rc2-23608": {
- "type": "package",
- "compile": {
- "lib/dotnet5.1/System.Collections.Immutable.dll": {}
- },
- "runtime": {
- "lib/dotnet5.1/System.Collections.Immutable.dll": {}
- }
- }
- }
- },
- "libraries": {
- "Newtonsoft.Json/8.0.3": {
- "sha512": "KGsYQdS2zLH+H8x2cZaSI7e+YZ4SFIbyy1YJQYl6GYBWjf5o4H1A68nxyq+WTyVSOJQ4GqS/DiPE+UseUizgMg==",
- "type": "package",
- "files": [
- "Newtonsoft.Json.8.0.3.nupkg.sha512",
- "Newtonsoft.Json.nuspec",
- "lib/net20/Newtonsoft.Json.dll",
- "lib/net20/Newtonsoft.Json.xml",
- "lib/net35/Newtonsoft.Json.dll",
- "lib/net35/Newtonsoft.Json.xml",
- "lib/net40/Newtonsoft.Json.dll",
- "lib/net40/Newtonsoft.Json.xml",
- "lib/net45/Newtonsoft.Json.dll",
- "lib/net45/Newtonsoft.Json.xml",
- "lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.dll",
- "lib/portable-net40+sl5+wp80+win8+wpa81/Newtonsoft.Json.xml",
- "lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.dll",
- "lib/portable-net45+wp80+win8+wpa81+dnxcore50/Newtonsoft.Json.xml",
- "tools/install.ps1"
- ]
- },
- "System.Collections.Immutable/1.2.0-rc2-23608": {
- "sha512": "LIodNcjmeDMzZ0P0nadxBAiZcxwTNXmiHMJoyj1xO2vvahd617xLnO8tJrWNCKgPcwDimuAC9twqsQRFiDOuDQ==",
- "type": "package",
- "files": [
- "System.Collections.Immutable.1.2.0-rc2-23608.nupkg.sha512",
- "System.Collections.Immutable.nuspec",
- "lib/dotnet5.1/System.Collections.Immutable.dll",
- "lib/dotnet5.1/System.Collections.Immutable.xml",
- "lib/portable-net45+win8+wp8+wpa81/System.Collections.Immutable.dll",
- "lib/portable-net45+win8+wp8+wpa81/System.Collections.Immutable.xml"
- ]
- }
- },
- "projectFileDependencyGroups": {
- "": [
- "Newtonsoft.Json >= 8.0.3",
- "System.Collections.Immutable >= 1.2.0-rc2-23608"
- ],
- ".NETFramework,Version=v4.6.1": []
- }
-}
\ No newline at end of file
diff --git a/src/Discord.Net/Discord.Net.csproj b/src/Discord.Net/Discord.Net.csproj
new file mode 100644
index 000000000..d8f98c647
--- /dev/null
+++ b/src/Discord.Net/Discord.Net.csproj
@@ -0,0 +1,209 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {18F6FE23-73F6-4CA6-BBD9-F0139DC3EE90}
+ Library
+ Properties
+ Discord
+ Discord.Net
+ v4.6.1
+ 512
+
+
+
+ true
+ full
+ false
+ bin\Debug\
+ TRACE;DEBUG;__DEMO__,__DEMO_EXPERIMENTAL__
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Discord.Net/Discord.Net.xproj b/src/Discord.Net/Discord.Net.xproj
deleted file mode 100644
index e5ec681b5..000000000
--- a/src/Discord.Net/Discord.Net.xproj
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
- 14.0.25123
- $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)
-
-
-
- 2c91bdd7-621d-460f-b768-ead106d9ba62
- Discord
- ..\..\..\TestBot\artifacts\obj\$(MSBuildProjectName)
- ..\..\..\TestBot\artifacts\bin\$(MSBuildProjectName)\
-
-
- 2.0
-
-
- True
-
-
-
\ No newline at end of file
diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs
deleted file mode 100644
index 2409a76d2..000000000
--- a/src/Discord.Net/DiscordClient.cs
+++ /dev/null
@@ -1,341 +0,0 @@
-using Discord.API.Rest;
-using Discord.Logging;
-using Discord.Net;
-using Discord.Net.Rest;
-using System;
-using System.Collections.Generic;
-using System.Collections.Immutable;
-using System.IO;
-using System.Linq;
-using System.Net;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-
-namespace Discord
-{
- public class DiscordClient : IDisposable
- {
- public event EventHandler Log;
- public event EventHandler LoggedIn, LoggedOut;
-
- protected readonly RestClientProvider _restClientProvider;
- protected readonly string _token;
- protected readonly LogManager _logManager;
- protected readonly SemaphoreSlim _connectionLock;
- protected readonly Logger _restLogger;
- protected CancellationTokenSource _cancelToken;
- protected bool _isDisposed;
-
- public string UserAgent { get; }
- public IReadOnlyList VoiceRegions { get; private set; }
- /// Gets the internal RestClient.
- public RestClient RestClient { get; protected set; }
- /// Gets the queue used for outgoing messages, if enabled.
- public MessageQueue MessageQueue { get; protected set; }
- public SelfUser CurrentUser { get; protected set; }
- public bool IsLoggedIn { get; private set; }
-
- internal CancellationToken CancelToken => _cancelToken.Token;
-
- public DiscordClient(string token, DiscordConfig config = null)
- {
- if (token == null) throw new ArgumentNullException(nameof(token));
-
- if (config == null)
- config = new DiscordConfig();
-
- _token = token;
- _connectionLock = new SemaphoreSlim(1, 1);
-
- _restClientProvider = config.RestClientProvider;
- UserAgent = $"DiscordBot ({DiscordConfig.LibUrl}, v{DiscordConfig.LibVersion})";
-
- _logManager = new LogManager(config.LogLevel);
- _logManager.Message += (s, e) => Log(this, e);
- _restLogger = _logManager.CreateLogger("Rest");
- }
-
- public async Task Login()
- {
- await _connectionLock.WaitAsync().ConfigureAwait(false);
- try
- {
- await LoginInternal().ConfigureAwait(false);
- }
- finally { _connectionLock.Release(); }
- }
- protected virtual async Task LoginInternal()
- {
- if (IsLoggedIn)
- await LogoutInternal().ConfigureAwait(false);
-
- try
- {
- _cancelToken = new CancellationTokenSource();
-
- RestClient = new RestClient(_restClientProvider(DiscordConfig.ClientAPIUrl, _cancelToken.Token));
- RestClient.SetHeader("accept", "*/*");
- RestClient.SetHeader("authorization", _token);
- RestClient.SetHeader("user-agent", UserAgent);
- RestClient.SentRequest += (s, e) => _restLogger.Verbose($"{e.Request.Method} {e.Request.Endpoint}: {e.Milliseconds} ms");
-
- MessageQueue = new MessageQueue(RestClient, _restLogger);
- await MessageQueue.Start(_cancelToken.Token).ConfigureAwait(false);
-
- var selfResponse = await RestClient.Send(new GetCurrentUserRequest()).ConfigureAwait(false);
- var regionsResponse = await RestClient.Send(new GetVoiceRegionsRequest()).ConfigureAwait(false);
-
- CurrentUser = CreateSelfUser(selfResponse);
- VoiceRegions = regionsResponse.Select(x => CreateVoiceRegion(x)).ToImmutableArray();
-
- IsLoggedIn = true;
- RaiseEvent(LoggedIn);
- }
- catch (Exception) { await LogoutInternal().ConfigureAwait(false); throw; }
- }
-
- public async Task Logout()
- {
- _cancelToken?.Cancel();
- await _connectionLock.WaitAsync().ConfigureAwait(false);
- try
- {
- await LogoutInternal().ConfigureAwait(false);
- }
- finally { _connectionLock.Release(); }
- }
- protected virtual async Task LogoutInternal()
- {
- bool wasLoggedIn = IsLoggedIn;
-
- try { _cancelToken.Cancel(); } catch { }
- try { await MessageQueue.Stop().ConfigureAwait(false); } catch { }
-
- RestClient = null;
- MessageQueue = null;
-
- if (wasLoggedIn)
- {
- IsLoggedIn = false;
- RaiseEvent(LoggedOut);
- }
- }
-
- public virtual async Task> GetDMChannels()
- {
- var response = await RestClient.Send(new GetCurrentUserDMsRequest()).ConfigureAwait(false);
- var result = ImmutableArray.CreateBuilder(response.Length);
- for (int i = 0; i < response.Length; i++)
- result[i] = CreateDMChannel(response[i]);
- return result.ToImmutable();
- }
- public virtual async Task GetInvite(string inviteIdOrXkcd)
- {
- if (inviteIdOrXkcd == null) throw new ArgumentNullException(nameof(inviteIdOrXkcd));
-
- //Remove trailing slash
- if (inviteIdOrXkcd.Length > 0 && inviteIdOrXkcd[inviteIdOrXkcd.Length - 1] == '/')
- inviteIdOrXkcd = inviteIdOrXkcd.Substring(0, inviteIdOrXkcd.Length - 1);
- //Remove leading URL
- int index = inviteIdOrXkcd.LastIndexOf('/');
- if (index >= 0)
- inviteIdOrXkcd = inviteIdOrXkcd.Substring(index + 1);
-
- try
- {
- var response = await RestClient.Send(new GetInviteRequest(inviteIdOrXkcd)).ConfigureAwait(false);
- return CreatePublicInvite(response);
- }
- catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound)
- {
- return null;
- }
- }
- public virtual async Task GetGuild(ulong id)
- {
- var response = await RestClient.Send(new GetGuildRequest(id)).ConfigureAwait(false);
- return CreateGuild(response);
- }
- public virtual async Task> GetGuilds()
- {
- var response = await RestClient.Send(new GetCurrentUserGuildsRequest()).ConfigureAwait(false);
- var result = ImmutableArray.CreateBuilder(response.Length);
- for (int i = 0; i < response.Length; i++)
- result[i] = CreateGuild(response[i]);
- return result.ToImmutable();
- }
- public virtual async Task GetUser(ulong id)
- {
- var response = await RestClient.Send(new GetUserRequest(id));
- var user = CreateGlobalUser(response);
- return user;
- }
- public virtual async Task GetUser(string username, ushort discriminator)
- {
- var response = await RestClient.Send(new QueryUserRequest() { Query = $"{username}#{discriminator}", Limit = 1 });
- if (response.Length > 0)
- {
- var user = CreateGlobalUser(response[0]);
- return user;
- }
- return null;
- }
- public virtual VoiceRegion GetOptimalVoiceRegion()
- {
- var regions = VoiceRegions;
- for (int i = 0; i < regions.Count; i++)
- {
- if (regions[i].IsOptimal)
- return regions[i];
- }
- return null;
- }
- public virtual VoiceRegion GetVoiceRegion(string id)
- {
- if (id == null) throw new ArgumentNullException(nameof(id));
-
- var regions = VoiceRegions;
- for (int i = 0; i < regions.Count; i++)
- {
- if (regions[i].Id == id)
- return regions[i];
- }
- return null;
- }
-
- public virtual async Task GetOrCreateDMChannel(ulong userId)
- {
- var response = await RestClient.Send(new CreateDMChannelRequest
- {
- RecipientId = userId
- }).ConfigureAwait(false);
-
- return CreateDMChannel(response);
- }
- /// Creates a new guild with the provided name and region. This function requires your bot to be whitelisted by Discord.
- public virtual async Task CreateGuild(string name, VoiceRegion region, Stream jpegIcon = null)
- {
- if (name == null) throw new ArgumentNullException(nameof(name));
- if (region == null) throw new ArgumentNullException(nameof(region));
-
- var response = await RestClient.Send(new CreateGuildRequest
- {
- Name = name,
- Region = region.Id,
- Icon = jpegIcon
- }).ConfigureAwait(false);
-
- return CreateGuild(response);
- }
-
- internal virtual DMChannel CreateDMChannel(API.Channel model)
- {
- var channel = new DMChannel(model.Id, this, 0);
- channel.Update(model);
- return channel;
- }
- internal virtual TextChannel CreateTextChannel(Guild guild, API.Channel model)
- {
- var channel = new TextChannel(model.Id, guild, 0, false);
- channel.Update(model);
- return channel;
- }
- internal virtual VoiceChannel CreateVoiceChannel(Guild guild, API.Channel model)
- {
- var channel = new VoiceChannel(model.Id, guild, false);
- channel.Update(model);
- return channel;
- }
- internal virtual GuildInvite CreateGuildInvite(GuildChannel channel, API.InviteMetadata model)
- {
- var invite = new GuildInvite(model.Code, channel);
- invite.Update(model);
- return invite;
- }
- internal virtual PublicInvite CreatePublicInvite(API.Invite model)
- {
- var invite = new PublicInvite(model.Code, this);
- invite.Update(model);
- return invite;
- }
- internal virtual Guild CreateGuild(API.Guild model)
- {
- var guild = new Guild(model.Id, this);
- guild.Update(model);
- return guild;
- }
- internal virtual Message CreateMessage(IMessageChannel channel, IUser user, API.Message model)
- {
- var msg = new Message(model.Id, channel, user);
- msg.Update(model);
- return msg;
- }
- internal virtual Role CreateRole(Guild guild, API.Role model)
- {
- var role = new Role(model.Id, guild);
- role.Update(model);
- return role;
- }
- internal virtual DMUser CreateDMUser(DMChannel channel, API.User model)
- {
- var user = new DMUser(CreateGlobalUser(model), channel);
- user.Update(model);
- return user;
- }
- internal virtual GuildUser CreateGuildUser(Guild guild, API.GuildMember model)
- {
- var user = new GuildUser(CreateGlobalUser(model.User), guild);
- user.Update(model);
- return user;
- }
- internal virtual GuildUser CreateBannedUser(Guild guild, API.User model)
- {
- var user = new GuildUser(CreateGlobalUser(model), guild);
- //user.Update(model);
- return user;
- }
- internal virtual SelfUser CreateSelfUser(API.User model)
- {
- var user = new SelfUser(model.Id, this);
- user.Update(model);
- return user;
- }
- internal virtual GlobalUser CreateGlobalUser(API.User model)
- {
- var user = new GlobalUser(model.Id, this);
- user.Update(model);
- return user;
- }
- internal virtual VoiceRegion CreateVoiceRegion(API.Rest.GetVoiceRegionsResponse model)
- {
- var region = new VoiceRegion(model.Id, this);
- region.Update(model);
- return region;
- }
-
- internal virtual void RemoveUser(GlobalUser user) { }
-
- protected virtual void Dispose(bool disposing)
- {
- if (!_isDisposed)
- {
- if (disposing)
- {
- MessageQueue.Dispose();
- RestClient.Dispose();
- _connectionLock.Dispose();
- }
- _isDisposed = true;
- }
- }
- public void Dispose() => Dispose(true);
-
- protected void RaiseEvent(EventHandler eventHandler)
- => eventHandler?.Invoke(this, EventArgs.Empty);
- protected void RaiseEvent(EventHandler eventHandler, T eventArgs) where T : EventArgs
- => eventHandler?.Invoke(this, eventArgs);
- protected void RaiseEvent(EventHandler eventHandler, Func eventArgs) where T : EventArgs
- => eventHandler?.Invoke(this, eventArgs());
- }
-}
diff --git a/src/Discord.Net/DiscordConfig.cs b/src/Discord.Net/DiscordConfig.cs
index 8598b9f27..e79919d60 100644
--- a/src/Discord.Net/DiscordConfig.cs
+++ b/src/Discord.Net/DiscordConfig.cs
@@ -1,62 +1,27 @@
-using Discord.Net.Rest;
-using Discord.Net.WebSockets;
-using System.Reflection;
+using System.Reflection;
namespace Discord
-{
+{
public class DiscordConfig
{
- public const int MaxMessageSize = 2000;
- public const int MaxMessagesPerBatch = 100;
+ public static string Version { get; } = typeof(DiscordConfig).GetTypeInfo().Assembly?.GetName().Version.ToString(3) ?? "Unknown";
+ public static string UserAgent { get; } = $"DiscordBot (https://github.com/RogueException/Discord.Net, v{Version})";
- public const string LibName = "Discord.Net";
- public static string LibVersion { get; } = typeof(DiscordConfig).GetTypeInfo().Assembly?.GetName().Version.ToString(3) ?? "Unknown";
- public const string LibUrl = "https://github.com/RogueException/Discord.Net";
+ public const int GatewayAPIVersion = 3;
public const string ClientAPIUrl = "https://discordapp.com/api/";
public const string CDNUrl = "https://cdn.discordapp.com/";
public const string InviteUrl = "https://discord.gg/";
+ public const int MaxMessageSize = 2000;
+ public const int MaxMessagesPerBatch = 100;
+ public const int MaxUsersPerBatch = 1000;
+
internal const int RestTimeout = 10000;
internal const int MessageQueueInterval = 100;
internal const int WebSocketQueueInterval = 100;
/// Gets or sets the minimum log level severity that will be sent to the LogMessage event.
public LogSeverity LogLevel { get; set; } = LogSeverity.Info;
-
- /// Gets or sets the time (in milliseconds) to wait for the websocket to connect and initialize.
- public int ConnectionTimeout { get; set; } = 30000;
- /// Gets or sets the time (in milliseconds) to wait after an unexpected disconnect before reconnecting.
- public int ReconnectDelay { get; set; } = 1000;
- /// Gets or sets the time (in milliseconds) to wait after an reconnect fails before retrying.
- public int FailedReconnectDelay { get; set; } = 15000;
-
- //Performance
-
- /// Gets or sets the number of messages per channel that should be kept in cache. Setting this to zero disables the message cache entirely.
- public int MessageCacheSize { get; set; } = 100;
- ///
- /// Gets or sets whether the permissions cache should be used.
- /// This makes operations such as User.GetPermissions(Channel), User.GuildPermissions, Channel.GetUser, and Channel.Members much faster while increasing memory usage.
- ///
- public bool UsePermissionsCache { get; set; } = true;
- /// Gets or sets whether the a copy of a model is generated on an update event to allow you to check which properties changed.
- public bool EnablePreUpdateEvents { get; set; } = true;
- ///
- /// Gets or sets the max number of users a guild may have for offline users to be included in the READY packet. Max is 250.
- /// Decreasing this may reduce CPU usage while increasing login time and network usage.
- ///
- public int LargeThreshold { get; set; } = 250;
-
- //Engines
-
- /// Gets or sets the REST engine to use. Defaults to DefaultRestClientProvider, which is built around .Net's HttpClient class.
- public RestClientProvider RestClientProvider { get; set; } = (url, ct) => new DefaultRestEngine(url, ct);
- ///
- /// Gets or sets the WebSocket engine to use. Defaults to DefaultWebSocketProvider, which uses .Net's WebSocketClient class.
- /// WebSockets are only used if DiscordClient.Connect() is called.
- ///
- public WebSocketProvider WebSocketProvider { get; set; } = null;
}
}
-
diff --git a/src/Discord.Net/DiscordRestClient.cs b/src/Discord.Net/DiscordRestClient.cs
new file mode 100644
index 000000000..091e0cb00
--- /dev/null
+++ b/src/Discord.Net/DiscordRestClient.cs
@@ -0,0 +1,256 @@
+using Discord.API.Rest;
+using Discord.Logging;
+using Discord.Net.Rest;
+using Discord.Rest;
+using Newtonsoft.Json.Linq;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Discord
+{
+ public sealed class DiscordRestClient : IDiscordClient, IDisposable
+ {
+ public event EventHandler Log;
+ public event EventHandler LoggedIn, LoggedOut;
+
+ private readonly SemaphoreSlim _connectionLock;
+ private readonly RestClientProvider _restClientProvider;
+ private readonly LogManager _log;
+ private CancellationTokenSource _cancelTokenSource;
+ private bool _isDisposed;
+ private string _userAgent;
+
+ public bool IsLoggedIn { get; private set; }
+ internal API.DiscordRawClient BaseClient { get; private set; }
+ internal SelfUser CurrentUser { get; private set; }
+
+ public DiscordRestClient(DiscordConfig config = null)
+ {
+ if (config == null)
+ config = new DiscordConfig();
+
+ _restClientProvider = (baseUrl, cancelToken) => new DefaultRestClient(baseUrl, cancelToken);
+
+ _connectionLock = new SemaphoreSlim(1, 1);
+ _log = new LogManager(config.LogLevel);
+ _userAgent = DiscordConfig.UserAgent;
+
+ _log.Message += (s,e) => Log.Raise(this, e);
+ }
+
+ public async Task Login(TokenType tokenType, string token)
+ {
+ await _connectionLock.WaitAsync().ConfigureAwait(false);
+ try
+ {
+ await LoginInternal(tokenType, token).ConfigureAwait(false);
+ }
+ finally { _connectionLock.Release(); }
+ }
+ private async Task LoginInternal(TokenType tokenType, string token)
+ {
+ if (IsLoggedIn)
+ LogoutInternal();
+
+ try
+ {
+ var cancelTokenSource = new CancellationTokenSource();
+
+ BaseClient = new API.DiscordRawClient(_restClientProvider, cancelTokenSource.Token, tokenType, token);
+ BaseClient.SentRequest += (s, e) => _log.Verbose($"{e.Method} {e.Endpoint}: {e.Milliseconds} ms");
+
+ //MessageQueue = new MessageQueue(RestClient, _restLogger);
+ //await MessageQueue.Start(_cancelTokenSource.Token).ConfigureAwait(false);
+
+ var currentUser = await BaseClient.GetCurrentUser().ConfigureAwait(false);
+ CurrentUser = new SelfUser(this, currentUser);
+
+ _cancelTokenSource = cancelTokenSource;
+ IsLoggedIn = true;
+ LoggedIn.Raise(this);
+ }
+ catch { LogoutInternal(); throw; }
+ }
+
+ public async Task Logout()
+ {
+ _cancelTokenSource?.Cancel();
+ await _connectionLock.WaitAsync().ConfigureAwait(false);
+ try
+ {
+ LogoutInternal();
+ }
+ finally { _connectionLock.Release(); }
+ }
+ private void LogoutInternal()
+ {
+ bool wasLoggedIn = IsLoggedIn;
+
+ try { _cancelTokenSource.Cancel(false); } catch { }
+
+ BaseClient = null;
+
+ if (wasLoggedIn)
+ {
+ IsLoggedIn = false;
+ LoggedOut.Raise(this);
+ }
+ }
+
+ public async Task> GetConnections()
+ {
+ var models = await BaseClient.GetCurrentUserConnections().ConfigureAwait(false);
+ return models.Select(x => new Connection(x));
+ }
+
+ public async Task GetChannel(ulong id)
+ {
+ var model = await BaseClient.GetChannel(id).ConfigureAwait(false);
+ if (model != null)
+ {
+ if (model.GuildId != null)
+ {
+ var guildModel = await BaseClient.GetGuild(model.GuildId.Value).ConfigureAwait(false);
+ if (guildModel != null)
+ {
+ var guild = new Guild(this, guildModel);
+ return guild.ToChannel(model);
+ }
+ }
+ else
+ return new DMChannel(this, model);
+ }
+ return null;
+ }
+ public async Task> GetDMChannels()
+ {
+ var models = await BaseClient.GetCurrentUserDMs().ConfigureAwait(false);
+ return models.Select(x => new DMChannel(this, x));
+ }
+
+ public async Task GetInvite(string inviteIdOrXkcd)
+ {
+ var model = await BaseClient.GetInvite(inviteIdOrXkcd).ConfigureAwait(false);
+ if (model != null)
+ return new PublicInvite(this, model);
+ return null;
+ }
+
+ public async Task GetGuild(ulong id)
+ {
+ var model = await BaseClient.GetGuild(id).ConfigureAwait(false);
+ if (model != null)
+ return new Guild(this, model);
+ return null;
+ }
+ public async Task GetGuildEmbed(ulong id)
+ {
+ var model = await BaseClient.GetGuildEmbed(id).ConfigureAwait(false);
+ if (model != null)
+ return new GuildEmbed(this, model);
+ return null;
+ }
+ public async Task> GetGuilds()
+ {
+ var models = await BaseClient.GetCurrentUserGuilds().ConfigureAwait(false);
+ return models.Select(x => new UserGuild(this, x));
+
+ }
+ public async Task CreateGuild(string name, IVoiceRegion region, Stream jpegIcon = null)
+ {
+ var args = new CreateGuildParams();
+ var model = await BaseClient.CreateGuild(args).ConfigureAwait(false);
+ return new Guild(this, model);
+ }
+
+ public async Task GetUser(ulong id)
+ {
+ var model = await BaseClient.GetUser(id).ConfigureAwait(false);
+ if (model != null)
+ return new PublicUser(this, model);
+ return null;
+ }
+ public async Task GetUser(string username, ushort discriminator)
+ {
+ var model = await BaseClient.GetUser(username, discriminator).ConfigureAwait(false);
+ if (model != null)
+ return new PublicUser(this, model);
+ return null;
+ }
+ public async Task GetCurrentUser()
+ {
+ var currentUser = CurrentUser;
+ if (currentUser == null)
+ {
+ var model = await BaseClient.GetCurrentUser().ConfigureAwait(false);
+ currentUser = new SelfUser(this, model);
+ CurrentUser = currentUser;
+ }
+ return currentUser;
+ }
+ public async Task> QueryUsers(string query, int limit)
+ {
+ var models = await BaseClient.QueryUsers(query, limit).ConfigureAwait(false);
+ return models.Select(x => new PublicUser(this, x));
+ }
+
+ public async Task> GetVoiceRegions()
+ {
+ var models = await BaseClient.GetVoiceRegions().ConfigureAwait(false);
+ return models.Select(x => new VoiceRegion(x));
+ }
+ public async Task GetVoiceRegion(string id)
+ {
+ var models = await BaseClient.GetVoiceRegions().ConfigureAwait(false);
+ return models.Select(x => new VoiceRegion(x)).Where(x => x.Id == id).FirstOrDefault();
+ }
+ public async Task GetOptimalVoiceRegion()
+ {
+ var models = await BaseClient.GetVoiceRegions().ConfigureAwait(false);
+ return models.Select(x => new VoiceRegion(x)).Where(x => x.IsOptimal).FirstOrDefault();
+ }
+
+ void Dispose(bool disposing)
+ {
+ if (!_isDisposed)
+ {
+ if (disposing)
+ _cancelTokenSource.Dispose();
+ _isDisposed = true;
+ }
+ }
+ public void Dispose() => Dispose(true);
+
+ API.DiscordRawClient IDiscordClient.BaseClient => BaseClient;
+ ISelfUser IDiscordClient.CurrentUser => CurrentUser;
+
+ async Task IDiscordClient.GetChannel(ulong id)
+ => await GetChannel(id).ConfigureAwait(false);
+ async Task> IDiscordClient.GetDMChannels()
+ => await GetDMChannels().ConfigureAwait(false);
+ async Task> IDiscordClient.GetConnections()
+ => await GetConnections().ConfigureAwait(false);
+ async Task IDiscordClient.GetInvite(string inviteIdOrXkcd)
+ => await GetInvite(inviteIdOrXkcd).ConfigureAwait(false);
+ async Task IDiscordClient.GetGuild(ulong id)
+ => await GetGuild(id).ConfigureAwait(false);
+ async Task> IDiscordClient.GetGuilds()
+ => await GetGuilds().ConfigureAwait(false);
+ async Task IDiscordClient.CreateGuild(string name, IVoiceRegion region, Stream jpegIcon)
+ => await CreateGuild(name, region, jpegIcon).ConfigureAwait(false);
+ async Task IDiscordClient.GetUser(ulong id)
+ => await GetUser(id).ConfigureAwait(false);
+ async Task> IDiscordClient.QueryUsers(string query, int limit)
+ => await QueryUsers(query, limit).ConfigureAwait(false);
+ async Task> IDiscordClient.GetVoiceRegions()
+ => await GetVoiceRegions().ConfigureAwait(false);
+ async Task IDiscordClient.GetVoiceRegion(string id)
+ => await GetVoiceRegion(id).ConfigureAwait(false);
+ async Task IDiscordClient.GetOptimalVoiceRegion()
+ => await GetOptimalVoiceRegion().ConfigureAwait(false);
+ }
+}
diff --git a/src/Discord.Net/DiscordSocketClient.cs b/src/Discord.Net/DiscordSocketClient.cs
deleted file mode 100644
index 40beb389e..000000000
--- a/src/Discord.Net/DiscordSocketClient.cs
+++ /dev/null
@@ -1,176 +0,0 @@
-using Discord.Logging;
-using Discord.Net.WebSockets;
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Linq;
-using System.Threading.Tasks;
-
-namespace Discord
-{
- public class DiscordSocketClient : DiscordClient
- {
- public event EventHandler Connected, Disconnected;
- public event EventHandler VoiceConnected, VoiceDisconnected;
-
- public event EventHandler ChannelCreated, ChannelDestroyed;
- public event EventHandler ChannelUpdated;
- public event EventHandler MessageReceived, MessageDeleted;
- public event EventHandler MessageUpdated;
- public event EventHandler RoleCreated, RoleDeleted;
- public event EventHandler RoleUpdated;
- public event EventHandler JoinedGuild, LeftGuild;
- public event EventHandler GuildAvailable, GuildUnavailable;
- public event EventHandler GuildUpdated;
- public event EventHandler CurrentUserUpdated;
- public event EventHandler UserJoined, UserLeft;
- public event EventHandler UserBanned, UserUnbanned;
- public event EventHandler UserUpdated;
- public event EventHandler UserIsTyping;
-
- private readonly Logger _discordLogger, _gatewayLogger;
- private readonly int _connectionTimeout, _reconnectDelay, _failedReconnectDelay;
- private readonly bool _enablePreUpdateEvents, _usePermissionCache;
- private readonly int _largeThreshold, _messageCacheSize;
- private ConcurrentDictionary _guilds;
- private ConcurrentDictionary _channels;
- private ConcurrentDictionary _privateChannels; //Key = RecipientId
-
- public int ConnectionId { get; }
- public int TotalConnections { get; }
- /// Gets the internal WebSocket for the Gateway event stream.
- public GatewaySocket GatewaySocket { get; private set; }
- /*/// Gets the current logged-in account.
- public CurrentUser CurrentUser { get; private set; }*/
-
- public bool IsConnected => GatewaySocket.State == ConnectionState.Connected;
-
- public DiscordSocketClient(string token, int connectionId = 0, int totalConnections = 1, DiscordConfig config = null)
- : base(token, config)
- {
- if (totalConnections < 1) throw new ArgumentOutOfRangeException(nameof(totalConnections));
- if (connectionId < 0) throw new ArgumentOutOfRangeException(nameof(connectionId));
- if (connectionId >= totalConnections) throw new ArgumentException($"{nameof(connectionId)} must be less than {nameof(totalConnections)}.", nameof(connectionId));
-
- ConnectionId = connectionId;
- TotalConnections = totalConnections;
-
- _connectionTimeout = config.ConnectionTimeout;
- _reconnectDelay = config.ReconnectDelay;
- _failedReconnectDelay = config.FailedReconnectDelay;
-
- _messageCacheSize = config.MessageCacheSize;
- _usePermissionCache = config.UsePermissionsCache;
- _enablePreUpdateEvents = config.EnablePreUpdateEvents;
- _largeThreshold = config.LargeThreshold;
-
- _discordLogger = _logManager.CreateLogger("Discord");
- _gatewayLogger = _logManager.CreateLogger("Gateway");
-
- _guilds = new ConcurrentDictionary(2, 0);
- _channels = new ConcurrentDictionary(2, 0);
- _privateChannels = new ConcurrentDictionary(2, 0);
- }
-
- protected override async Task LogoutInternal()
- {
- await DisconnectInternal().ConfigureAwait(false);
-
- _guilds.Clear();
- _channels.Clear();
- _privateChannels.Clear();
-
- CurrentUser = null;
-
- await base.LogoutInternal();
- }
-
- public async Task Connect()
- {
- await _connectionLock.WaitAsync().ConfigureAwait(false);
- try
- {
- await ConnectInternal().ConfigureAwait(false);
- }
- finally { _connectionLock.Release(); }
- }
- protected virtual Task ConnectInternal()
- {
- throw new NotImplementedException();
- //GatewaySocket = new GatewaySocket(_webSocketProvider(_cancelToken.Token));
- //GatewaySocket.SetHeader("user-agent", _userAgent);
- //await GatewaySocket.Connect(_cancelToken.Token).ConfigureAwait(false);
- }
-
- public async Task Disconnect()
- {
- await _connectionLock.WaitAsync().ConfigureAwait(false);
- try
- {
- await DisconnectInternal().ConfigureAwait(false);
- }
- finally { _connectionLock.Release(); }
- }
- protected virtual async Task DisconnectInternal()
- {
- if (GatewaySocket != null)
- {
- await GatewaySocket.Disconnect().ConfigureAwait(false);
- GatewaySocket = null;
- }
- }
-
- public override async Task GetOrCreateDMChannel(ulong userId)
- {
- DMChannel channel;
- if (_privateChannels.TryGetValue(userId, out channel))
- return channel;
-
- return await base.GetOrCreateDMChannel(userId).ConfigureAwait(false);
- }
- public override Task> GetDMChannels()
- {
- return Task.FromResult(_privateChannels.Select(x => x.Value));
- }
- public override Task> GetGuilds()
- {
- return Task.FromResult(_guilds.Select(x => x.Value));
- }
- public override Task GetGuild(ulong id)
- {
- Guild guild;
- _guilds.TryGetValue(id, out guild);
- return Task.FromResult(guild);
- }
-
- internal override DMChannel CreateDMChannel(API.Channel model)
- {
- var channel = new DMChannel(model.Id, this, _messageCacheSize);
- channel.Update(model);
- return channel;
- }
- internal override TextChannel CreateTextChannel(Guild guild, API.Channel model)
- {
- var channel = new TextChannel(model.Id, guild, _messageCacheSize, _usePermissionCache);
- channel.Update(model);
- return channel;
- }
- internal override VoiceChannel CreateVoiceChannel(Guild guild, API.Channel model)
- {
- var channel = new VoiceChannel(model.Id, guild, _usePermissionCache);
- channel.Update(model);
- return channel;
- }
-
- protected override void Dispose(bool disposing)
- {
- if (!_isDisposed)
- {
- if (disposing)
- {
- GatewaySocket.Dispose();
- }
- }
- }
- }
-}
diff --git a/src/Discord.Net/Entities/Channels/DMChannel.cs b/src/Discord.Net/Entities/Channels/DMChannel.cs
deleted file mode 100644
index c176b9dc0..000000000
--- a/src/Discord.Net/Entities/Channels/DMChannel.cs
+++ /dev/null
@@ -1,97 +0,0 @@
-using Discord.API.Rest;
-using Discord.Net;
-using System.Collections.Generic;
-using System.Collections.Immutable;
-using System.IO;
-using System.Net;
-using System.Threading.Tasks;
-using Model = Discord.API.Channel;
-
-namespace Discord
-{
- public class DMChannel : IEntity, IMessageChannel
- {
- ///
- public ulong Id { get; }
- ///
- public DiscordClient Discord { get; }
-
- ///
- public DMUser Recipient { get; private set; }
-
- ///
- public string Name => $"@{Recipient.Username}#{Recipient.Discriminator}";
- ///
- public IEnumerable Users => ImmutableArray.Create(Discord.CurrentUser, Recipient);
- ///
- ChannelType IChannel.Type => ChannelType.DM;
-
- private readonly MessageManager _messages;
-
- internal DMChannel(ulong id, DiscordClient client, int messageCacheSize)
- {
- Id = id;
- Discord = client;
- _messages = new MessageManager(this, messageCacheSize);
- }
- internal void Update(Model model)
- {
- if (Recipient == null)
- Recipient = Discord.CreateDMUser(this, model.Recipient);
- else
- Recipient.Update(model.Recipient);
- }
-
- ///
- public IUser GetUser(ulong id)
- {
- if (id == Recipient.Id)
- return Recipient;
- else if (id == Discord.CurrentUser.Id)
- return Discord.CurrentUser;
- else
- return null;
- }
-
- ///
- public Task GetMessage(ulong id)
- => _messages.Get(id);
- ///
- public Task> GetMessages(int limit = 100)
- => _messages.GetMany(limit);
- ///
- public Task> GetMessages(int limit = 100, ulong? relativeMessageId = null, Relative relativeDir = Relative.Before)
- => _messages.GetMany(limit, relativeMessageId, relativeDir);
-
- ///
- public Task SendMessage(string text, bool isTTS = false)
- => _messages.Send(text, isTTS);
- ///
- public Task SendFile(string filePath, string text = null, bool isTTS = false)
- => _messages.SendFile(filePath, text, isTTS);
- ///
- public Task SendFile(Stream stream, string filename, string text = null, bool isTTS = false)
- => _messages.SendFile(stream, filename, text, isTTS);
-
- ///
- public Task TriggerTyping()
- => _messages.TriggerTyping();
-
- ///
- public async Task Delete()
- {
- try { await Discord.RestClient.Send(new DeleteChannelRequest(Id)).ConfigureAwait(false); }
- catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { }
- }
- ///
- public async Task Update()
- {
- var response = await Discord.RestClient.Send(new GetChannelRequest(Id)).ConfigureAwait(false);
- if (response != null)
- Update(response);
- }
-
- ///
- public override string ToString() => Name;
- }
-}
diff --git a/src/Discord.Net/Entities/Channels/GuildChannel.cs b/src/Discord.Net/Entities/Channels/GuildChannel.cs
deleted file mode 100644
index aea8c86c0..000000000
--- a/src/Discord.Net/Entities/Channels/GuildChannel.cs
+++ /dev/null
@@ -1,129 +0,0 @@
-using Discord.API.Rest;
-using Discord.Net;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Threading.Tasks;
-using Model = Discord.API.Channel;
-
-namespace Discord
-{
- public abstract class GuildChannel : IChannel, IEntity
- {
- private readonly PermissionManager _permissions;
-
- ///