diff --git a/src/Discord.Net/API/Voice.cs b/src/Discord.Net/API/Voice.cs index 17670dcf0..d1f223a1e 100644 --- a/src/Discord.Net/API/Voice.cs +++ b/src/Discord.Net/API/Voice.cs @@ -53,90 +53,4 @@ namespace Discord.API [JsonProperty("token")] public string Token; } - - //Commands (Voice) - internal sealed class VoiceLoginCommand : WebSocketMessage - { - public VoiceLoginCommand() : base(0) { } - public class Data - { - [JsonProperty("server_id")] - [JsonConverter(typeof(LongStringConverter))] - public long ServerId; - [JsonProperty("user_id")] - [JsonConverter(typeof(LongStringConverter))] - public long UserId; - [JsonProperty("session_id")] - public string SessionId; - [JsonProperty("token")] - public string Token; - } - } - internal sealed class VoiceLogin2Command : WebSocketMessage - { - public VoiceLogin2Command() : base(1) { } - public class Data - { - public class SocketInfo - { - [JsonProperty("address")] - public string Address; - [JsonProperty("port")] - public int Port; - [JsonProperty("mode")] - public string Mode = "xsalsa20_poly1305"; - } - [JsonProperty("protocol")] - public string Protocol = "udp"; - [JsonProperty("data")] - public SocketInfo SocketData = new SocketInfo(); - } - } - internal sealed class VoiceKeepAliveCommand : WebSocketMessage - { - public VoiceKeepAliveCommand() : base(3, EpochTime.GetMilliseconds()) { } - } - internal sealed class IsTalkingCommand : WebSocketMessage - { - public IsTalkingCommand() : base(5) { } - public class Data - { - [JsonProperty("delay")] - public int Delay; - [JsonProperty("speaking")] - public bool IsSpeaking; - } - } - - //Events (Voice) - public class VoiceReadyEvent - { - [JsonProperty("ssrc")] - public uint SSRC; - [JsonProperty("port")] - public ushort Port; - [JsonProperty("modes")] - public string[] Modes; - [JsonProperty("heartbeat_interval")] - public int HeartbeatInterval; - } - - public class JoinServerEvent - { - [JsonProperty("secret_key")] - public byte[] SecretKey; - [JsonProperty("mode")] - public string Mode; - } - - public class IsTalkingEvent - { - [JsonProperty("user_id")] - [JsonConverter(typeof(LongStringConverter))] - public long UserId; - [JsonProperty("ssrc")] - public uint SSRC; - [JsonProperty("speaking")] - public bool IsSpeaking; - } } diff --git a/src/Discord.Net/Helpers/Shared/EventHelper.cs b/src/Discord.Net/Helpers/Shared/EventHelper.cs new file mode 100644 index 000000000..6fc6a5811 --- /dev/null +++ b/src/Discord.Net/Helpers/Shared/EventHelper.cs @@ -0,0 +1,17 @@ +using System; + +namespace Discord +{ + public static class EventHelper + { + public static void Raise(Logger logger, string name, Action action) + { + try { action(); } + catch (Exception ex) + { + var ex2 = ex.GetBaseException(); + logger.Log(LogSeverity.Error, $"{name}'s handler raised {ex2.GetType().Name}: ${ex2.Message}", ex); + } + } + } +} diff --git a/src/Discord.Net/LogExtensions.cs b/src/Discord.Net/LogExtensions.cs new file mode 100644 index 000000000..7d524aa3f --- /dev/null +++ b/src/Discord.Net/LogExtensions.cs @@ -0,0 +1,8 @@ +namespace Discord +{ + public static class LogExtensions + { + public static LogService Log(this DiscordClient client, bool required = true) + => client.GetService(required); + } +}