Isolated API definitions to their own library

This commit is contained in:
RogueException
2016-12-23 15:10:45 -04:00
parent ca6eb6aff4
commit 8326d01f62
200 changed files with 183 additions and 73 deletions

View File

@@ -1,11 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class AuthenticateParams
{
[JsonProperty("access_token")]
public string AccessToken { get; set; }
}
}

View File

@@ -1,18 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
using System;
namespace Discord.API.Rpc
{
public class AuthenticateResponse
{
[JsonProperty("application")]
public Application Application { get; set; }
[JsonProperty("expires")]
public DateTimeOffset Expires { get; set; }
[JsonProperty("user")]
public User User { get; set; }
[JsonProperty("scopes")]
public string[] Scopes { get; set; }
}
}

View File

@@ -1,16 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Discord.API.Rpc
{
public class AuthorizeParams
{
[JsonProperty("client_id")]
public string ClientId { get; set; }
[JsonProperty("scopes")]
public IReadOnlyCollection<string> Scopes { get; set; }
[JsonProperty("rpc_token")]
public Optional<string> RpcToken { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class AuthorizeResponse
{
[JsonProperty("code")]
public string Code { get; set; }
}
}

View File

@@ -1,34 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class Channel
{
//Shared
[JsonProperty("id")]
public ulong Id { get; set; }
[JsonProperty("type")]
public ChannelType Type { get; set; }
//GuildChannel
[JsonProperty("guild_id")]
public Optional<ulong> GuildId { get; set; }
[JsonProperty("name")]
public Optional<string> Name { get; set; }
[JsonProperty("position")]
public Optional<int> Position { get; set; }
//IMessageChannel
[JsonProperty("messages")]
public Message[] Messages { get; set; }
//VoiceChannel
[JsonProperty("bitrate")]
public Optional<int> Bitrate { get; set; }
[JsonProperty("user_limit")]
public Optional<int> UserLimit { get; set; }
[JsonProperty("voice_states")]
public ExtendedVoiceState[] VoiceStates { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class ChannelSubscriptionParams
{
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
}
}

View File

@@ -1,14 +0,0 @@
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class ChannelSummary
{
[JsonProperty("id")]
public ulong Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("type")]
public ChannelType Type { get; set; }
}
}

View File

@@ -1,13 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class ErrorEvent
{
[JsonProperty("code")]
public int Code { get; set; }
[JsonProperty("message")]
public string Message { get; set; }
}
}

View File

@@ -1,21 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class ExtendedVoiceState
{
[JsonProperty("user")]
public User User { get; set; }
[JsonProperty("voice_state")]
public Optional<VoiceState> VoiceState { get; set; }
[JsonProperty("nick")]
public Optional<string> Nickname { get; set; }
[JsonProperty("volume")]
public Optional<int> Volume { get; set; }
[JsonProperty("mute")]
public Optional<bool> Mute { get; set; }
[JsonProperty("pan")]
public Optional<Pan> Pan { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class GetChannelParams
{
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class GetChannelsParams
{
[JsonProperty("guild_id")]
public ulong GuildId { get; set; }
}
}

View File

@@ -1,12 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Discord.API.Rpc
{
public class GetChannelsResponse
{
[JsonProperty("channels")]
public IReadOnlyCollection<ChannelSummary> Channels { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class GetGuildParams
{
[JsonProperty("guild_id")]
public ulong GuildId { get; set; }
}
}

View File

@@ -1,8 +0,0 @@
#pragma warning disable CS1591
namespace Discord.API.Rpc
{
public class GetGuildsParams
{
}
}

View File

@@ -1,11 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class GetGuildsResponse
{
[JsonProperty("guilds")]
public GuildSummary[] Guilds { get; set; }
}
}

View File

@@ -1,18 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Discord.API.Rpc
{
public class Guild
{
[JsonProperty("id")]
public ulong Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
[JsonProperty("icon_url")]
public string IconUrl { get; set; }
[JsonProperty("members")]
public IEnumerable<GuildMember> Members { get; set; }
}
}

View File

@@ -1,15 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class GuildMember
{
[JsonProperty("user")]
public User User { get; set; }
[JsonProperty("status")]
public UserStatus Status { get; set; }
/*[JsonProperty("activity")]
public object Activity { get; set; }*/
}
}

View File

@@ -1,13 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class GuildStatusEvent
{
[JsonProperty("guild")]
public Guild Guild { get; set; }
[JsonProperty("online")]
public int Online { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class GuildSubscriptionParams
{
[JsonProperty("guild_id")]
public ulong GuildId { get; set; }
}
}

View File

@@ -1,12 +0,0 @@
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class GuildSummary
{
[JsonProperty("id")]
public ulong Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
}

View File

@@ -1,17 +0,0 @@
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class Message : Discord.API.Message
{
[JsonProperty("blocked")]
public Optional<bool> IsBlocked { get; }
[JsonProperty("content_parsed")]
public Optional<object[]> ContentParsed { get; }
[JsonProperty("author_color")]
public Optional<string> AuthorColor { get; } //#Hex
[JsonProperty("mentions")]
public new Optional<ulong[]> UserMentions { get; set; }
}
}

View File

@@ -1,12 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class MessageEvent
{
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
[JsonProperty("message")]
public Message Message { get; set; }
}
}

View File

@@ -1,12 +0,0 @@
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class Pan
{
[JsonProperty("left")]
public float Left { get; set; }
[JsonProperty("right")]
public float Right { get; set; }
}
}

View File

@@ -1,13 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class ReadyEvent
{
[JsonProperty("v")]
public int Version { get; set; }
[JsonProperty("config")]
public RpcConfig Config { get; set; }
}
}

View File

@@ -1,15 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class RpcConfig
{
[JsonProperty("cdn_host")]
public string CdnHost { get; set; }
[JsonProperty("api_endpoint")]
public string ApiEndpoint { get; set; }
[JsonProperty("environment")]
public string Environment { get; set; }
}
}

View File

@@ -1,13 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class SelectChannelParams
{
[JsonProperty("channel_id")]
public ulong? ChannelId { get; set; }
[JsonProperty("force")]
public Optional<bool> Force { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class SetLocalVolumeParams
{
[JsonProperty("volume")]
public int Volume { get; set; }
}
}

View File

@@ -1,13 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class SetLocalVolumeResponse
{
[JsonProperty("user_id")]
public ulong UserId { get; set; }
[JsonProperty("volume")]
public int Volume { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class SpeakingEvent
{
[JsonProperty("user_id")]
public ulong UserId { get; set; }
}
}

View File

@@ -1,11 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class SubscriptionResponse
{
[JsonProperty("evt")]
public string Event { get; set; }
}
}

View File

@@ -1,18 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class UserVoiceSettings
{
[JsonProperty("userId")]
internal ulong UserId { get; set; }
[JsonProperty("pan")]
public Optional<Pan> Pan { get; set; }
[JsonProperty("volume")]
public Optional<int> Volume { get; set; }
[JsonProperty("mute")]
public Optional<bool> Mute { get; set; }
}
}

View File

@@ -1,12 +0,0 @@
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class VoiceDevice
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("name")]
public string Name { get; set; }
}
}

View File

@@ -1,14 +0,0 @@
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class VoiceDeviceSettings
{
[JsonProperty("device_id")]
public Optional<string> DeviceId { get; set; }
[JsonProperty("volume")]
public Optional<float> Volume { get; set; }
[JsonProperty("available_devices")]
public Optional<VoiceDevice[]> AvailableDevices { get; set; }
}
}

View File

@@ -1,18 +0,0 @@
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class VoiceMode
{
[JsonProperty("type")]
public Optional<string> Type { get; set; }
[JsonProperty("auto_threshold")]
public Optional<bool> AutoThreshold { get; set; }
[JsonProperty("threshold")]
public Optional<float> Threshold { get; set; }
[JsonProperty("shortcut")]
public Optional<VoiceShortcut[]> Shortcut { get; set; }
[JsonProperty("delay")]
public Optional<float> Delay { get; set; }
}
}

View File

@@ -1,26 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class VoiceSettings
{
[JsonProperty("input")]
public VoiceDeviceSettings Input { get; set; }
[JsonProperty("output")]
public VoiceDeviceSettings Output { get; set; }
[JsonProperty("mode")]
public VoiceMode Mode { get; set; }
[JsonProperty("automatic_gain_control")]
public Optional<bool> AutomaticGainControl { get; set; }
[JsonProperty("echo_cancellation")]
public Optional<bool> EchoCancellation { get; set; }
[JsonProperty("noise_suppression")]
public Optional<bool> NoiseSuppression { get; set; }
[JsonProperty("qos")]
public Optional<bool> QualityOfService { get; set; }
[JsonProperty("silence_warning")]
public Optional<bool> SilenceWarning { get; set; }
}
}

View File

@@ -1,15 +0,0 @@
using Discord.Rpc;
using Newtonsoft.Json;
namespace Discord.API.Rpc
{
public class VoiceShortcut
{
[JsonProperty("type")]
public Optional<VoiceShortcutType> Type { get; set; }
[JsonProperty("code")]
public Optional<int> Code { get; set; }
[JsonProperty("name")]
public Optional<string> Name { get; set; }
}
}

View File

@@ -1,20 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
using System;
namespace Discord.API.Rpc
{
public class RpcFrame
{
[JsonProperty("cmd")]
public string Cmd { get; set; }
[JsonProperty("nonce")]
public Optional<Guid?> Nonce { get; set; }
[JsonProperty("evt")]
public Optional<string> Event { get; set; }
[JsonProperty("data")]
public Optional<object> Data { get; set; }
[JsonProperty("args")]
public object Args { get; set; }
}
}

View File

@@ -9,6 +9,7 @@
<PackageLicenseUrl>http://opensource.org/licenses/MIT</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>git://github.com/RogueException/Discord.Net</RepositoryUrl>
<RootNamespace>Discord.Rpc</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
@@ -20,6 +21,7 @@
</Compile>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Discord.Net.API\Discord.Net.API.csproj" />
<ProjectReference Include="..\Discord.Net.Core\Discord.Net.Core.csproj" />
<ProjectReference Include="..\Discord.Net.Rest\Discord.Net.Rest.csproj" />
</ItemGroup>
@@ -29,9 +31,6 @@
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.Net.WebSockets.Client" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Net\" />
</ItemGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<NoWarn>$(NoWarn);CS1573;CS1591</NoWarn>
<WarningsAsErrors>true</WarningsAsErrors>

View File

@@ -69,14 +69,13 @@ namespace Discord.API
public ConnectionState ConnectionState { get; private set; }
public DiscordRpcApiClient(string clientId, string userAgent, string origin, RestClientProvider restClientProvider, WebSocketProvider webSocketProvider,
RetryMode defaultRetryMode = RetryMode.AlwaysRetry, JsonSerializer serializer = null, RequestQueue requestQueue = null)
: base(restClientProvider, userAgent, defaultRetryMode, serializer, requestQueue, false)
RetryMode defaultRetryMode = RetryMode.AlwaysRetry, JsonSerializer serializer = null)
: base(restClientProvider, userAgent, defaultRetryMode, serializer, false)
{
_connectionLock = new SemaphoreSlim(1, 1);
_clientId = clientId;
_origin = origin;
_requestQueue = requestQueue ?? new RequestQueue();
_requests = new ConcurrentDictionary<Guid, RpcRequest>();
_webSocketClient = webSocketProvider();

View File

@@ -67,7 +67,7 @@ namespace Discord.Rpc
}
private static API.DiscordRpcApiClient CreateApiClient(string clientId, string origin, DiscordRpcConfig config)
=> new API.DiscordRpcApiClient(clientId, DiscordRestConfig.UserAgent, origin, config.RestClientProvider, config.WebSocketProvider, requestQueue: new RequestQueue());
=> new API.DiscordRpcApiClient(clientId, DiscordRestConfig.UserAgent, origin, config.RestClientProvider, config.WebSocketProvider);
/// <inheritdoc />
public async Task ConnectAsync()

View File

@@ -14,7 +14,7 @@ namespace Discord.Rpc
public ushort DiscriminatorValue { get; private set; }
public string AvatarId { get; private set; }
public string AvatarUrl => API.CDN.GetUserAvatarUrl(Id, AvatarId);
public string AvatarUrl => CDN.GetUserAvatarUrl(Id, AvatarId);
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
public string Discriminator => DiscriminatorValue.ToString("D4");
public string Mention => MentionUtils.MentionUser(Id);

View File

@@ -1,10 +0,0 @@
namespace Discord.Rpc
{
public enum VoiceShortcutType
{
KeyboardKey = 0,
MouseButton = 1,
KeyboardModifierKey = 2,
GamepadButton = 3
}
}