| @@ -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 | |||
| @@ -1,8 +0,0 @@ | |||
| <?xml version="1.0" encoding="utf-8"?> | |||
| <configuration> | |||
| <packageSources> | |||
| <add key="AspNetCiDev" value="https://www.myget.org/F/aspnetcidev/api/v3/index.json" /> | |||
| <add key="NuGet" value="https://api.nuget.org/v3/index.json" /> | |||
| <add key="aspnet-contrib" value="https://www.myget.org/F/aspnet-contrib/api/v3/index.json" /> | |||
| </packageSources> | |||
| </configuration> | |||
| @@ -1,6 +0,0 @@ | |||
| { | |||
| "projects": [ "src" ], | |||
| "sdk": { | |||
| "version": "1.0.0-rc2-20221" | |||
| } | |||
| } | |||
| @@ -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; | |||
| @@ -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")] | |||
| @@ -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<ulong> Integrations { get; set; } | |||
| } | |||
| } | |||
| @@ -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")] | |||
| @@ -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")] | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -1,10 +0,0 @@ | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API | |||
| { | |||
| public class MemberPresenceGame | |||
| { | |||
| [JsonProperty("name")] | |||
| public string Name { get; set; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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<GetVoiceRegionsResponse[]> | |||
| { | |||
| 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; } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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<SentRequestEventArgs> 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<TResponse> Send<TResponse>(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<TResponse>(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<TResponse> Send<TResponse>(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<TResponse>(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<TResponse> Send<TResponse>(string method, string endpoint, Stream file, IReadOnlyDictionary<string, string> multipartArgs) | |||
| where TResponse : class | |||
| { | |||
| var stopwatch = Stopwatch.StartNew(); | |||
| var responseStream = await _restClient.Send(method, endpoint).ConfigureAwait(false); | |||
| stopwatch.Stop(); | |||
| var response = Deserialize<TResponse>(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<string, string> 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<GetGatewayResponse> GetGateway() | |||
| { | |||
| return await Send<GetGatewayResponse>("GET", "gateway").ConfigureAwait(false); | |||
| } | |||
| //Channels | |||
| public async Task<Channel> GetChannel(ulong channelId) | |||
| { | |||
| if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId)); | |||
| try | |||
| { | |||
| return await Send<Channel>("GET", $"channels/{channelId}").ConfigureAwait(false); | |||
| } | |||
| catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } | |||
| } | |||
| public async Task<Channel> GetChannel(ulong guildId, ulong channelId) | |||
| { | |||
| if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId)); | |||
| try | |||
| { | |||
| var model = await Send<Channel>("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<IEnumerable<Channel>> GetGuildChannels(ulong guildId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| return await Send<IEnumerable<Channel>>("GET", $"guild/{guildId}/channels").ConfigureAwait(false); | |||
| } | |||
| public async Task<Channel> 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<Channel>("POST", $"guilds/{guildId}/channels", args).ConfigureAwait(false); | |||
| } | |||
| public async Task<Channel> DeleteChannel(ulong channelId) | |||
| { | |||
| if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId)); | |||
| return await Send<Channel>("DELETE", $"channels/{channelId}").ConfigureAwait(false); | |||
| } | |||
| public async Task<Channel> 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<Channel>("PATCH", $"channels/{channelId}", args).ConfigureAwait(false); | |||
| } | |||
| public async Task<Channel> 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<Channel>("PATCH", $"channels/{channelId}", args).ConfigureAwait(false); | |||
| } | |||
| public async Task<Channel> 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<Channel>("PATCH", $"channels/{channelId}", args).ConfigureAwait(false); | |||
| } | |||
| public async Task ModifyGuildChannels(ulong guildId, IEnumerable<ModifyGuildChannelsParams> 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<Guild> GetGuild(ulong guildId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| try | |||
| { | |||
| return await Send<Guild>("GET", $"guilds/{guildId}").ConfigureAwait(false); | |||
| } | |||
| catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } | |||
| } | |||
| public async Task<Guild> 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<Guild>("POST", "guilds", args).ConfigureAwait(false); | |||
| } | |||
| public async Task<Guild> DeleteGuild(ulong guildId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| return await Send<Guild>("DELETE", $"guilds/{guildId}").ConfigureAwait(false); | |||
| } | |||
| public async Task<Guild> LeaveGuild(ulong guildId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| return await Send<Guild>("DELETE", $"users/@me/guilds/{guildId}").ConfigureAwait(false); | |||
| } | |||
| public async Task<Guild> 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<Guild>("PATCH", $"guilds/{guildId}", args).ConfigureAwait(false); | |||
| } | |||
| public async Task<GetGuildPruneCountResponse> 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<GetGuildPruneCountResponse>("POST", $"guilds/{guildId}/prune", args).ConfigureAwait(false); | |||
| } | |||
| public async Task<GetGuildPruneCountResponse> 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<GetGuildPruneCountResponse>("GET", $"guilds/{guildId}/prune", args).ConfigureAwait(false); | |||
| } | |||
| //Guild Bans | |||
| public async Task<IEnumerable<User>> GetGuildBans(ulong guildId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| return await Send<IEnumerable<User>>("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<GuildEmbed> GetGuildEmbed(ulong guildId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| try | |||
| { | |||
| return await Send<GuildEmbed>("GET", $"guilds/{guildId}/embed").ConfigureAwait(false); | |||
| } | |||
| catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } | |||
| } | |||
| public async Task<GuildEmbed> ModifyGuildEmbed(ulong guildId, ModifyGuildEmbedParams args) | |||
| { | |||
| if (args == null) throw new ArgumentNullException(nameof(args)); | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| return await Send<GuildEmbed>("PATCH", $"guilds/{guildId}/embed", args).ConfigureAwait(false); | |||
| } | |||
| //Guild Integrations | |||
| public async Task<IEnumerable<Integration>> GetGuildIntegrations(ulong guildId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| return await Send<IEnumerable<Integration>>("GET", $"guilds/{guildId}/integrations").ConfigureAwait(false); | |||
| } | |||
| public async Task<Integration> 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<Integration>("POST", $"guilds/{guildId}/integrations").ConfigureAwait(false); | |||
| } | |||
| public async Task<Integration> DeleteGuildIntegration(ulong guildId, ulong integrationId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| if (integrationId == 0) throw new ArgumentOutOfRangeException(nameof(integrationId)); | |||
| return await Send<Integration>("DELETE", $"guilds/{guildId}/integrations/{integrationId}").ConfigureAwait(false); | |||
| } | |||
| public async Task<Integration> 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<Integration>("PATCH", $"guilds/{guildId}/integrations/{integrationId}", args).ConfigureAwait(false); | |||
| } | |||
| public async Task<Integration> SyncGuildIntegration(ulong guildId, ulong integrationId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| if (integrationId == 0) throw new ArgumentOutOfRangeException(nameof(integrationId)); | |||
| return await Send<Integration>("POST", $"guilds/{guildId}/integrations/{integrationId}/sync").ConfigureAwait(false); | |||
| } | |||
| //Guild Invites | |||
| public async Task<Invite> GetInvite(string inviteIdOrXkcd) | |||
| { | |||
| if (string.IsNullOrEmpty(inviteIdOrXkcd)) throw new ArgumentOutOfRangeException(nameof(inviteIdOrXkcd)); | |||
| try | |||
| { | |||
| return await Send<Invite>("GET", $"invites/{inviteIdOrXkcd}").ConfigureAwait(false); | |||
| } | |||
| catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } | |||
| } | |||
| public async Task<IEnumerable<InviteMetadata>> GetGuildInvites(ulong guildId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| return await Send<IEnumerable<InviteMetadata>>("GET", $"guilds/{guildId}/invites").ConfigureAwait(false); | |||
| } | |||
| public async Task<InviteMetadata[]> GetChannelInvites(ulong channelId) | |||
| { | |||
| if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId)); | |||
| return await Send<InviteMetadata[]>("GET", $"channels/{channelId}/invites").ConfigureAwait(false); | |||
| } | |||
| public async Task<InviteMetadata> 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<InviteMetadata>("POST", $"channels/{channelId}/invites", args).ConfigureAwait(false); | |||
| } | |||
| public async Task<Invite> DeleteInvite(string inviteCode) | |||
| { | |||
| if (string.IsNullOrEmpty(inviteCode)) throw new ArgumentOutOfRangeException(nameof(inviteCode)); | |||
| return await Send<Invite>("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<GuildMember> 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<GuildMember>("GET", $"guilds/{guildId}/members/{userId}").ConfigureAwait(false); | |||
| } | |||
| catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } | |||
| } | |||
| public async Task<IEnumerable<GuildMember>> 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<GuildMember[]> result; | |||
| if (args.Limit != null) | |||
| result = new List<GuildMember[]>((limit + DiscordConfig.MaxUsersPerBatch - 1) / DiscordConfig.MaxUsersPerBatch); | |||
| else | |||
| result = new List<GuildMember[]>(); | |||
| while (true) | |||
| { | |||
| int runLimit = (limit >= DiscordConfig.MaxUsersPerBatch) ? DiscordConfig.MaxUsersPerBatch : limit; | |||
| string endpoint = $"guild/{guildId}/members?limit={limit}&offset={offset}"; | |||
| var models = await Send<GuildMember[]>("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<GuildMember> 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<GuildMember>("PATCH", $"guilds/{guildId}/members/{userId}", args).ConfigureAwait(false); | |||
| } | |||
| //Guild Roles | |||
| public async Task<IEnumerable<Role>> GetGuildRoles(ulong guildId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| return await Send<IEnumerable<Role>>("GET", $"guild/{guildId}/roles").ConfigureAwait(false); | |||
| } | |||
| public async Task<Role> CreateGuildRole(ulong guildId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| return await Send<Role>("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<Role> 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<Role>("PATCH", $"guilds/{guildId}/roles/{roleId}", args).ConfigureAwait(false); | |||
| } | |||
| public async Task<IEnumerable<Role>> ModifyGuildRoles(ulong guildId, IEnumerable<ModifyGuildRolesParams> 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<IEnumerable<Role>>("PATCH", $"guilds/{guildId}/roles", args).ConfigureAwait(false); | |||
| } | |||
| } | |||
| //Messages | |||
| public async Task<IEnumerable<Message>> 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<Message[]>("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<Message> CreateMessage(ulong channelId, CreateMessageParams args) | |||
| { | |||
| if (args == null) throw new ArgumentNullException(nameof(args)); | |||
| if (channelId == 0) throw new ArgumentOutOfRangeException(nameof(channelId)); | |||
| return await Send<Message>("POST", $"channels/{channelId}/messages", args).ConfigureAwait(false); | |||
| } | |||
| public async Task<Message> 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<Message>("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<Message> 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<Message>("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<User> GetUser(ulong userId) | |||
| { | |||
| if (userId == 0) throw new ArgumentOutOfRangeException(nameof(userId)); | |||
| try | |||
| { | |||
| return await Send<User>("GET", $"users/{userId}").ConfigureAwait(false); | |||
| } | |||
| catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } | |||
| } | |||
| public async Task<User> 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<IEnumerable<User>> 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<IEnumerable<User>>("GET", $"users?q={Uri.EscapeDataString(query)}&limit={limit}").ConfigureAwait(false); | |||
| } | |||
| //Current User/DMs | |||
| public async Task<User> GetCurrentUser() | |||
| { | |||
| return await Send<User>("GET", "users/@me").ConfigureAwait(false); | |||
| } | |||
| public async Task<IEnumerable<Connection>> GetCurrentUserConnections() | |||
| { | |||
| return await Send<IEnumerable<Connection>>("GET", "users/@me/connections").ConfigureAwait(false); | |||
| } | |||
| public async Task<IEnumerable<Channel>> GetCurrentUserDMs() | |||
| { | |||
| return await Send<IEnumerable<Channel>>("GET", "users/@me/channels").ConfigureAwait(false); | |||
| } | |||
| public async Task<IEnumerable<UserGuild>> GetCurrentUserGuilds() | |||
| { | |||
| return await Send<IEnumerable<UserGuild>>("GET", "users/@me/guilds").ConfigureAwait(false); | |||
| } | |||
| public async Task<User> 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<User>("PATCH", "users/@me", args).ConfigureAwait(false); | |||
| } | |||
| public async Task<Channel> CreateDMChannel(CreateDMChannelParams args) | |||
| { | |||
| if (args == null) throw new ArgumentNullException(nameof(args)); | |||
| if (args.RecipientId == 0) throw new ArgumentOutOfRangeException(nameof(args.RecipientId)); | |||
| return await Send<Channel>("POST", $"users/@me/channels", args).ConfigureAwait(false); | |||
| } | |||
| //Voice Regions | |||
| public async Task<IEnumerable<VoiceRegion>> GetVoiceRegions() | |||
| { | |||
| return await Send<IEnumerable<VoiceRegion>>("GET", "voice/regions").ConfigureAwait(false); | |||
| } | |||
| public async Task<IEnumerable<VoiceRegion>> GetGuildVoiceRegions(ulong guildId) | |||
| { | |||
| if (guildId == 0) throw new ArgumentOutOfRangeException(nameof(guildId)); | |||
| return await Send<IEnumerable<VoiceRegion>>("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<T>(Stream jsonStream) | |||
| { | |||
| using (TextReader text = new StreamReader(jsonStream)) | |||
| using (JsonReader reader = new JsonTextReader(text)) | |||
| return _serializer.Deserialize<T>(reader); | |||
| } | |||
| private bool HandleException(Exception ex) | |||
| { | |||
| //TODO: Implement... maybe via SentRequest? Need to bubble this up to DiscordClient or a MessageQueue | |||
| return false; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,26 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public enum OpCode : byte | |||
| { | |||
| /// <summary> C←S - Used to send most events. </summary> | |||
| Dispatch = 0, | |||
| /// <summary> C↔S - Used to keep the connection alive and measure latency. </summary> | |||
| Heartbeat = 1, | |||
| /// <summary> C→S - Used to associate a connection with a token and specify configuration. </summary> | |||
| Identify = 2, | |||
| /// <summary> C→S - Used to update client's status and current game id. </summary> | |||
| StatusUpdate = 3, | |||
| /// <summary> C→S - Used to join a particular voice channel. </summary> | |||
| VoiceStateUpdate = 4, | |||
| /// <summary> C→S - Used to ensure the guild's voice server is alive. Only send this if voice connection fails or suddenly drops. </summary> | |||
| VoiceServerPing = 5, | |||
| /// <summary> C→S - Used to resume a connection after a redirect occurs. </summary> | |||
| Resume = 6, | |||
| /// <summary> C←S - Used to notify a client that they must reconnect to another gateway. </summary> | |||
| Reconnect = 7, | |||
| /// <summary> C→S - Used to request all members that were withheld by large_threshold. </summary> | |||
| RequestGuildMembers = 8, | |||
| /// <summary> C←S - Used to notify the client of an invalid session id. </summary> | |||
| InvalidSession = 9 | |||
| } | |||
| } | |||
| @@ -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(); | |||
| } | |||
| } | |||
| @@ -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<string, string> Properties { get; set; } | |||
| [JsonProperty("large_threshold", NullValueHandling = NullValueHandling.Ignore)] | |||
| public int LargeThreshold { get; set; } | |||
| [JsonProperty("compress")] | |||
| public bool UseCompression { get; set; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class ChannelCreateEvent : Channel { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class ChannelDeleteEvent : Channel { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class ChannelUpdateEvent : Channel { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class GuildBanAddEvent : MemberReference { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class GuildBanRemoveEvent : MemberReference { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class GuildCreateEvent : ExtendedGuild { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class GuildDeleteEvent : ExtendedGuild { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class GuildMemberAddEvent : ExtendedMember { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class GuildMemberRemoveEvent : MemberReference { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class GuildMemberUpdateEvent : GuildMember { } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class GuildRoleDeleteEvent : RoleReference { } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class GuildUpdateEvent : Guild { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class MessageAckEvent : MessageReference { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class MessageCreateEvent : Message { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class MessageDeleteEvent : MessageReference { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class MessageUpdateEvent : Message { } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class PresenceUpdateEvent : MemberPresence { } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -1,10 +0,0 @@ | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class ResumedEvent | |||
| { | |||
| [JsonProperty("heartbeat_interval")] | |||
| public int HeartbeatInterval { get; set; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class UserUpdateEvent : User { } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -1,4 +0,0 @@ | |||
| namespace Discord.API.GatewaySocket | |||
| { | |||
| public class VoiceStateUpdateEvent : MemberVoiceState { } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class AcceptInviteRequest : IRestRequest<Invite> | |||
| { | |||
| string IRestRequest.Method => "POST"; | |||
| string IRestRequest.Endpoint => $"invites/{InviteCode}"; | |||
| object IRestRequest.Payload => null; | |||
| public string InviteCode { get; } | |||
| public AcceptInviteRequest(string inviteCode) | |||
| { | |||
| InviteCode = inviteCode; | |||
| } | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,23 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization.OptIn)] | |||
| public class BeginGuildPruneRequest : IRestRequest<GetGuildPruneCountResponse> | |||
| { | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,29 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization.OptIn)] | |||
| public class CreateChannelInviteRequest : IRestRequest<Invite> | |||
| { | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -1,16 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization.OptIn)] | |||
| public class CreateDMChannelRequest : IRestRequest<Channel> | |||
| { | |||
| string IRestRequest.Method => "POST"; | |||
| string IRestRequest.Endpoint => $"users/@me/channels"; | |||
| object IRestRequest.Payload => this; | |||
| [JsonProperty("recipient_id")] | |||
| public ulong RecipientId { get; set; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class CreateDMChannelParams | |||
| { | |||
| [JsonProperty("recipient_id")] | |||
| public ulong RecipientId { get; set; } | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class CreateGuildBanParams | |||
| { | |||
| [JsonProperty("delete-message-days")] | |||
| public int PruneDays { get; set; } = 0; | |||
| } | |||
| } | |||
| @@ -1,27 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization.OptIn)] | |||
| public class CreateGuildChannelRequest : IRestRequest<Channel> | |||
| { | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -1,25 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization.OptIn)] | |||
| public class CreateGuildIntegrationRequest : IRestRequest<Integration> | |||
| { | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| } | |||
| } | |||
| @@ -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<Guild> | |||
| public class CreateGuildParams | |||
| { | |||
| string IRestRequest.Method => "POST"; | |||
| string IRestRequest.Endpoint => $"guilds"; | |||
| object IRestRequest.Payload => this; | |||
| [JsonProperty("name")] | |||
| public string Name { get; set; } | |||
| [JsonProperty("region")] | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class CreateGuildRoleRequest : IRestRequest<Role> | |||
| { | |||
| string IRestRequest.Method => "POST"; | |||
| string IRestRequest.Endpoint => $"guilds/{GuildId}/roles"; | |||
| object IRestRequest.Payload => null; | |||
| public ulong GuildId { get; } | |||
| public CreateGuildRoleRequest(ulong guildId) | |||
| { | |||
| GuildId = guildId; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,27 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization.OptIn)] | |||
| public class CreateMessageRequest : IRestRequest<Message> | |||
| { | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class DeleteChannelRequest : IRestRequest<Channel> | |||
| { | |||
| string IRestRequest.Method => "DELETE"; | |||
| string IRestRequest.Endpoint => $"channels/{ChannelId}"; | |||
| object IRestRequest.Payload => null; | |||
| public ulong ChannelId { get; } | |||
| public DeleteChannelRequest(ulong channelId) | |||
| { | |||
| ChannelId = channelId; | |||
| } | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class DeleteGuildRequest : IRestRequest<Guild> | |||
| { | |||
| string IRestRequest.Method => "DELETE"; | |||
| string IRestRequest.Endpoint => $"guilds/{GuildId}"; | |||
| object IRestRequest.Payload => null; | |||
| public ulong GuildId { get; } | |||
| public DeleteGuildRequest(ulong guildId) | |||
| { | |||
| GuildId = guildId; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,20 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class DeleteGuildIntegrationRequest : IRestRequest<Integration> | |||
| { | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class DeleteInviteRequest : IRestRequest<Invite> | |||
| { | |||
| string IRestRequest.Method => "DELETE"; | |||
| string IRestRequest.Endpoint => $"invites/{InviteCode}"; | |||
| object IRestRequest.Payload => null; | |||
| public string InviteCode { get; } | |||
| public DeleteInviteRequest(string inviteCode) | |||
| { | |||
| InviteCode = inviteCode; | |||
| } | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,11 @@ | |||
| using Newtonsoft.Json; | |||
| using System.Collections.Generic; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class DeleteMessagesParam | |||
| { | |||
| [JsonProperty("messages")] | |||
| public IEnumerable<ulong> MessageIds { get; set; } | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetChannelRequest : IRestRequest<Channel> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"channels/{ChannelId}"; | |||
| object IRestRequest.Payload => null; | |||
| public ulong ChannelId { get; } | |||
| public GetChannelRequest(ulong channelId) | |||
| { | |||
| ChannelId = channelId; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,20 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization.OptIn)] | |||
| public class GetChannelInvitesRequest : IRestRequest<InviteMetadata[]> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"channels/{ChannelId}/invites"; | |||
| object IRestRequest.Payload => null; | |||
| public ulong ChannelId { get; } | |||
| public GetChannelInvitesRequest(ulong channelId) | |||
| { | |||
| ChannelId = channelId; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,34 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization.OptIn)] | |||
| public class GetChannelMessagesRequest : IRestRequest<Message[]> | |||
| { | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -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; | |||
| } | |||
| } | |||
| @@ -1,11 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetCurrentUserRequest : IRestRequest<User> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"users/@me"; | |||
| object IRestRequest.Payload => null; | |||
| } | |||
| } | |||
| @@ -1,11 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetCurrentUserConnectionsRequest : IRestRequest<Connection[]> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"users/@me/connections"; | |||
| object IRestRequest.Payload => null; | |||
| } | |||
| } | |||
| @@ -1,11 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetCurrentUserDMsRequest : IRestRequest<Channel[]> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"users/@me/channels"; | |||
| object IRestRequest.Payload => null; | |||
| } | |||
| } | |||
| @@ -1,11 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetCurrentUserGuildsRequest : IRestRequest<Guild[]> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"users/@me/guilds"; | |||
| object IRestRequest.Payload => null; | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetGatewayRequest : IRestRequest<GetGatewayResponse> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"gateway"; | |||
| object IRestRequest.Payload => null; | |||
| } | |||
| public class GetGatewayResponse | |||
| { | |||
| [JsonProperty("url")] | |||
| public string Url { get; set; } | |||
| } | |||
| } | |||
| @@ -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; } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetGuildRequest : IRestRequest<Guild> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"guilds/{GuildId}"; | |||
| object IRestRequest.Payload => null; | |||
| public ulong GuildId { get; } | |||
| public GetGuildRequest(ulong guildId) | |||
| { | |||
| GuildId = guildId; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetGuildBansRequest : IRestRequest<User[]> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"guilds/{GuildId}/bans"; | |||
| object IRestRequest.Payload => null; | |||
| public ulong GuildId { get; } | |||
| public GetGuildBansRequest(ulong guildId) | |||
| { | |||
| GuildId = guildId; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetGuildChannelsRequest : IRestRequest<Channel[]> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"guild/{GuildId}/channels"; | |||
| object IRestRequest.Payload => null; | |||
| public ulong GuildId { get; } | |||
| public GetGuildChannelsRequest(ulong guildId) | |||
| { | |||
| GuildId = guildId; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetGuildEmbedRequest : IRestRequest<GuildEmbed> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"guilds/{GuildId}/embed"; | |||
| object IRestRequest.Payload => null; | |||
| public ulong GuildId { get; } | |||
| public GetGuildEmbedRequest(ulong guildId) | |||
| { | |||
| GuildId = guildId; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetGuildIntegrationsRequest : IRestRequest<Integration[]> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"guilds/{GuildId}/integrations"; | |||
| object IRestRequest.Payload => null; | |||
| public ulong GuildId { get; } | |||
| public GetGuildIntegrationsRequest(ulong guildId) | |||
| { | |||
| GuildId = guildId; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetGuildInvitesRequest : IRestRequest<Invite[]> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"guilds/{GuildId}/invites"; | |||
| object IRestRequest.Payload => null; | |||
| public ulong GuildId { get; } | |||
| public GetGuildInvitesRequest(ulong guildId) | |||
| { | |||
| GuildId = guildId; | |||
| } | |||
| } | |||
| } | |||
| @@ -1,20 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetGuildMemberRequest : IRestRequest<GuildMember> | |||
| { | |||
| 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; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,8 @@ | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetGuildMembersParams | |||
| { | |||
| public int? Limit { get; set; } = null; | |||
| public int Offset { get; set; } = 0; | |||
| } | |||
| } | |||
| @@ -1,29 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| [JsonObject(MemberSerialization.OptIn)] | |||
| public class GetGuildPruneCountRequest : IRestRequest<GetGuildPruneCountResponse> | |||
| { | |||
| 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; } | |||
| } | |||
| } | |||
| @@ -0,0 +1,10 @@ | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetGuildPruneCountResponse | |||
| { | |||
| [JsonProperty("pruned")] | |||
| public int Pruned { get; set; } | |||
| } | |||
| } | |||
| @@ -1,18 +0,0 @@ | |||
| using Discord.Net.Rest; | |||
| namespace Discord.API.Rest | |||
| { | |||
| public class GetGuildRolesRequest : IRestRequest<Role[]> | |||
| { | |||
| string IRestRequest.Method => "GET"; | |||
| string IRestRequest.Endpoint => $"guild/{GuildId}/roles"; | |||
| object IRestRequest.Payload => null; | |||
| public ulong GuildId { get; } | |||
| public GetGuildRolesRequest(ulong guildId) | |||
| { | |||
| GuildId = guildId; | |||
| } | |||
| } | |||
| } | |||