Started converting websocket and rpc classes
This commit is contained in:
@@ -3,6 +3,7 @@ using Discord.API.Rpc;
|
||||
using Discord.Net.Queue;
|
||||
using Discord.Net.Rest;
|
||||
using Discord.Net.WebSockets;
|
||||
using Discord.Rpc;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
@@ -66,8 +67,8 @@ namespace Discord.API
|
||||
|
||||
public ConnectionState ConnectionState { get; private set; }
|
||||
|
||||
public DiscordRpcApiClient(string clientId, string origin, RestClientProvider restClientProvider, WebSocketProvider webSocketProvider, JsonSerializer serializer = null, RequestQueue requestQueue = null)
|
||||
: base(restClientProvider, serializer, requestQueue)
|
||||
public DiscordRpcApiClient(string clientId, string userAgent, string origin, RestClientProvider restClientProvider, WebSocketProvider webSocketProvider, JsonSerializer serializer = null, RequestQueue requestQueue = null)
|
||||
: base(restClientProvider, userAgent, serializer, requestQueue)
|
||||
{
|
||||
_connectionLock = new SemaphoreSlim(1, 1);
|
||||
_clientId = clientId;
|
||||
|
||||
3
src/Discord.Net.Rpc/AssemblyInfo.cs
Normal file
3
src/Discord.Net.Rpc/AssemblyInfo.cs
Normal file
@@ -0,0 +1,3 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Discord.Net.Test")]
|
||||
@@ -11,9 +11,9 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public partial class DiscordRpcClient : DiscordRestClient
|
||||
public partial class DiscordRpcClient : DiscordClient
|
||||
{
|
||||
private readonly ILogger _rpcLogger;
|
||||
private readonly Logger _rpcLogger;
|
||||
private readonly JsonSerializer _serializer;
|
||||
|
||||
private TaskCompletionSource<bool> _connectTask;
|
||||
@@ -58,18 +58,7 @@ namespace Discord.Rpc
|
||||
};
|
||||
}
|
||||
private static API.DiscordRpcApiClient CreateApiClient(DiscordRpcConfig config)
|
||||
=> new API.DiscordRpcApiClient(config.ClientId, config.Origin, config.RestClientProvider, config.WebSocketProvider, requestQueue: new RequestQueue());
|
||||
|
||||
internal override void Dispose(bool disposing)
|
||||
{
|
||||
if (!_isDisposed)
|
||||
ApiClient.Dispose();
|
||||
}
|
||||
|
||||
protected override Task ValidateTokenAsync(TokenType tokenType, string token)
|
||||
{
|
||||
return Task.CompletedTask; //Validation is done in DiscordRpcAPIClient
|
||||
}
|
||||
=> new API.DiscordRpcApiClient(config.ClientId, DiscordRestConfig.UserAgent, config.Origin, config.RestClientProvider, config.WebSocketProvider, requestQueue: new RequestQueue());
|
||||
|
||||
/// <inheritdoc />
|
||||
public Task ConnectAsync() => ConnectAsync(false);
|
||||
@@ -371,20 +360,20 @@ namespace Discord.Rpc
|
||||
//Messages
|
||||
case "MESSAGE_CREATE":
|
||||
{
|
||||
await _rpcLogger.DebugAsync("Received Dispatch (MESSAGE_CREATE)").ConfigureAwait(false);
|
||||
/*await _rpcLogger.DebugAsync("Received Dispatch (MESSAGE_CREATE)").ConfigureAwait(false);
|
||||
var data = (payload.Value as JToken).ToObject<MessageEvent>(_serializer);
|
||||
var msg = new RpcMessage(this, data.Message);
|
||||
|
||||
await _messageReceivedEvent.InvokeAsync(data.ChannelId, msg).ConfigureAwait(false);
|
||||
await _messageReceivedEvent.InvokeAsync(data.ChannelId, msg).ConfigureAwait(false);*/
|
||||
}
|
||||
break;
|
||||
case "MESSAGE_UPDATE":
|
||||
{
|
||||
await _rpcLogger.DebugAsync("Received Dispatch (MESSAGE_UPDATE)").ConfigureAwait(false);
|
||||
/*await _rpcLogger.DebugAsync("Received Dispatch (MESSAGE_UPDATE)").ConfigureAwait(false);
|
||||
var data = (payload.Value as JToken).ToObject<MessageEvent>(_serializer);
|
||||
var msg = new RpcMessage(this, data.Message);
|
||||
|
||||
await _messageUpdatedEvent.InvokeAsync(data.ChannelId, msg).ConfigureAwait(false);
|
||||
await _messageUpdatedEvent.InvokeAsync(data.ChannelId, msg).ConfigureAwait(false);*/
|
||||
}
|
||||
break;
|
||||
case "MESSAGE_DELETE":
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
/*public interface IRemoteUserGuild : ISnowflakeEntity
|
||||
{
|
||||
/// <summary> Gets the name of this guild. </summary>
|
||||
string Name { get; }
|
||||
}*/
|
||||
}
|
||||
10
src/Discord.Net.Rpc/Entities/Messages/RpcMessage.cs
Normal file
10
src/Discord.Net.Rpc/Entities/Messages/RpcMessage.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
/*internal class RpcMessage : RpcEntity<ulong>, IMessage
|
||||
{
|
||||
internal RpcMessage(DiscordRpcClient discord, API.Message model)
|
||||
: base(dicsord, model.Id)
|
||||
{
|
||||
}
|
||||
}*/
|
||||
}
|
||||
19
src/Discord.Net.Rpc/Entities/RpcEntity.cs
Normal file
19
src/Discord.Net.Rpc/Entities/RpcEntity.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
public abstract class RpcEntity<T> : IEntity<T>
|
||||
where T : IEquatable<T>
|
||||
{
|
||||
public DiscordRpcClient Discord { get; }
|
||||
public T Id { get; }
|
||||
|
||||
internal RpcEntity(DiscordRpcClient discord, T id)
|
||||
{
|
||||
Discord = discord;
|
||||
Id = id;
|
||||
}
|
||||
|
||||
IDiscordClient IEntity<T>.Discord => Discord;
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using Model = Discord.API.Rpc.RpcUserGuild;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
/*internal class RemoteUserGuild : IRemoteUserGuild, ISnowflakeEntity
|
||||
/*internal class RemoteUserGuild : RpcEntity, IRemoteUserGuild, ISnowflakeEntity
|
||||
{
|
||||
public ulong Id { get; }
|
||||
public DiscordRestClient Discord { get; }
|
||||
@@ -12,7 +12,7 @@ namespace Discord.Rpc
|
||||
|
||||
public DateTimeOffset CreatedAt => DateTimeUtils.FromSnowflake(Id);
|
||||
|
||||
public RemoteUserGuild(DiscordRestClient discord, Model model)
|
||||
internal RemoteUserGuild(DiscordRestClient discord, Model model)
|
||||
{
|
||||
Id = model.Id;
|
||||
Discord = discord;
|
||||
@@ -1,15 +0,0 @@
|
||||
using Discord.Rest;
|
||||
|
||||
namespace Discord.Rpc
|
||||
{
|
||||
internal class RpcMessage : Message
|
||||
{
|
||||
public override DiscordRestClient Discord { get; }
|
||||
|
||||
public RpcMessage(DiscordRpcClient discord, API.Message model)
|
||||
: base(null, model.Author.IsSpecified ? new User(model.Author.Value) : null, model)
|
||||
{
|
||||
Discord = discord;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,35 @@
|
||||
{
|
||||
"version": "1.0.0-beta2-*",
|
||||
|
||||
"buildOptions": {
|
||||
"compile": {
|
||||
"include": [ "../Discord.Net.Utils/**.cs" ]
|
||||
"configurations": {
|
||||
"Release": {
|
||||
"buildOptions": {
|
||||
"define": [ "RELEASE" ],
|
||||
"nowarn": [ "CS1573", "CS1591" ],
|
||||
"optimize": true,
|
||||
"warningsAsErrors": true,
|
||||
"xmlDoc": true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
"dependencies": {
|
||||
"Discord.Net.Core": {
|
||||
"target": "project"
|
||||
},
|
||||
"Discord.Net.Rest": {
|
||||
"target": "project"
|
||||
},
|
||||
"NETStandard.Library": "1.6.0"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"netstandard1.6": {
|
||||
"imports": "dnxcore50"
|
||||
"netstandard1.3": {
|
||||
"imports": [
|
||||
"dotnet5.4",
|
||||
"dnxcore50",
|
||||
"portable-net45+win8"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user