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,25 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
using System;
namespace Discord.API.Gateway
{
public class ExtendedGuild : Guild
{
[JsonProperty("unavailable")]
public bool? Unavailable { get; set; }
[JsonProperty("member_count")]
public int MemberCount { get; set; }
[JsonProperty("large")]
public bool Large { get; set; }
[JsonProperty("presences")]
public Presence[] Presences { get; set; }
[JsonProperty("members")]
public GuildMember[] Members { get; set; }
[JsonProperty("channels")]
public Channel[] Channels { get; set; }
[JsonProperty("joined_at")]
public DateTimeOffset JoinedAt { get; set; }
}
}

View File

@@ -1,33 +0,0 @@
#pragma warning disable CS1591
namespace Discord.API.Gateway
{
public enum GatewayOpCode : 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. </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 members that were withheld by large_threshold </summary>
RequestGuildMembers = 8,
/// <summary> C←S - Used to notify the client that their session has expired and cannot be resumed. </summary>
InvalidSession = 9,
/// <summary> C←S - Used to provide information to the client immediately on connection. </summary>
Hello = 10,
/// <summary> C←S - Used to reply to a client's heartbeat. </summary>
HeartbeatAck = 11,
/// <summary> C→S - Used to request presence updates from particular guilds. </summary>
GuildSync = 12
}
}

View File

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

View File

@@ -1,13 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Gateway
{
public class GuildEmojiUpdateEvent
{
[JsonProperty("guild_id")]
public ulong GuildId { get; set; }
[JsonProperty("emojis")]
public Emoji[] Emojis { get; set; }
}
}

View File

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

View File

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

View File

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

View File

@@ -1,13 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Gateway
{
public class GuildMembersChunkEvent
{
[JsonProperty("guild_id")]
public ulong GuildId { get; set; }
[JsonProperty("members")]
public GuildMember[] Members { get; set; }
}
}

View File

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

View File

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

View File

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

View File

@@ -1,18 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Gateway
{
public class GuildSyncEvent
{
[JsonProperty("id")]
public ulong Id { get; set; }
[JsonProperty("large")]
public bool Large { get; set; }
[JsonProperty("presences")]
public Presence[] Presences { get; set; }
[JsonProperty("members")]
public GuildMember[] Members { get; set; }
}
}

View File

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

View File

@@ -1,21 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Discord.API.Gateway
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class IdentifyParams
{
[JsonProperty("token")]
public string Token { get; set; }
[JsonProperty("properties")]
public IDictionary<string, string> Properties { get; set; }
[JsonProperty("large_threshold")]
public int LargeThreshold { get; set; }
[JsonProperty("compress")]
public bool UseCompression { get; set; }
[JsonProperty("shard")]
public Optional<int[]> ShardingParams { get; set; }
}
}

View File

@@ -1,14 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Discord.API.Gateway
{
public class MessageDeleteBulkEvent
{
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
[JsonProperty("ids")]
public IEnumerable<ulong> Ids { get; set; }
}
}

View File

@@ -1,16 +0,0 @@
using Newtonsoft.Json;
namespace Discord.API.Gateway
{
public class Reaction
{
[JsonProperty("user_id")]
public ulong UserId { get; set; }
[JsonProperty("message_id")]
public ulong MessageId { get; set; }
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
[JsonProperty("emoji")]
public Emoji Emoji { get; set; }
}
}

View File

@@ -1,38 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Gateway
{
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("relationships")]
public Relationship[] Relationships { get; set; }
//Ignored
/*[JsonProperty("user_settings")]
[JsonProperty("user_guild_settings")]
[JsonProperty("tutorial")]*/
}
}

View File

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

View File

@@ -1,12 +0,0 @@
using Newtonsoft.Json;
namespace Discord.API.Gateway
{
public class RemoveAllReactionsEvent
{
[JsonProperty("channel_id")]
public ulong ChannelId { get; set; }
[JsonProperty("message_id")]
public ulong MessageId { get; set; }
}
}

View File

@@ -1,18 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
using System.Collections.Generic;
namespace Discord.API.Gateway
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class RequestMembersParams
{
[JsonProperty("query")]
public string Query { get; set; }
[JsonProperty("limit")]
public int Limit { get; set; }
[JsonProperty("guild_id")]
public IEnumerable<ulong> GuildIds { get; set; }
}
}

View File

@@ -1,16 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Gateway
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class ResumeParams
{
[JsonProperty("token")]
public string Token { get; set; }
[JsonProperty("session_id")]
public string SessionId { get; set; }
[JsonProperty("seq")]
public int Sequence { get; set; }
}
}

View File

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

View File

@@ -1,18 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Gateway
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class StatusUpdateParams
{
[JsonProperty("status")]
public UserStatus Status { get; set; }
[JsonProperty("since"), Int53]
public long? IdleSince { get; set; }
[JsonProperty("afk")]
public bool IsAFK { get; set; }
[JsonProperty("game")]
public Game Game { get; set; }
}
}

View File

@@ -1,15 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Gateway
{
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; }
}
}

View File

@@ -1,15 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Gateway
{
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; }
}
}

View File

@@ -1,22 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Gateway
{
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
public class VoiceStateUpdateParams
{
[JsonProperty("self_mute")]
public bool SelfMute { get; set; }
[JsonProperty("self_deaf")]
public bool SelfDeaf { get; set; }
[JsonProperty("guild_id")]
public ulong? GuildId { get; set; }
public IGuild Guild { set { GuildId = value?.Id; } }
[JsonProperty("channel_id")]
public ulong? ChannelId { get; set; }
public IChannel Channel { set { ChannelId = value?.Id; } }
}
}

View File

@@ -1,17 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API
{
public class SocketFrame
{
[JsonProperty("op")]
public int Operation { get; set; }
[JsonProperty("t", NullValueHandling = NullValueHandling.Ignore)]
public string Type { get; set; }
[JsonProperty("s", NullValueHandling = NullValueHandling.Ignore)]
public int? Sequence { get; set; }
[JsonProperty("d")]
public object Payload { get; set; }
}
}

View File

@@ -1,17 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Voice
{
public class IdentifyParams
{
[JsonProperty("server_id")]
public ulong GuildId { get; set; }
[JsonProperty("user_id")]
public ulong UserId { get; set; }
[JsonProperty("session_id")]
public string SessionId { get; set; }
[JsonProperty("token")]
public string Token { get; set; }
}
}

View File

@@ -1,17 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Voice
{
public class ReadyEvent
{
[JsonProperty("ssrc")]
public uint SSRC { get; set; }
[JsonProperty("port")]
public ushort Port { get; set; }
[JsonProperty("modes")]
public string[] Modes { get; set; }
[JsonProperty("heartbeat_interval")]
public int HeartbeatInterval { get; set; }
}
}

View File

@@ -1,13 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Voice
{
public class SelectProtocolParams
{
[JsonProperty("protocol")]
public string Protocol { get; set; }
[JsonProperty("data")]
public UdpProtocolInfo Data { get; set; }
}
}

View File

@@ -1,13 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Voice
{
public class SessionDescriptionEvent
{
[JsonProperty("secret_key")]
public byte[] SecretKey { get; set; }
[JsonProperty("mode")]
public string Mode { get; set; }
}
}

View File

@@ -1,13 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Voice
{
public class SpeakingParams
{
[JsonProperty("speaking")]
public bool IsSpeaking { get; set; }
[JsonProperty("delay")]
public int Delay { get; set; }
}
}

View File

@@ -1,15 +0,0 @@
#pragma warning disable CS1591
using Newtonsoft.Json;
namespace Discord.API.Voice
{
public class UdpProtocolInfo
{
[JsonProperty("address")]
public string Address { get; set; }
[JsonProperty("port")]
public int Port { get; set; }
[JsonProperty("mode")]
public string Mode { get; set; }
}
}

View File

@@ -1,21 +0,0 @@
#pragma warning disable CS1591
namespace Discord.API.Voice
{
public enum VoiceOpCode : byte
{
/// <summary> C→S - Used to associate a connection with a token. </summary>
Identify = 0,
/// <summary> C→S - Used to specify configuration. </summary>
SelectProtocol = 1,
/// <summary> C←S - Used to notify that the voice connection was successful and informs the client of available protocols. </summary>
Ready = 2,
/// <summary> C→S - Used to keep the connection alive and measure latency. </summary>
Heartbeat = 3,
/// <summary> C←S - Used to reply to a client's heartbeat. </summary>
HeartbeatAck = 3,
/// <summary> C←S - Used to provide an encryption key to the client. </summary>
SessionDescription = 4,
/// <summary> C↔S - Used to inform that a certain user is speaking. </summary>
Speaking = 5
}
}

View File

@@ -7,7 +7,6 @@ using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@@ -180,10 +179,9 @@ namespace Discord.Audio
{
return new RTPWriteStream(this, _secretKey, samplesPerFrame, _ssrc, bufferSize = 4000);
}
public Stream CreatePCMStream(int samplesPerFrame, int? bitrate = null,
OpusApplication application = OpusApplication.MusicOrMixed, int bufferSize = 4000)
public Stream CreatePCMStream(int samplesPerFrame, int? bitrate = null, int bufferSize = 4000)
{
return new OpusEncodeStream(this, _secretKey, samplesPerFrame, _ssrc, bitrate, application, bufferSize);
return new OpusEncodeStream(this, _secretKey, samplesPerFrame, _ssrc, bitrate, bufferSize);
}
private async Task ProcessMessageAsync(VoiceOpCode opCode, object payload)

View File

@@ -0,0 +1,9 @@
namespace Discord.Audio
{
public enum OpusApplication : int
{
Voice = 2048,
MusicOrMixed = 2049,
LowLatency = 2051
}
}

View File

@@ -7,8 +7,7 @@
private readonly OpusEncoder _encoder;
internal OpusEncodeStream(AudioClient audioClient, byte[] secretKey, int samplesPerFrame, uint ssrc, int? bitrate = null,
OpusApplication application = OpusApplication.MusicOrMixed, int bufferSize = 4000)
internal OpusEncodeStream(AudioClient audioClient, byte[] secretKey, int samplesPerFrame, uint ssrc, int? bitrate = null, int bufferSize = 4000)
: base(audioClient, secretKey, samplesPerFrame, ssrc, bufferSize)
{
_encoder = new OpusEncoder(SampleRate, Channels);

View File

@@ -10,12 +10,14 @@
<PackageLicenseUrl>http://opensource.org/licenses/MIT</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>git://github.com/RogueException/Discord.Net</RepositoryUrl>
<RootNamespace>Discord.WebSocket</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</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>

View File

@@ -33,8 +33,8 @@ namespace Discord.API
public ConnectionState ConnectionState { get; private set; }
public DiscordSocketApiClient(RestClientProvider restClientProvider, string userAgent, WebSocketProvider webSocketProvider,
RetryMode defaultRetryMode = RetryMode.AlwaysRetry, JsonSerializer serializer = null, RequestQueue requestQueue = null)
: base(restClientProvider, userAgent, defaultRetryMode, serializer, requestQueue, true)
RetryMode defaultRetryMode = RetryMode.AlwaysRetry, JsonSerializer serializer = null)
: base(restClientProvider, userAgent, defaultRetryMode, serializer, true)
{
_gatewayClient = webSocketProvider();
//_gatewayClient.SetHeader("user-agent", DiscordConfig.UserAgent); (Causes issues in .NET Framework 4.6+)

View File

@@ -126,7 +126,7 @@ namespace Discord.WebSocket
_largeGuilds = new ConcurrentQueue<ulong>();
}
private static API.DiscordSocketApiClient CreateApiClient(DiscordSocketConfig config)
=> new API.DiscordSocketApiClient(config.RestClientProvider, DiscordRestConfig.UserAgent, config.WebSocketProvider, requestQueue: new RequestQueue());
=> new API.DiscordSocketApiClient(config.RestClientProvider, DiscordRestConfig.UserAgent, config.WebSocketProvider);
protected override async Task OnLoginAsync(TokenType tokenType, string token)
{
@@ -1773,8 +1773,6 @@ namespace Discord.WebSocket
}
//IDiscordClient
DiscordRestApiClient IDiscordClient.ApiClient => ApiClient;
Task IDiscordClient.ConnectAsync()
=> ConnectAsync();

View File

@@ -15,7 +15,7 @@ namespace Discord.WebSocket
internal abstract SocketGlobalUser GlobalUser { get; }
internal abstract SocketPresence Presence { get; 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);