@@ -0,0 +1,64 @@ | |||||
using System; | |||||
using System.Threading.Tasks; | |||||
namespace Discord.Rpc | |||||
{ | |||||
public partial class DiscordRpcClient | |||||
{ | |||||
//General | |||||
public event Func<Task> Connected | |||||
{ | |||||
add { _connectedEvent.Add(value); } | |||||
remove { _connectedEvent.Remove(value); } | |||||
} | |||||
private readonly AsyncEvent<Func<Task>> _connectedEvent = new AsyncEvent<Func<Task>>(); | |||||
public event Func<Exception, Task> Disconnected | |||||
{ | |||||
add { _disconnectedEvent.Add(value); } | |||||
remove { _disconnectedEvent.Remove(value); } | |||||
} | |||||
private readonly AsyncEvent<Func<Exception, Task>> _disconnectedEvent = new AsyncEvent<Func<Exception, Task>>(); | |||||
public event Func<Task> Ready | |||||
{ | |||||
add { _readyEvent.Add(value); } | |||||
remove { _readyEvent.Remove(value); } | |||||
} | |||||
private readonly AsyncEvent<Func<Task>> _readyEvent = new AsyncEvent<Func<Task>>(); | |||||
//Guild | |||||
public event Func<Task> GuildUpdated | |||||
{ | |||||
add { _guildUpdatedEvent.Add(value); } | |||||
remove { _guildUpdatedEvent.Remove(value); } | |||||
} | |||||
private readonly AsyncEvent<Func<Task>> _guildUpdatedEvent = new AsyncEvent<Func<Task>>(); | |||||
//Voice | |||||
public event Func<Task> VoiceStateUpdated | |||||
{ | |||||
add { _voiceStateUpdatedEvent.Add(value); } | |||||
remove { _voiceStateUpdatedEvent.Remove(value); } | |||||
} | |||||
private readonly AsyncEvent<Func<Task>> _voiceStateUpdatedEvent = new AsyncEvent<Func<Task>>(); | |||||
//Messages | |||||
public event Func<Task> MessageReceived | |||||
{ | |||||
add { _messageReceivedEvent.Add(value); } | |||||
remove { _messageReceivedEvent.Remove(value); } | |||||
} | |||||
private readonly AsyncEvent<Func<Task>> _messageReceivedEvent = new AsyncEvent<Func<Task>>(); | |||||
public event Func<Task> MessageUpdated | |||||
{ | |||||
add { _messageUpdatedEvent.Add(value); } | |||||
remove { _messageUpdatedEvent.Remove(value); } | |||||
} | |||||
private readonly AsyncEvent<Func<Task>> _messageUpdatedEvent = new AsyncEvent<Func<Task>>(); | |||||
public event Func<Task> MessageDeleted | |||||
{ | |||||
add { _messageDeletedEvent.Add(value); } | |||||
remove { _messageDeletedEvent.Remove(value); } | |||||
} | |||||
private readonly AsyncEvent<Func<Task>> _messageDeletedEvent = new AsyncEvent<Func<Task>>(); | |||||
} | |||||
} |
@@ -237,7 +237,7 @@ namespace Discord.Rpc | |||||
{ | { | ||||
//CancellationToken = cancelToken //TODO: Implement | //CancellationToken = cancelToken //TODO: Implement | ||||
}; | }; | ||||
if (LoginState != LoginState.LoggedOut) | if (LoginState != LoginState.LoggedOut) | ||||
await ApiClient.SendAuthenticateAsync(options).ConfigureAwait(false); //Has bearer | await ApiClient.SendAuthenticateAsync(options).ConfigureAwait(false); //Has bearer | ||||
@@ -253,6 +253,58 @@ namespace Discord.Rpc | |||||
} | } | ||||
break; | break; | ||||
//Guilds | |||||
case "GUILD_STATUS": | |||||
{ | |||||
await _guildUpdatedEvent.InvokeAsync().ConfigureAwait(false); | |||||
} | |||||
break; | |||||
//Voice | |||||
case "VOICE_STATE_CREATE": | |||||
{ | |||||
await _voiceStateUpdatedEvent.InvokeAsync().ConfigureAwait(false); | |||||
} | |||||
break; | |||||
case "VOICE_STATE_UPDATE": | |||||
{ | |||||
await _voiceStateUpdatedEvent.InvokeAsync().ConfigureAwait(false); | |||||
} | |||||
break; | |||||
case "VOICE_STATE_DELETE": | |||||
{ | |||||
await _voiceStateUpdatedEvent.InvokeAsync().ConfigureAwait(false); | |||||
} | |||||
break; | |||||
case "SPEAKING_START": | |||||
{ | |||||
await _voiceStateUpdatedEvent.InvokeAsync().ConfigureAwait(false); | |||||
} | |||||
break; | |||||
case "SPEAKING_STOP": | |||||
{ | |||||
await _voiceStateUpdatedEvent.InvokeAsync().ConfigureAwait(false); | |||||
} | |||||
break; | |||||
//Messages | |||||
case "MESSAGE_CREATE": | |||||
{ | |||||
await _messageReceivedEvent.InvokeAsync().ConfigureAwait(false); | |||||
} | |||||
break; | |||||
case "MESSAGE_UPDATE": | |||||
{ | |||||
await _messageUpdatedEvent.InvokeAsync().ConfigureAwait(false); | |||||
} | |||||
break; | |||||
case "MESSAGE_DELETE": | |||||
{ | |||||
await _messageDeletedEvent.InvokeAsync().ConfigureAwait(false); | |||||
} | |||||
break; | |||||
//Others | //Others | ||||
default: | default: | ||||
await _rpcLogger.WarningAsync($"Unknown Dispatch ({evnt})").ConfigureAwait(false); | await _rpcLogger.WarningAsync($"Unknown Dispatch ({evnt})").ConfigureAwait(false); | ||||
@@ -260,7 +312,7 @@ namespace Discord.Rpc | |||||
} | } | ||||
break; | break; | ||||
/*default: | |||||
/*default: //Other opcodes are used for command responses | |||||
await _rpcLogger.WarningAsync($"Unknown OpCode ({cmd})").ConfigureAwait(false); | await _rpcLogger.WarningAsync($"Unknown OpCode ({cmd})").ConfigureAwait(false); | ||||
return;*/ | return;*/ | ||||
} | } | ||||