diff --git a/src/Discord.Net.Audio.Net45/Discord.Net.Audio.csproj b/src/Discord.Net.Audio.Net45/Discord.Net.Audio.csproj
index d613a1650..415f1b098 100644
--- a/src/Discord.Net.Audio.Net45/Discord.Net.Audio.csproj
+++ b/src/Discord.Net.Audio.Net45/Discord.Net.Audio.csproj
@@ -84,9 +84,18 @@
Sodium\SecretBox.cs
+
+ UserIsTalkingEventArgs.cs
+
VoiceBuffer.cs
+
+ VoiceDisconnectedEventArgs.cs
+
+
+ VoicePacketEventArgs.cs
+
diff --git a/src/Discord.Net.Audio/AudioService.cs b/src/Discord.Net.Audio/AudioService.cs
index fcd2a43b7..f9ba67db5 100644
--- a/src/Discord.Net.Audio/AudioService.cs
+++ b/src/Discord.Net.Audio/AudioService.cs
@@ -1,49 +1,10 @@
-using Discord.Net.WebSockets;
-using System;
+using System;
using System.Collections.Concurrent;
using System.Linq;
using System.Threading.Tasks;
namespace Discord.Audio
{
- public class VoiceDisconnectedEventArgs : DisconnectedEventArgs
- {
- public readonly ulong ServerId;
-
- public VoiceDisconnectedEventArgs(ulong serverId, DisconnectedEventArgs e)
- : base(e.WasUnexpected, e.Exception)
- {
- ServerId = serverId;
- }
- }
- public class UserIsSpeakingEventArgs : UserEventArgs
- {
- public readonly bool IsSpeaking;
-
- public UserIsSpeakingEventArgs(User user, bool isSpeaking)
- : base(user)
- {
- IsSpeaking = isSpeaking;
- }
- }
- public class VoicePacketEventArgs : EventArgs
- {
- public readonly ulong UserId;
- public readonly ulong ChannelId;
- public readonly byte[] Buffer;
- public readonly int Offset;
- public readonly int Count;
-
- public VoicePacketEventArgs(ulong userId, ulong channelId, byte[] buffer, int offset, int count)
- {
- UserId = userId;
- ChannelId = channelId;
- Buffer = buffer;
- Offset = offset;
- Count = count;
- }
- }
-
public class AudioService : IService
{
private AudioClient _defaultClient;
@@ -51,46 +12,33 @@ namespace Discord.Audio
private ConcurrentDictionary _talkingUsers;
//private int _nextClientId;
- internal DiscordClient Client => _client;
- private DiscordClient _client;
+ internal DiscordClient Client { get; private set; }
+ public AudioServiceConfig Config { get; }
- public AudioServiceConfig Config => _config;
- private readonly AudioServiceConfig _config;
+ public event EventHandler Connected = delegate { };
+ public event EventHandler Disconnected = delegate { };
+ public event EventHandler PacketReceived = delegate { };
+ public event EventHandler UserIsSpeakingUpdated = delegate { };
- public event EventHandler Connected;
- private void RaiseConnected()
- {
- if (Connected != null)
- Connected(this, EventArgs.Empty);
- }
- public event EventHandler Disconnected;
- private void RaiseDisconnected(ulong serverId, DisconnectedEventArgs e)
- {
- if (Disconnected != null)
- Disconnected(this, new VoiceDisconnectedEventArgs(serverId, e));
- }
- public event EventHandler OnPacket;
- internal void RaiseOnPacket(VoicePacketEventArgs e)
- {
- if (OnPacket != null)
- OnPacket(this, e);
- }
- public event EventHandler UserIsSpeakingUpdated;
- private void RaiseUserIsSpeakingUpdated(User user, bool isSpeaking)
- {
- if (UserIsSpeakingUpdated != null)
- UserIsSpeakingUpdated(this, new UserIsSpeakingEventArgs(user, isSpeaking));
- }
+ private void OnConnected()
+ => Connected(this, EventArgs.Empty);
+ private void OnDisconnected(ulong serverId, bool wasUnexpected, Exception ex)
+ => Disconnected(this, new VoiceDisconnectedEventArgs(serverId, wasUnexpected, ex));
+ internal void OnPacketReceived(VoicePacketEventArgs e)
+ => PacketReceived(this, e);
+ private void OnUserIsSpeakingUpdated(User user, bool isSpeaking)
+ => UserIsSpeakingUpdated(this, new UserIsSpeakingEventArgs(user, isSpeaking));
public AudioService(AudioServiceConfig config)
{
- _config = config;
- _config.Lock();
+ Config = config;
}
public void Install(DiscordClient client)
{
- _client = client;
- if (Config.EnableMultiserver)
+ Client = client;
+ Config.Lock();
+
+ if (Config.EnableMultiserver)
_voiceClients = new ConcurrentDictionary();
else
{
@@ -113,7 +61,7 @@ namespace Discord.Audio
{
bool ignored;
if (_talkingUsers.TryRemove(member.Key, out ignored))
- RaiseUserIsSpeakingUpdated(member.Key, false);
+ OnUserIsSpeakingUpdated(member.Key, false);
}
};
}
diff --git a/src/Discord.Net.Audio/UserIsTalkingEventArgs.cs b/src/Discord.Net.Audio/UserIsTalkingEventArgs.cs
new file mode 100644
index 000000000..698f44d4c
--- /dev/null
+++ b/src/Discord.Net.Audio/UserIsTalkingEventArgs.cs
@@ -0,0 +1,13 @@
+namespace Discord
+{
+ public class UserIsSpeakingEventArgs : UserEventArgs
+ {
+ public bool IsSpeaking { get; }
+
+ public UserIsSpeakingEventArgs(User user, bool isSpeaking)
+ : base(user)
+ {
+ IsSpeaking = isSpeaking;
+ }
+ }
+}
diff --git a/src/Discord.Net.Audio/VoiceDisconnectedEventArgs.cs b/src/Discord.Net.Audio/VoiceDisconnectedEventArgs.cs
new file mode 100644
index 000000000..4f46abde2
--- /dev/null
+++ b/src/Discord.Net.Audio/VoiceDisconnectedEventArgs.cs
@@ -0,0 +1,15 @@
+using System;
+
+namespace Discord
+{
+ public class VoiceDisconnectedEventArgs : DisconnectedEventArgs
+ {
+ public ulong ServerId { get; }
+
+ public VoiceDisconnectedEventArgs(ulong serverId, bool wasUnexpected, Exception ex)
+ : base(wasUnexpected, ex)
+ {
+ ServerId = serverId;
+ }
+ }
+}
diff --git a/src/Discord.Net.Audio/VoicePacketEventArgs.cs b/src/Discord.Net.Audio/VoicePacketEventArgs.cs
new file mode 100644
index 000000000..1f509182b
--- /dev/null
+++ b/src/Discord.Net.Audio/VoicePacketEventArgs.cs
@@ -0,0 +1,22 @@
+using System;
+
+namespace Discord
+{
+ public class VoicePacketEventArgs : EventArgs
+ {
+ public ulong UserId { get; }
+ public ulong ChannelId { get; }
+ public byte[] Buffer { get; }
+ public int Offset { get; }
+ public int Count { get; }
+
+ public VoicePacketEventArgs(ulong userId, ulong channelId, byte[] buffer, int offset, int count)
+ {
+ UserId = userId;
+ ChannelId = channelId;
+ Buffer = buffer;
+ Offset = offset;
+ Count = count;
+ }
+ }
+}
diff --git a/src/Discord.Net.Commands.Net45/Discord.Net.Commands.csproj b/src/Discord.Net.Commands.Net45/Discord.Net.Commands.csproj
index 5f7eac6e8..d28a6875f 100644
--- a/src/Discord.Net.Commands.Net45/Discord.Net.Commands.csproj
+++ b/src/Discord.Net.Commands.Net45/Discord.Net.Commands.csproj
@@ -45,21 +45,27 @@
CommandBuilder.cs
+
+ CommandErrorEventArgs.cs
+
+
+ CommandEventArgs.cs
+
CommandExtensions.cs
CommandMap.cs
+
+ CommandParameter.cs
+
CommandParser.cs
CommandService.cs
-
- CommandService.Events.cs
-
CommandServiceConfig.cs
diff --git a/src/Discord.Net.Commands/Command.cs b/src/Discord.Net.Commands/Command.cs
index 28f414485..8aec0b90f 100644
--- a/src/Discord.Net.Commands/Command.cs
+++ b/src/Discord.Net.Commands/Command.cs
@@ -5,48 +5,24 @@ using System.Threading.Tasks;
namespace Discord.Commands
{
- public enum ParameterType
- {
- /// Catches a single required parameter.
- Required,
- /// Catches a single optional parameter.
- Optional,
- /// Catches a zero or more optional parameters.
- Multiple,
- /// Catches all remaining text as a single optional parameter.
- Unparsed
- }
- public sealed class CommandParameter
- {
- public string Name { get; }
- public int Id { get; internal set; }
- public ParameterType Type { get; }
-
- public CommandParameter(string name, ParameterType type)
- {
- Name = name;
- Type = type;
- }
- }
-
public sealed class Command
- {
- public string Text { get; }
+ {
+ private string[] _aliases;
+ internal CommandParameter[] _parameters;
+ private IPermissionChecker[] _checks;
+ private Func _runFunc;
+ internal readonly Dictionary _parametersByName;
+
+ public string Text { get; }
public string Category { get; internal set; }
public bool IsHidden { get; internal set; }
public string Description { get; internal set; }
public IEnumerable Aliases => _aliases;
- private string[] _aliases;
-
public IEnumerable Parameters => _parameters;
- internal CommandParameter[] _parameters;
-
- private IPermissionChecker[] _checks;
- private Func _runFunc;
- internal readonly Dictionary _parametersByName;
+ public CommandParameter this[string name] => _parametersByName[name];
- internal Command(string text)
+ internal Command(string text)
{
Text = text;
IsHidden = false;
@@ -55,7 +31,6 @@ namespace Discord.Commands
_parametersByName = new Dictionary();
}
- public CommandParameter this[string name] => _parametersByName[name];
internal void SetAliases(string[] aliases)
{
diff --git a/src/Discord.Net.Commands/CommandErrorEventArgs.cs b/src/Discord.Net.Commands/CommandErrorEventArgs.cs
new file mode 100644
index 000000000..5f47c6d7c
--- /dev/null
+++ b/src/Discord.Net.Commands/CommandErrorEventArgs.cs
@@ -0,0 +1,18 @@
+using System;
+
+namespace Discord.Commands
+{
+ public enum CommandErrorType { Exception, UnknownCommand, BadPermissions, BadArgCount, InvalidInput }
+ public class CommandErrorEventArgs : CommandEventArgs
+ {
+ public CommandErrorType ErrorType { get; }
+ public Exception Exception { get; }
+
+ public CommandErrorEventArgs(CommandErrorType errorType, CommandEventArgs baseArgs, Exception ex)
+ : base(baseArgs.Message, baseArgs.Command, baseArgs.Args)
+ {
+ Exception = ex;
+ ErrorType = errorType;
+ }
+ }
+}
diff --git a/src/Discord.Net.Commands/CommandEventArgs.cs b/src/Discord.Net.Commands/CommandEventArgs.cs
new file mode 100644
index 000000000..818f5fa23
--- /dev/null
+++ b/src/Discord.Net.Commands/CommandEventArgs.cs
@@ -0,0 +1,27 @@
+using System;
+
+namespace Discord.Commands
+{
+ public class CommandEventArgs : EventArgs
+ {
+ private readonly string[] _args;
+
+ public Message Message { get; }
+ public Command Command { get; }
+
+ public User User => Message.User;
+ public Channel Channel => Message.Channel;
+ public Server Server => Message.Channel.Server;
+
+ public CommandEventArgs(Message message, Command command, string[] args)
+ {
+ Message = message;
+ Command = command;
+ _args = args;
+ }
+
+ public string[] Args => _args;
+ public string GetArg(int index) => _args[index];
+ public string GetArg(string name) => _args[Command[name].Id];
+ }
+}
diff --git a/src/Discord.Net.Commands/CommandParameter.cs b/src/Discord.Net.Commands/CommandParameter.cs
new file mode 100644
index 000000000..413674b78
--- /dev/null
+++ b/src/Discord.Net.Commands/CommandParameter.cs
@@ -0,0 +1,26 @@
+namespace Discord.Commands
+{
+ public enum ParameterType
+ {
+ /// Catches a single required parameter.
+ Required,
+ /// Catches a single optional parameter.
+ Optional,
+ /// Catches a zero or more optional parameters.
+ Multiple,
+ /// Catches all remaining text as a single optional parameter.
+ Unparsed
+ }
+ public sealed class CommandParameter
+ {
+ public string Name { get; }
+ public int Id { get; internal set; }
+ public ParameterType Type { get; }
+
+ public CommandParameter(string name, ParameterType type)
+ {
+ Name = name;
+ Type = type;
+ }
+ }
+}
diff --git a/src/Discord.Net.Commands/CommandService.Events.cs b/src/Discord.Net.Commands/CommandService.Events.cs
deleted file mode 100644
index c5ad7747b..000000000
--- a/src/Discord.Net.Commands/CommandService.Events.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-using System;
-
-namespace Discord.Commands
-{
- public class CommandEventArgs : EventArgs
- {
- private readonly string[] _args;
-
- public Message Message { get; }
- public Command Command { get; }
-
- public User User => Message.User;
- public Channel Channel => Message.Channel;
- public Server Server => Message.Channel.Server;
-
- public CommandEventArgs(Message message, Command command, string[] args)
- {
- Message = message;
- Command = command;
- _args = args;
- }
-
- public string[] Args => _args;
- public string GetArg(int index) => _args[index];
- public string GetArg(string name) => _args[Command[name].Id];
- }
-
- public enum CommandErrorType { Exception, UnknownCommand, BadPermissions, BadArgCount, InvalidInput }
- public class CommandErrorEventArgs : CommandEventArgs
- {
- public CommandErrorType ErrorType { get; }
- public Exception Exception { get; }
-
- public CommandErrorEventArgs(CommandErrorType errorType, CommandEventArgs baseArgs, Exception ex)
- : base(baseArgs.Message, baseArgs.Command, baseArgs.Args)
- {
- Exception = ex;
- ErrorType = errorType;
- }
- }
-
- public partial class CommandService
- {
- public event EventHandler RanCommand;
- private void RaiseRanCommand(CommandEventArgs args)
- {
- if (RanCommand != null)
- RanCommand(this, args);
- }
- public event EventHandler CommandError;
- private void RaiseCommandError(CommandErrorType errorType, CommandEventArgs args, Exception ex = null)
- {
- if (CommandError != null)
- CommandError(this, new CommandErrorEventArgs(errorType, args, ex));
- }
- }
-}
diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs
index 8269832f3..f54f8e3a1 100644
--- a/src/Discord.Net.Commands/CommandService.cs
+++ b/src/Discord.Net.Commands/CommandService.cs
@@ -6,42 +6,45 @@ using System.Threading.Tasks;
namespace Discord.Commands
{
- /// A Discord.Net client with extensions for handling common bot operations like text commands.
- public sealed partial class CommandService : IService
+ public partial class CommandService : IService
{
- private readonly CommandServiceConfig _config;
- private readonly CommandGroupBuilder _root;
- private DiscordClient _client;
-
- public DiscordClient Client => _client;
- public CommandGroupBuilder Root => _root;
+ private readonly List _allCommands;
+ private readonly Dictionary _categories;
+ private readonly CommandMap _map; //Command map stores all commands by their input text, used for fast resolving and parsing
+
+ public CommandServiceConfig Config { get; }
+ public CommandGroupBuilder Root { get; }
+ public DiscordClient Client { get; private set; }
//AllCommands store a flattened collection of all commands
- public IEnumerable AllCommands => _allCommands;
- private readonly List _allCommands;
-
- //Command map stores all commands by their input text, used for fast resolving and parsing
- private readonly CommandMap _map;
-
+ public IEnumerable AllCommands => _allCommands;
//Groups store all commands by their module, used for more informative help
internal IEnumerable Categories => _categories.Values;
- private readonly Dictionary _categories;
- public CommandService(CommandServiceConfig config)
+ public event EventHandler Command = delegate { };
+ public event EventHandler CommandError = delegate { };
+
+ private void OnCommand(CommandEventArgs args)
+ => Command(this, args);
+ private void OnCommandError(CommandErrorType errorType, CommandEventArgs args, Exception ex = null)
+ => CommandError(this, new CommandErrorEventArgs(errorType, args, ex));
+
+ public CommandService(CommandServiceConfig config)
{
- _config = config;
+ Config = config;
+
_allCommands = new List();
_map = new CommandMap(null, "", "");
_categories = new Dictionary();
- _root = new CommandGroupBuilder(this, "", null);
+ Root = new CommandGroupBuilder(this, "", null);
}
void IService.Install(DiscordClient client)
{
- _client = client;
- _config.Lock();
+ Client = client;
+ Config.Lock();
- if (_config.HelpMode != HelpMode.Disable)
+ if (Config.HelpMode != HelpMode.Disable)
{
CreateCommand("help")
.Parameter("command", ParameterType.Multiple)
@@ -49,7 +52,7 @@ namespace Discord.Commands
.Description("Returns information about commands.")
.Do(async e =>
{
- Channel replyChannel = _config.HelpMode == HelpMode.Public ? e.Channel : await e.User.CreatePMChannel().ConfigureAwait(false);
+ Channel replyChannel = Config.HelpMode == HelpMode.Public ? e.Channel : await e.User.CreatePMChannel().ConfigureAwait(false);
if (e.Args.Length > 0) //Show command help
{
var map = _map.GetItem(string.Join(" ", e.Args));
@@ -66,13 +69,13 @@ namespace Discord.Commands
client.MessageReceived += async (s, e) =>
{
if (_allCommands.Count == 0) return;
- if (e.Message.User == null || e.Message.User.Id == _client.CurrentUser.Id) return;
+ if (e.Message.User == null || e.Message.User.Id == Client.CurrentUser.Id) return;
string msg = e.Message.RawText;
if (msg.Length == 0) return;
//Check for command char if one is provided
- var chars = _config.CommandChars;
+ var chars = Config.CommandChars;
if (chars.Length > 0)
{
if (!chars.Contains(msg[0]))
@@ -87,7 +90,7 @@ namespace Discord.Commands
if (commands == null)
{
CommandEventArgs errorArgs = new CommandEventArgs(e.Message, null, null);
- RaiseCommandError(CommandErrorType.UnknownCommand, errorArgs);
+ OnCommandError(CommandErrorType.UnknownCommand, errorArgs);
return;
}
else
@@ -104,7 +107,7 @@ namespace Discord.Commands
else
{
var errorArgs = new CommandEventArgs(e.Message, command, null);
- RaiseCommandError(error.Value, errorArgs);
+ OnCommandError(error.Value, errorArgs);
return;
}
}
@@ -115,24 +118,24 @@ namespace Discord.Commands
string errorText;
if (!command.CanRun(eventArgs.User, eventArgs.Channel, out errorText))
{
- RaiseCommandError(CommandErrorType.BadPermissions, eventArgs, errorText != null ? new Exception(errorText) : null);
+ OnCommandError(CommandErrorType.BadPermissions, eventArgs, errorText != null ? new Exception(errorText) : null);
return;
}
// Run the command
try
{
- RaiseRanCommand(eventArgs);
+ OnCommand(eventArgs);
await command.Run(eventArgs).ConfigureAwait(false);
}
catch (Exception ex)
{
- RaiseCommandError(CommandErrorType.Exception, eventArgs, ex);
+ OnCommandError(CommandErrorType.Exception, eventArgs, ex);
}
return;
}
var errorArgs2 = new CommandEventArgs(e.Message, null, null);
- RaiseCommandError(CommandErrorType.BadArgCount, errorArgs2);
+ OnCommandError(CommandErrorType.BadArgCount, errorArgs2);
}
};
}
@@ -184,7 +187,7 @@ namespace Discord.Commands
{
output.Append("\n\n");
- var chars = _config.CommandChars;
+ var chars = Config.CommandChars;
if (chars.Length > 0)
{
if (chars.Length == 1)
@@ -294,8 +297,8 @@ namespace Discord.Commands
output.AppendLine($"Aliases: `" + string.Join("`, `", command.Aliases) + '`');
}
- public void CreateGroup(string cmd, Action config = null) => _root.CreateGroup(cmd, config);
- public CommandBuilder CreateCommand(string cmd) => _root.CreateCommand(cmd);
+ public void CreateGroup(string cmd, Action config = null) => Root.CreateGroup(cmd, config);
+ public CommandBuilder CreateCommand(string cmd) => Root.CreateCommand(cmd);
internal void AddCommand(Command command)
{
diff --git a/src/Discord.Net.Modules/ModuleManager.cs b/src/Discord.Net.Modules/ModuleManager.cs
index af70d0967..0ab3b8867 100644
--- a/src/Discord.Net.Modules/ModuleManager.cs
+++ b/src/Discord.Net.Modules/ModuleManager.cs
@@ -6,7 +6,7 @@ using System.Linq;
namespace Discord.Modules
{
- public class ModuleManager
+ public sealed class ModuleManager
{
public event EventHandler ServerEnabled = delegate { };
public event EventHandler ServerDisabled = delegate { };
diff --git a/src/Discord.Net.Modules/ModuleService.cs b/src/Discord.Net.Modules/ModuleService.cs
index 0f3c455ae..731b57457 100644
--- a/src/Discord.Net.Modules/ModuleService.cs
+++ b/src/Discord.Net.Modules/ModuleService.cs
@@ -5,21 +5,19 @@ namespace Discord.Modules
{
public class ModuleService : IService
{
- private DiscordClient _client;
-
- //ModuleServiceConfig Config { get; }
+ public DiscordClient Client { get; private set; }
+
public IEnumerable Modules => _modules.Values;
private readonly Dictionary _modules;
- public ModuleService(/*ModuleServiceConfig config*/)
+ public ModuleService()
{
- //Config = config;
_modules = new Dictionary();
}
void IService.Install(DiscordClient client)
{
- _client = client;
+ Client = client;
}
public void Install(T module, string name, FilterType type)
@@ -27,10 +25,12 @@ namespace Discord.Modules
{
if (module == null) throw new ArgumentNullException(nameof(module));
if (name == null) throw new ArgumentNullException(nameof(name));
- if (_client == null) throw new InvalidOperationException("Service needs to be added to a DiscordClient before modules can be installed.");
- if (_modules.ContainsKey(module)) throw new InvalidOperationException("This module has already been added.");
+ if (Client == null)
+ throw new InvalidOperationException("Service needs to be added to a DiscordClient before modules can be installed.");
+ if (_modules.ContainsKey(module))
+ throw new InvalidOperationException("This module has already been added.");
- var manager = new ModuleManager(_client, name, type);
+ var manager = new ModuleManager(Client, name, type);
_modules.Add(module, manager);
module.Install(manager);
}
diff --git a/src/Discord.Net.Net45/Discord.Net.csproj b/src/Discord.Net.Net45/Discord.Net.csproj
index 57682d40e..076f0be13 100644
--- a/src/Discord.Net.Net45/Discord.Net.csproj
+++ b/src/Discord.Net.Net45/Discord.Net.csproj
@@ -391,15 +391,24 @@
API\Status\Rest\Upcoming.cs
+
+ ChannelEventArgs.cs
+
+
+ ChannelUserEventArgs.cs
+
+
+ Config.cs
+
+
+ DisconnectedEventArgs.cs
+
DiscordClient.cs
DiscordClient.Events.cs
-
- DiscordClient.Obsolete.cs
-
DiscordConfig.cs
@@ -421,33 +430,6 @@
Enums\UserStatus.cs
-
- Events\ChannelEventArgs.cs
-
-
- Events\ChannelUserEventArgs.cs
-
-
- Events\DisconnectedEventArgs.cs
-
-
- Events\LogMessageEventArgs.cs
-
-
- Events\MessageEventArgs.cs
-
-
- Events\ProfileEventArgs.cs
-
-
- Events\RoleEventArgs.cs
-
-
- Events\ServerEventArgs.cs
-
-
- Events\UserEventArgs.cs
-
Extensions.cs
@@ -457,12 +439,21 @@
IService.cs
+
+ Legacy.cs
+
Logging\Logger.cs
Logging\LogManager.cs
+
+ LogMessageEventArgs.cs
+
+
+ MessageEventArgs.cs
+
MessageQueue.cs
@@ -502,6 +493,9 @@
Net\Rest\IRestEngine.cs
+
+ Net\Rest\RequestEventArgs.cs
+
Net\Rest\RestClient.cs
@@ -514,6 +508,9 @@
Net\WebSockets\WebSocketException.cs
+
+ Net\WebSockets\BinaryMessageEventArgs.cs
+
Net\WebSockets\BuiltInEngine.cs
@@ -523,30 +520,39 @@
Net\WebSockets\IWebSocketEngine.cs
-
- Net\WebSockets\WebSocket.BuiltIn.cs
+
+ Net\WebSockets\TextMessageEventArgs.cs
Net\WebSockets\WebSocket.cs
-
- Net\WebSockets\WebSocketSharpEngine.cs
+
+ Net\WebSockets\WebSocketEventEventArgs.cs
Net\WebSockets\WS4NetEngine.cs
-
- Reference.cs
+
+ ProfileEventArgs.cs
RelativeDirection.cs
+
+ RoleEventArgs.cs
+
+
+ ServerEventArgs.cs
+
ServiceManager.cs
TaskManager.cs
+
+ UserEventArgs.cs
+
diff --git a/src/Discord.Net/API/Client/GatewaySocket/Commands/Identify.cs b/src/Discord.Net/API/Client/GatewaySocket/Commands/Identify.cs
index 7b6c44902..76a3a3e6f 100644
--- a/src/Discord.Net/API/Client/GatewaySocket/Commands/Identify.cs
+++ b/src/Discord.Net/API/Client/GatewaySocket/Commands/Identify.cs
@@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace Discord.API.Client.GatewaySocket
{
[JsonObject(MemberSerialization.OptIn)]
- internal sealed class IdentifyCommand : IWebSocketMessage
+ public sealed class IdentifyCommand : IWebSocketMessage
{
int IWebSocketMessage.OpCode => (int)OpCodes.Identify;
object IWebSocketMessage.Payload => this;
diff --git a/src/Discord.Net/API/Client/GatewaySocket/Commands/RequestMembers.cs b/src/Discord.Net/API/Client/GatewaySocket/Commands/RequestMembers.cs
index de230afe2..2a2799c12 100644
--- a/src/Discord.Net/API/Client/GatewaySocket/Commands/RequestMembers.cs
+++ b/src/Discord.Net/API/Client/GatewaySocket/Commands/RequestMembers.cs
@@ -4,7 +4,7 @@ using Newtonsoft.Json;
namespace Discord.API.Client.GatewaySocket
{
[JsonObject(MemberSerialization.OptIn)]
- internal sealed class RequestMembersCommand : IWebSocketMessage
+ public sealed class RequestMembersCommand : IWebSocketMessage
{
int IWebSocketMessage.OpCode => (int)OpCodes.RequestGuildMembers;
object IWebSocketMessage.Payload => this;
diff --git a/src/Discord.Net/API/Client/GatewaySocket/Events/GuildBanAdd.cs b/src/Discord.Net/API/Client/GatewaySocket/Events/GuildBanAdd.cs
index f3829ae70..823e3506a 100644
--- a/src/Discord.Net/API/Client/GatewaySocket/Events/GuildBanAdd.cs
+++ b/src/Discord.Net/API/Client/GatewaySocket/Events/GuildBanAdd.cs
@@ -1,9 +1,4 @@
-using Discord.API.Converters;
-using Newtonsoft.Json;
-
-namespace Discord.API.Client.GatewaySocket
+namespace Discord.API.Client.GatewaySocket
{
- public sealed class GuildBanAddEvent : MemberReference
- {
- }
+ public sealed class GuildBanAddEvent : MemberReference { }
}
diff --git a/src/Discord.Net/API/Client/GatewaySocket/Events/GuildBanRemove.cs b/src/Discord.Net/API/Client/GatewaySocket/Events/GuildBanRemove.cs
index 00f3d2de3..a977b8702 100644
--- a/src/Discord.Net/API/Client/GatewaySocket/Events/GuildBanRemove.cs
+++ b/src/Discord.Net/API/Client/GatewaySocket/Events/GuildBanRemove.cs
@@ -1,9 +1,4 @@
-using Discord.API.Converters;
-using Newtonsoft.Json;
-
-namespace Discord.API.Client.GatewaySocket
+namespace Discord.API.Client.GatewaySocket
{
- public sealed class GuildBanRemoveEvent : MemberReference
- {
- }
+ public sealed class GuildBanRemoveEvent : MemberReference { }
}
diff --git a/src/Discord.Net/API/Client/GatewaySocket/Events/GuildEmojisUpdate.cs b/src/Discord.Net/API/Client/GatewaySocket/Events/GuildEmojisUpdate.cs
index f1c2f3884..8d2400a7b 100644
--- a/src/Discord.Net/API/Client/GatewaySocket/Events/GuildEmojisUpdate.cs
+++ b/src/Discord.Net/API/Client/GatewaySocket/Events/GuildEmojisUpdate.cs
@@ -1,4 +1,4 @@
namespace Discord.API.Client.GatewaySocket.Events
{
- //public sealed class GuildEmojisUpdate { }
+ //public sealed class GuildEmojisUpdateEvent { }
}
diff --git a/src/Discord.Net/API/Client/GatewaySocket/Events/GuildMembersChunk.cs b/src/Discord.Net/API/Client/GatewaySocket/Events/GuildMembersChunk.cs
index 6f790825a..1cb256c79 100644
--- a/src/Discord.Net/API/Client/GatewaySocket/Events/GuildMembersChunk.cs
+++ b/src/Discord.Net/API/Client/GatewaySocket/Events/GuildMembersChunk.cs
@@ -8,6 +8,6 @@ namespace Discord.API.Client.GatewaySocket
[JsonProperty("guild_id"), JsonConverter(typeof(LongStringConverter))]
public ulong GuildId { get; set; }
[JsonProperty("members")]
- public Member[] Members;
+ public Member[] Members { get; set; }
}
}
diff --git a/src/Discord.Net/API/Client/IWebSocketMessage.cs b/src/Discord.Net/API/Client/IWebSocketMessage.cs
index 6f6de535a..715110e51 100644
--- a/src/Discord.Net/API/Client/IWebSocketMessage.cs
+++ b/src/Discord.Net/API/Client/IWebSocketMessage.cs
@@ -8,7 +8,7 @@ namespace Discord.API.Client
object Payload { get; }
bool IsPrivate { get; }
}
- public class WebSocketMessage
+ public sealed class WebSocketMessage
{
[JsonProperty("op")]
public int? Operation { get; set; }
diff --git a/src/Discord.Net/API/Converters.cs b/src/Discord.Net/API/Converters.cs
index 91ea53575..1142e5755 100644
--- a/src/Discord.Net/API/Converters.cs
+++ b/src/Discord.Net/API/Converters.cs
@@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace Discord.API.Converters
{
- public class LongStringConverter : JsonConverter
+ public sealed class LongStringConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
=> objectType == typeof(ulong);
@@ -14,7 +14,7 @@ namespace Discord.API.Converters
=> writer.WriteValue(((ulong)value).ToIdString());
}
- public class NullableLongStringConverter : JsonConverter
+ public sealed class NullableLongStringConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
=> objectType == typeof(ulong?);
@@ -24,7 +24,7 @@ namespace Discord.API.Converters
=> writer.WriteValue(((ulong?)value).ToIdString());
}
- /*public class LongStringEnumerableConverter : JsonConverter
+ /*public sealed class LongStringEnumerableConverter : JsonConverter
{
public override bool CanConvert(Type objectType) => objectType == typeof(IEnumerable);
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
@@ -55,7 +55,7 @@ namespace Discord.API.Converters
}
}*/
- internal class LongStringArrayConverter : JsonConverter
+ internal sealed class LongStringArrayConverter : JsonConverter
{
public override bool CanConvert(Type objectType) => objectType == typeof(IEnumerable);
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
diff --git a/src/Discord.Net/Events/ChannelEventArgs.cs b/src/Discord.Net/ChannelEventArgs.cs
similarity index 99%
rename from src/Discord.Net/Events/ChannelEventArgs.cs
rename to src/Discord.Net/ChannelEventArgs.cs
index 4f1ca23a6..4aecf34f1 100644
--- a/src/Discord.Net/Events/ChannelEventArgs.cs
+++ b/src/Discord.Net/ChannelEventArgs.cs
@@ -5,6 +5,7 @@ namespace Discord
public class ChannelEventArgs : EventArgs
{
public Channel Channel { get; }
+
public Server Server => Channel.Server;
public ChannelEventArgs(Channel channel) { Channel = channel; }
diff --git a/src/Discord.Net/Events/ChannelUserEventArgs.cs b/src/Discord.Net/ChannelUserEventArgs.cs
similarity index 100%
rename from src/Discord.Net/Events/ChannelUserEventArgs.cs
rename to src/Discord.Net/ChannelUserEventArgs.cs
diff --git a/src/Discord.Net/Config.cs b/src/Discord.Net/Config.cs
new file mode 100644
index 000000000..af7da9529
--- /dev/null
+++ b/src/Discord.Net/Config.cs
@@ -0,0 +1,24 @@
+using System;
+
+namespace Discord
+{
+ public abstract class Config
+ where T : Config
+ {
+ protected bool _isLocked;
+ protected internal void Lock() { _isLocked = true; }
+ protected void SetValue(ref U storage, U value)
+ {
+ if (_isLocked)
+ throw new InvalidOperationException("Unable to modify a discord client's configuration after it has been created.");
+ storage = value;
+ }
+
+ public T Clone()
+ {
+ var config = MemberwiseClone() as T;
+ config._isLocked = false;
+ return config;
+ }
+ }
+}
diff --git a/src/Discord.Net/Events/DisconnectedEventArgs.cs b/src/Discord.Net/DisconnectedEventArgs.cs
similarity index 100%
rename from src/Discord.Net/Events/DisconnectedEventArgs.cs
rename to src/Discord.Net/DisconnectedEventArgs.cs
diff --git a/src/Discord.Net/DiscordConfig.cs b/src/Discord.Net/DiscordConfig.cs
index d5210915a..b809ec8e2 100644
--- a/src/Discord.Net/DiscordConfig.cs
+++ b/src/Discord.Net/DiscordConfig.cs
@@ -13,26 +13,6 @@ namespace Discord
Verbose = 4,
Debug = 5
}
-
- public abstract class Config
- where T : Config
- {
- protected bool _isLocked;
- protected internal void Lock() { _isLocked = true; }
- protected void SetValue(ref U storage, U value)
- {
- if (_isLocked)
- throw new InvalidOperationException("Unable to modify a discord client's configuration after it has been created.");
- storage = value;
- }
-
- public T Clone()
- {
- var config = MemberwiseClone() as T;
- config._isLocked = false;
- return config;
- }
- }
public class DiscordConfig : Config
{
diff --git a/src/Discord.Net/Enums/ChannelType.cs b/src/Discord.Net/Enums/ChannelType.cs
index 59c439a8e..f3c19ad38 100644
--- a/src/Discord.Net/Enums/ChannelType.cs
+++ b/src/Discord.Net/Enums/ChannelType.cs
@@ -1,6 +1,6 @@
namespace Discord
{
- public class ChannelType : StringEnum
+ public sealed class ChannelType : StringEnum
{
/// A text-only channel.
public static ChannelType Text { get; } = new ChannelType("text");
diff --git a/src/Discord.Net/Enums/PermissionTarget.cs b/src/Discord.Net/Enums/PermissionTarget.cs
index 65c81bbc4..bb4a10211 100644
--- a/src/Discord.Net/Enums/PermissionTarget.cs
+++ b/src/Discord.Net/Enums/PermissionTarget.cs
@@ -1,6 +1,6 @@
namespace Discord
{
- public class PermissionTarget : StringEnum
+ public sealed class PermissionTarget : StringEnum
{
/// A text-only channel.
public static PermissionTarget Role { get; } = new PermissionTarget("role");
diff --git a/src/Discord.Net/Enums/UserStatus.cs b/src/Discord.Net/Enums/UserStatus.cs
index b2da3c8f5..709fe4eab 100644
--- a/src/Discord.Net/Enums/UserStatus.cs
+++ b/src/Discord.Net/Enums/UserStatus.cs
@@ -1,6 +1,6 @@
namespace Discord
{
- public class UserStatus : StringEnum
+ public sealed class UserStatus : StringEnum
{
/// User is currently online and active.
public static UserStatus Online { get; } = new UserStatus("online");
diff --git a/src/Discord.Net/DiscordClient.Obsolete.cs b/src/Discord.Net/Legacy.cs
similarity index 98%
rename from src/Discord.Net/DiscordClient.Obsolete.cs
rename to src/Discord.Net/Legacy.cs
index 083ef7837..34a348619 100644
--- a/src/Discord.Net/DiscordClient.Obsolete.cs
+++ b/src/Discord.Net/Legacy.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
-namespace Discord.Legacy
+namespace Discord
{
public static class Mention
{
@@ -31,19 +31,19 @@ namespace Discord.Legacy
if (server == null) throw new ArgumentNullException(nameof(server));
return server.FindChannels(name, type, exactMatch);
}
-
+
[Obsolete("Use Server.CreateChannel")]
public static Task CreateChannel(this DiscordClient client, Server server, string name, ChannelType type)
{
if (server == null) throw new ArgumentNullException(nameof(server));
return server.CreateChannel(name, type);
- }
+ }
[Obsolete("Use User.CreateChannel")]
public static Task CreatePMChannel(this DiscordClient client, User user)
{
if (user == null) throw new ArgumentNullException(nameof(user));
return user.CreatePMChannel();
- }
+ }
[Obsolete("Use Channel.Edit")]
public static Task EditChannel(this DiscordClient client, Channel channel, string name = null, string topic = null, int? position = null)
{
@@ -62,15 +62,15 @@ namespace Discord.Legacy
{
if (server == null) throw new ArgumentNullException(nameof(server));
return server.ReorderChannels(channels, after);
- }
-
+ }
+
[Obsolete("Use Server.GetInvites")]
public static Task> GetInvites(this DiscordClient client, Server server)
{
if (server == null) throw new ArgumentNullException(nameof(server));
return server.GetInvites();
}
-
+
[Obsolete("Use Server.CreateInvite")]
public static Task CreateInvite(this DiscordClient client, Server server, int? maxAge = 1800, int? maxUses = null, bool tempMembership = false, bool withXkcd = false)
{
@@ -83,20 +83,20 @@ namespace Discord.Legacy
if (channel == null) throw new ArgumentNullException(nameof(channel));
return channel.CreateInvite(maxAge, maxUses, tempMembership, withXkcd);
}
-
+
[Obsolete("Use Invite.Delete")]
public static Task DeleteInvite(this DiscordClient client, Invite invite)
{
if (invite == null) throw new ArgumentNullException(nameof(invite));
return invite.Delete();
- }
+ }
[Obsolete("Use Invite.Accept")]
public static Task AcceptInvite(this DiscordClient client, Invite invite)
{
if (invite == null) throw new ArgumentNullException(nameof(invite));
return invite.Accept();
}
-
+
[Obsolete("Use Channel.SendMessage")]
public static Task SendMessage(this DiscordClient client, Channel channel, string text)
{
@@ -139,14 +139,14 @@ namespace Discord.Legacy
if (user == null) throw new ArgumentNullException(nameof(user));
return user.SendFile(filename, stream);
}
-
+
[Obsolete("Use Message.Edit")]
public static Task EditMessage(this DiscordClient client, Message message, string text)
{
if (message == null) throw new ArgumentNullException(nameof(message));
return message.Edit(text);
}
-
+
[Obsolete("Use Message.Delete")]
public static Task DeleteMessage(this DiscordClient client, Message message)
{
@@ -161,14 +161,14 @@ namespace Discord.Legacy
foreach (var message in messages)
await message.Delete().ConfigureAwait(false);
}
-
+
[Obsolete("Use Channel.DownloadMessages")]
public static Task DownloadMessages(this DiscordClient client, Channel channel, int limit = 100, ulong? relativeMessageId = null, RelativeDirection relativeDir = RelativeDirection.Before, bool useCache = true)
{
if (channel == null) throw new ArgumentNullException(nameof(channel));
return channel.DownloadMessages(limit, relativeMessageId, relativeDir, useCache);
}
-
+
[Obsolete("Use Message.Acknowledge")]
public static Task AckMessage(this DiscordClient client, Message message)
{
@@ -212,7 +212,7 @@ namespace Discord.Legacy
return JsonConvert.SerializeObject(channel.Messages);
}*/
-
+
[Obsolete("Use Server.GetUser")]
public static User GetUser(this DiscordClient client, Server server, ulong userId)
{
@@ -225,7 +225,7 @@ namespace Discord.Legacy
if (server == null) throw new ArgumentNullException(nameof(server));
return server.GetUser(username, discriminator);
}
-
+
[Obsolete("Use Server.FindUsers")]
public static IEnumerable FindUsers(this DiscordClient client, Server server, string name, bool exactMatch = false)
{
@@ -287,20 +287,20 @@ namespace Discord.Legacy
string username = null, string email = null, string password = null,
Stream avatar = null, ImageType avatarType = ImageType.Png)
=> client.CurrentUser.Edit(currentPassword, username, email, password, avatar, avatarType);
-
+
[Obsolete("Use Server.GetRole")]
public static Role GetRole(this DiscordClient client, Server server, ulong id)
{
if (server == null) throw new ArgumentNullException(nameof(server));
return server.GetRole(id);
- }
+ }
[Obsolete("Use Server.FindRoles")]
public static IEnumerable FindRoles(this DiscordClient client, Server server, string name)
{
if (server == null) throw new ArgumentNullException(nameof(server));
return server.FindRoles(name);
}
-
+
[Obsolete("Use Server.CreateRole")]
public static Task CreateRole(this DiscordClient client, Server server, string name, ServerPermissions permissions = null, Color color = null, bool isHoisted = false)
{
@@ -320,21 +320,21 @@ namespace Discord.Legacy
if (role == null) throw new ArgumentNullException(nameof(role));
return role.Delete();
}
-
+
[Obsolete("Use Server.ReorderRoles")]
public static Task ReorderRoles(this DiscordClient client, Server server, IEnumerable roles, Role after = null)
{
if (server == null) throw new ArgumentNullException(nameof(server));
return server.ReorderRoles(roles, after);
}
-
+
[Obsolete("Use Server.Edit")]
public static Task EditServer(this DiscordClient client, Server server, string name = null, string region = null, Stream icon = null, ImageType iconType = ImageType.Png)
{
if (server == null) throw new ArgumentNullException(nameof(server));
return server.Edit(name, region, icon, iconType);
}
-
+
[Obsolete("Use Server.Leave")]
public static Task LeaveServer(this DiscordClient client, Server server)
{
diff --git a/src/Discord.Net/Events/LogMessageEventArgs.cs b/src/Discord.Net/LogMessageEventArgs.cs
similarity index 89%
rename from src/Discord.Net/Events/LogMessageEventArgs.cs
rename to src/Discord.Net/LogMessageEventArgs.cs
index 2aca5af34..bd1fa5b93 100644
--- a/src/Discord.Net/Events/LogMessageEventArgs.cs
+++ b/src/Discord.Net/LogMessageEventArgs.cs
@@ -2,7 +2,7 @@
namespace Discord
{
- public sealed class LogMessageEventArgs : EventArgs
+ public class LogMessageEventArgs : EventArgs
{
public LogSeverity Severity { get; }
public string Source { get; }
diff --git a/src/Discord.Net/Logging/LogManager.cs b/src/Discord.Net/Logging/LogManager.cs
index 576ec7679..f52031df9 100644
--- a/src/Discord.Net/Logging/LogManager.cs
+++ b/src/Discord.Net/Logging/LogManager.cs
@@ -2,7 +2,7 @@
namespace Discord.Logging
{
- public class LogManager
+ public sealed class LogManager
{
private readonly DiscordClient _client;
diff --git a/src/Discord.Net/Logging/Logger.cs b/src/Discord.Net/Logging/Logger.cs
index 9d7a6111b..6c1cc1a4b 100644
--- a/src/Discord.Net/Logging/Logger.cs
+++ b/src/Discord.Net/Logging/Logger.cs
@@ -2,7 +2,7 @@
namespace Discord.Logging
{
- public class Logger
+ public sealed class Logger
{
private readonly LogManager _manager;
diff --git a/src/Discord.Net/Events/MessageEventArgs.cs b/src/Discord.Net/MessageEventArgs.cs
similarity index 99%
rename from src/Discord.Net/Events/MessageEventArgs.cs
rename to src/Discord.Net/MessageEventArgs.cs
index b4f94d30a..7edb23347 100644
--- a/src/Discord.Net/Events/MessageEventArgs.cs
+++ b/src/Discord.Net/MessageEventArgs.cs
@@ -5,6 +5,7 @@ namespace Discord
public class MessageEventArgs : EventArgs
{
public Message Message { get; }
+
public User User => Message.User;
public Channel Channel => Message.Channel;
public Server Server => Message.Server;
diff --git a/src/Discord.Net/MessageQueue.cs b/src/Discord.Net/MessageQueue.cs
index fdb80c791..bb6872673 100644
--- a/src/Discord.Net/MessageQueue.cs
+++ b/src/Discord.Net/MessageQueue.cs
@@ -9,9 +9,9 @@ using System.Threading.Tasks;
namespace Discord.Net
{
/// Manages an outgoing message queue for DiscordClient.
- public class MessageQueue
+ public sealed class MessageQueue
{
- private class MessageQueueItem
+ private struct MessageQueueItem
{
public readonly ulong Id, ChannelId;
public readonly string Text;
diff --git a/src/Discord.Net/Models/Color.cs b/src/Discord.Net/Models/Color.cs
index faea44507..c19f6ef71 100644
--- a/src/Discord.Net/Models/Color.cs
+++ b/src/Discord.Net/Models/Color.cs
@@ -2,7 +2,7 @@
namespace Discord
{
- public class Color
+ public sealed class Color
{
public static readonly Color Default = PresetColor(0);
@@ -65,8 +65,8 @@ namespace Discord
//Bypasses isLocked for API changes.
_rawValue = rawValue;
}
- protected byte GetByte(int pos) => (byte)((_rawValue >> (8 * (pos - 1))) & 0xFF);
- protected void SetByte(int pos, byte value)
+ private byte GetByte(int pos) => (byte)((_rawValue >> (8 * (pos - 1))) & 0xFF);
+ private void SetByte(int pos, byte value)
{
if (_isLocked)
throw new InvalidOperationException("Unable to edit cached colors directly, use Copy() to make an editable copy.");
diff --git a/src/Discord.Net/Models/User.cs b/src/Discord.Net/Models/User.cs
index 54b186117..4b05eaceb 100644
--- a/src/Discord.Net/Models/User.cs
+++ b/src/Discord.Net/Models/User.cs
@@ -9,7 +9,7 @@ using APIMember = Discord.API.Client.Member;
namespace Discord
{
- public class User
+ public sealed class User
{
internal static string GetAvatarUrl(ulong userId, string avatarId)
=> avatarId != null ? $"{DiscordConfig.CDNUrl}avatars/{userId}/{avatarId}.jpg" : null;
diff --git a/src/Discord.Net/Net/HttpException.cs b/src/Discord.Net/Net/HttpException.cs
index 8bfdbf73b..afb17bcaf 100644
--- a/src/Discord.Net/Net/HttpException.cs
+++ b/src/Discord.Net/Net/HttpException.cs
@@ -7,7 +7,7 @@ namespace Discord.Net
#if NET46
[Serializable]
#endif
- public class HttpException : Exception
+ public sealed class HttpException : Exception
{
public HttpStatusCode StatusCode { get; }
diff --git a/src/Discord.Net/Net/Rest/RequestEventArgs.cs b/src/Discord.Net/Net/Rest/RequestEventArgs.cs
new file mode 100644
index 000000000..0741c88db
--- /dev/null
+++ b/src/Discord.Net/Net/Rest/RequestEventArgs.cs
@@ -0,0 +1,20 @@
+using System;
+
+namespace Discord.Net.Rest
+{
+ public class RequestEventArgs : EventArgs
+ {
+ public string Method { get; }
+ public string Path { get; }
+ public string Payload { get; }
+ public double ElapsedMilliseconds { get; }
+
+ public RequestEventArgs(string method, string path, string payload, double milliseconds)
+ {
+ Method = method;
+ Path = path;
+ Payload = payload;
+ ElapsedMilliseconds = milliseconds;
+ }
+ }
+}
diff --git a/src/Discord.Net/Net/Rest/RestClient.cs b/src/Discord.Net/Net/Rest/RestClient.cs
index e5fe1e82c..a5cac77ac 100644
--- a/src/Discord.Net/Net/Rest/RestClient.cs
+++ b/src/Discord.Net/Net/Rest/RestClient.cs
@@ -8,21 +8,6 @@ using System.Threading.Tasks;
namespace Discord.Net.Rest
{
- public class RequestEventArgs : EventArgs
- {
- public string Method { get; }
- public string Path { get; }
- public string Payload { get; }
- public double ElapsedMilliseconds { get; }
- public RequestEventArgs(string method, string path, string payload, double milliseconds)
- {
- Method = method;
- Path = path;
- Payload = payload;
- ElapsedMilliseconds = milliseconds;
- }
- }
-
public sealed partial class RestClient
{
private readonly DiscordConfig _config;
diff --git a/src/Discord.Net/Net/WebSocketException.cs b/src/Discord.Net/Net/WebSocketException.cs
index b845d90c4..d2c61b644 100644
--- a/src/Discord.Net/Net/WebSocketException.cs
+++ b/src/Discord.Net/Net/WebSocketException.cs
@@ -2,7 +2,7 @@
namespace Discord.Net
{
- public class WebSocketException : Exception
+ public sealed class WebSocketException : Exception
{
public int Code { get; }
public string Reason { get; }
diff --git a/src/Discord.Net/Net/WebSockets/BinaryMessageEventArgs.cs b/src/Discord.Net/Net/WebSockets/BinaryMessageEventArgs.cs
new file mode 100644
index 000000000..7c6f633e9
--- /dev/null
+++ b/src/Discord.Net/Net/WebSockets/BinaryMessageEventArgs.cs
@@ -0,0 +1,11 @@
+using System;
+
+namespace Discord.Net.WebSockets
+{
+ public class BinaryMessageEventArgs : EventArgs
+ {
+ public byte[] Data { get; }
+
+ public BinaryMessageEventArgs(byte[] data) { Data = data; }
+ }
+}
diff --git a/src/Discord.Net/Net/WebSockets/BuiltInEngine.cs b/src/Discord.Net/Net/WebSockets/BuiltInEngine.cs
index ff2cba729..7c454715d 100644
--- a/src/Discord.Net/Net/WebSockets/BuiltInEngine.cs
+++ b/src/Discord.Net/Net/WebSockets/BuiltInEngine.cs
@@ -12,7 +12,7 @@ using WebSocketClient = System.Net.WebSockets.ClientWebSocket;
namespace Discord.Net.WebSockets
{
- internal class BuiltInEngine : IWebSocketEngine
+ internal sealed class BuiltInEngine : IWebSocketEngine
{
private const int ReceiveChunkSize = 12 * 1024; //12KB
private const int SendChunkSize = 4 * 1024; //4KB
@@ -23,12 +23,12 @@ namespace Discord.Net.WebSockets
private WebSocketClient _webSocket;
private Task _tempTask;
- public event EventHandler BinaryMessage = delegate { };
- public event EventHandler TextMessage = delegate { };
+ public event EventHandler BinaryMessage = delegate { };
+ public event EventHandler TextMessage = delegate { };
private void OnBinaryMessage(byte[] data)
- => BinaryMessage(this, new WebSocketBinaryMessageEventArgs(data));
+ => BinaryMessage(this, new BinaryMessageEventArgs(data));
private void OnTextMessage(string msg)
- => TextMessage(this, new WebSocketTextMessageEventArgs(msg));
+ => TextMessage(this, new TextMessageEventArgs(msg));
internal BuiltInEngine(DiscordConfig config)
{
diff --git a/src/Discord.Net/Net/WebSockets/GatewaySocket.cs b/src/Discord.Net/Net/WebSockets/GatewaySocket.cs
index 0250ed271..b5c6d18e4 100644
--- a/src/Discord.Net/Net/WebSockets/GatewaySocket.cs
+++ b/src/Discord.Net/Net/WebSockets/GatewaySocket.cs
@@ -10,18 +10,7 @@ using System.Threading.Tasks;
namespace Discord.Net.WebSockets
{
- public sealed class WebSocketEventEventArgs : EventArgs
- {
- public readonly string Type;
- public readonly JToken Payload;
- internal WebSocketEventEventArgs(string type, JToken data)
- {
- Type = type;
- Payload = data;
- }
- }
-
- public partial class GatewaySocket : WebSocket
+ public sealed class GatewaySocket : WebSocket
{
private uint _lastSequence;
private string _sessionId;
diff --git a/src/Discord.Net/Net/WebSockets/IWebSocketEngine.cs b/src/Discord.Net/Net/WebSockets/IWebSocketEngine.cs
index 61e33464a..68f31f12b 100644
--- a/src/Discord.Net/Net/WebSockets/IWebSocketEngine.cs
+++ b/src/Discord.Net/Net/WebSockets/IWebSocketEngine.cs
@@ -5,21 +5,10 @@ using System.Threading.Tasks;
namespace Discord.Net.WebSockets
{
- public class WebSocketBinaryMessageEventArgs : EventArgs
- {
- public readonly byte[] Data;
- public WebSocketBinaryMessageEventArgs(byte[] data) { Data = data; }
- }
- public class WebSocketTextMessageEventArgs : EventArgs
- {
- public readonly string Message;
- public WebSocketTextMessageEventArgs(string msg) { Message = msg; }
- }
-
public interface IWebSocketEngine
{
- event EventHandler BinaryMessage;
- event EventHandler TextMessage;
+ event EventHandler BinaryMessage;
+ event EventHandler TextMessage;
Task Connect(string host, CancellationToken cancelToken);
Task Disconnect();
diff --git a/src/Discord.Net/Net/WebSockets/TextMessageEventArgs.cs b/src/Discord.Net/Net/WebSockets/TextMessageEventArgs.cs
new file mode 100644
index 000000000..e4e186044
--- /dev/null
+++ b/src/Discord.Net/Net/WebSockets/TextMessageEventArgs.cs
@@ -0,0 +1,11 @@
+using System;
+
+namespace Discord.Net.WebSockets
+{
+ public class TextMessageEventArgs : EventArgs
+ {
+ public string Message { get; }
+
+ public TextMessageEventArgs(string msg) { Message = msg; }
+ }
+}
diff --git a/src/Discord.Net/Net/WebSockets/WS4NetEngine.cs b/src/Discord.Net/Net/WebSockets/WS4NetEngine.cs
index 4c1813501..cbbd1c35f 100644
--- a/src/Discord.Net/Net/WebSockets/WS4NetEngine.cs
+++ b/src/Discord.Net/Net/WebSockets/WS4NetEngine.cs
@@ -10,7 +10,7 @@ using WebSocketClient = WebSocket4Net.WebSocket;
namespace Discord.Net.WebSockets
{
- internal class WS4NetEngine : IWebSocketEngine
+ internal sealed class WS4NetEngine : IWebSocketEngine
{
private readonly DiscordConfig _config;
private readonly ConcurrentQueue _sendQueue;
@@ -18,12 +18,12 @@ namespace Discord.Net.WebSockets
private WebSocketClient _webSocket;
private ManualResetEventSlim _waitUntilConnect, _waitUntilDisconnect;
- public event EventHandler BinaryMessage = delegate { };
- public event EventHandler TextMessage = delegate { };
+ public event EventHandler BinaryMessage = delegate { };
+ public event EventHandler TextMessage = delegate { };
private void OnBinaryMessage(byte[] data)
- => BinaryMessage(this, new WebSocketBinaryMessageEventArgs(data));
+ => BinaryMessage(this, new BinaryMessageEventArgs(data));
private void OnTextMessage(string msg)
- => TextMessage(this, new WebSocketTextMessageEventArgs(msg));
+ => TextMessage(this, new TextMessageEventArgs(msg));
internal WS4NetEngine(DiscordConfig config, TaskManager taskManager)
{
diff --git a/src/Discord.Net/Net/WebSockets/WebSocket.BuiltIn.cs b/src/Discord.Net/Net/WebSockets/WebSocket.BuiltIn.cs
deleted file mode 100644
index 6062265ae..000000000
--- a/src/Discord.Net/Net/WebSockets/WebSocket.BuiltIn.cs
+++ /dev/null
@@ -1,152 +0,0 @@
-#if DOTNET5_4
-/*using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Net.WebSockets;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using State = System.Net.WebSockets.WebSocketState;
-
-namespace Discord.Net.WebSockets
-{
- internal class BuiltInWebSocketEngine : IWebSocketEngine
- {
- private const int ReceiveChunkSize = 4096;
- private const int SendChunkSize = 4096;
- private const int HR_TIMEOUT = -2147012894;
-
- private readonly ConcurrentQueue _sendQueue;
- private readonly int _sendInterval;
- private ClientWebSocket _webSocket;
-
- public event EventHandler ProcessMessage;
- private void RaiseProcessMessage(string msg)
- {
- if (ProcessMessage != null)
- ProcessMessage(this, new WebSocketMessageEventArgs(msg));
- }
-
- public BuiltInWebSocketEngine(int sendInterval)
- {
- _sendInterval = sendInterval;
- _sendQueue = new ConcurrentQueue();
- }
-
- public Task Connect(string host, CancellationToken cancelToken)
- {
- _webSocket = new ClientWebSocket();
- return _webSocket.ConnectAsync(new Uri(host), cancelToken);
- }
-
- public Task Disconnect()
- {
- string ignored;
- while (_sendQueue.TryDequeue(out ignored)) { }
- _webSocket.Dispose();
- _webSocket = new ClientWebSocket();
- return TaskHelper.CompletedTask;
- }
-
- public IEnumerable GetTasks(CancellationToken cancelToken)
- {
- return new Task[]
- {
- ReceiveAsync(cancelToken),
- SendAsync(cancelToken)
- };
- }
-
- private Task ReceiveAsync(CancellationToken cancelToken)
- {
- return Task.Run(async () =>
- {
- var buffer = new ArraySegment(new byte[ReceiveChunkSize]);
- var builder = new StringBuilder();
-
- try
- {
- while (_webSocket.State == State.Open && !cancelToken.IsCancellationRequested)
- {
- WebSocketReceiveResult result = null;
- do
- {
- if (_webSocket.State != State.Open || cancelToken.IsCancellationRequested)
- return;
-
- try
- {
- result = await _webSocket.ReceiveAsync(buffer, cancelToken).ConfigureAwait(false);
- }
- catch (Win32Exception ex) when (ex.HResult == HR_TIMEOUT)
- {
- throw new Exception($"Connection timed out.");
- }
-
- if (result.MessageType == WebSocketMessageType.Close)
- throw new Exception($"Got Close Message ({result.CloseStatus?.ToString() ?? "Unexpected"}): " +
- result.CloseStatusDescription != "" ? result.CloseStatusDescription : "No Reason");
- else
- builder.Append(Encoding.UTF8.GetString(buffer.Array, buffer.Offset, result.Count));
-
- }
- while (result == null || !result.EndOfMessage);
-
- RaiseProcessMessage(builder.ToString());
-
- builder.Clear();
- }
- }
- catch (OperationCanceledException) { }
- });
- }
- private Task SendAsync(CancellationToken cancelToken)
- {
- return Task.Run(async () =>
- {
- try
- {
- while (_webSocket.State == State.Open && !cancelToken.IsCancellationRequested)
- {
- string json;
- while (_sendQueue.TryDequeue(out json))
- {
- byte[] bytes = Encoding.UTF8.GetBytes(json);
- int frameCount = (int)Math.Ceiling((double)bytes.Length / SendChunkSize);
-
- int offset = 0;
- for (var i = 0; i < frameCount; i++, offset += SendChunkSize)
- {
- bool isLast = i == (frameCount - 1);
-
- int count;
- if (isLast)
- count = bytes.Length - (i * SendChunkSize);
- else
- count = SendChunkSize;
-
- try
- {
- await _webSocket.SendAsync(new ArraySegment(bytes, offset, count), WebSocketMessageType.Text, isLast, cancelToken).ConfigureAwait(false);
- }
- catch (Win32Exception ex) when (ex.HResult == HR_TIMEOUT)
- {
- return;
- }
- }
- }
- await Task.Delay(_sendInterval, cancelToken).ConfigureAwait(false);
- }
- }
- catch (OperationCanceledException) { }
- });
- }
-
- public void QueueMessage(string message)
- {
- _sendQueue.Enqueue(message);
- }
- }
-}*/
-#endif
\ No newline at end of file
diff --git a/src/Discord.Net/Net/WebSockets/WebSocketEventEventArgs.cs b/src/Discord.Net/Net/WebSockets/WebSocketEventEventArgs.cs
new file mode 100644
index 000000000..a0c60edcf
--- /dev/null
+++ b/src/Discord.Net/Net/WebSockets/WebSocketEventEventArgs.cs
@@ -0,0 +1,17 @@
+using Newtonsoft.Json.Linq;
+using System;
+
+namespace Discord.Net.WebSockets
+{
+ public class WebSocketEventEventArgs : EventArgs
+ {
+ public string Type { get; }
+ public JToken Payload { get; }
+
+ internal WebSocketEventEventArgs(string type, JToken data)
+ {
+ Type = type;
+ Payload = data;
+ }
+ }
+}
diff --git a/src/Discord.Net/Net/WebSockets/WebSocketSharpEngine.cs b/src/Discord.Net/Net/WebSockets/WebSocketSharpEngine.cs
deleted file mode 100644
index 7c99c5fe3..000000000
--- a/src/Discord.Net/Net/WebSockets/WebSocketSharpEngine.cs
+++ /dev/null
@@ -1,118 +0,0 @@
-/*#if !DOTNET5_4
-using System;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-using WSSharpWebSocket = WebSocketSharp.WebSocket;
-
-namespace Discord.Net.WebSockets
-{
- internal class WebSocketSharpEngine : IWebSocketEngine
- {
- private readonly DiscordConfig _config;
- private readonly Logger _logger;
- private readonly ConcurrentQueue _sendQueue;
- private readonly WebSocket _parent;
- private WSSharpWebSocket _webSocket;
-
- public event EventHandler BinaryMessage;
- public event EventHandler TextMessage;
- private void RaiseBinaryMessage(byte[] data)
- {
- if (BinaryMessage != null)
- BinaryMessage(this, new WebSocketBinaryMessageEventArgs(data));
- }
- private void RaiseTextMessage(string msg)
- {
- if (TextMessage != null)
- TextMessage(this, new WebSocketTextMessageEventArgs(msg));
- }
-
- internal WebSocketSharpEngine(WebSocket parent, DiscordConfig config, Logger logger)
- {
- _parent = parent;
- _config = config;
- _logger = logger;
- _sendQueue = new ConcurrentQueue();
- }
-
- public Task Connect(string host, CancellationToken cancelToken)
- {
- _webSocket = new WSSharpWebSocket(host);
- _webSocket.EmitOnPing = false;
- _webSocket.EnableRedirection = true;
- //_webSocket.Compression = WebSocketSharp.CompressionMethod.Deflate;
- _webSocket.SetProxy(null, null, null); //Disable
- //_webSocket.SetProxy(_config.ProxyUrl, _config.ProxyCredentials?.UserName, _config.ProxyCredentials?.Password);
- _webSocket.OnMessage += (s, e) =>
- {
- if (e.IsBinary)
- RaiseBinaryMessage(e.RawData);
- else if (e.IsText)
- RaiseTextMessage(e.Data);
- };
- _webSocket.OnError += async (s, e) =>
- {
- _logger.Log(LogSeverity.Error, "WebSocket Error", e.Exception);
- await _parent.SignalDisconnect(e.Exception, isUnexpected: true).ConfigureAwait(false);
- };
- _webSocket.OnClose += async (s, e) =>
- {
- string code = e.WasClean ? e.Code.ToString() : "Unexpected";
- string reason = e.Reason != "" ? e.Reason : "No Reason";
- var ex = new Exception($"Got Close Message ({code}): {reason}");
- await _parent.SignalDisconnect(ex, isUnexpected: true).ConfigureAwait(false);
- };
- _webSocket.Log.Output = (e, m) => { }; //Dont let websocket-sharp print to console directly
- _webSocket.Connect();
- return TaskHelper.CompletedTask;
- }
-
- public Task Disconnect()
- {
- string ignored;
- while (_sendQueue.TryDequeue(out ignored)) { }
-
- var socket = _webSocket;
- _webSocket = null;
- if (socket != null)
- socket.Close();
-
- return TaskHelper.CompletedTask;
- }
-
- public IEnumerable GetTasks(CancellationToken cancelToken)
- {
- return new Task[]
- {
- SendAsync(cancelToken)
- };
- }
-
- private Task SendAsync(CancellationToken cancelToken)
- {
- var sendInterval = _config.WebSocketInterval;
- return Task.Run(async () =>
- {
- try
- {
- while (!cancelToken.IsCancellationRequested)
- {
- string json;
- while (_sendQueue.TryDequeue(out json))
- _webSocket.Send(json);
- await Task.Delay(sendInterval, cancelToken).ConfigureAwait(false);
- }
- }
- catch (OperationCanceledException) { }
- });
- }
-
- public void QueueMessage(string message)
- {
- _sendQueue.Enqueue(message);
- }
- }
-}
-#endif*/
\ No newline at end of file
diff --git a/src/Discord.Net/Events/ProfileEventArgs.cs b/src/Discord.Net/ProfileEventArgs.cs
similarity index 100%
rename from src/Discord.Net/Events/ProfileEventArgs.cs
rename to src/Discord.Net/ProfileEventArgs.cs
diff --git a/src/Discord.Net/Reference.cs b/src/Discord.Net/Reference.cs
deleted file mode 100644
index 4a3d6035c..000000000
--- a/src/Discord.Net/Reference.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-using System;
-
-namespace Discord
-{
- /*internal class Reference
- where T : CachedObject
- {
- private Action _onCache, _onUncache;
- private Func _getItem;
- private ulong? _id;
- public ulong? Id
- {
- get { return _id; }
- set
- {
- _id = value;
- _value = null;
- }
- }
-
- private T _value;
- public T Value
- {
- get
- {
- }
- }
-
- public T Load()
- {
- var v = _value; //A little trickery to make this threadsafe
- var id = _id;
- if (v != null && !_value.IsCached)
- {
- v = null;
- _value = null;
- }
- if (v == null && id != null)
- {
- v = _getItem(id.Value);
- if (v != null && _onCache != null)
- _onCache(v);
- _value = v;
- }
- return v;
- return Value != null; //Used for precaching
- }
-
- public void Unload()
- {
- if (_onUncache != null)
- {
- var v = _value;
- if (v != null && _onUncache != null)
- _onUncache(v);
- }
- }
-
- public Reference(Func onUpdate, Action onCache = null, Action onUncache = null)
- : this(null, onUpdate, onCache, onUncache)
- { }
- public Reference(ulong? id, Func getItem, Action onCache = null, Action onUncache = null)
- {
- _id = id;
- _getItem = getItem;
- _onCache = onCache;
- _onUncache = onUncache;
- _value = null;
- }
- }*/
-}
diff --git a/src/Discord.Net/Events/RoleEventArgs.cs b/src/Discord.Net/RoleEventArgs.cs
similarity index 99%
rename from src/Discord.Net/Events/RoleEventArgs.cs
rename to src/Discord.Net/RoleEventArgs.cs
index 60dbecad7..13eb0f7f4 100644
--- a/src/Discord.Net/Events/RoleEventArgs.cs
+++ b/src/Discord.Net/RoleEventArgs.cs
@@ -5,6 +5,7 @@ namespace Discord
public class RoleEventArgs : EventArgs
{
public Role Role { get; }
+
public Server Server => Role.Server;
public RoleEventArgs(Role role) { Role = role; }
diff --git a/src/Discord.Net/Events/ServerEventArgs.cs b/src/Discord.Net/ServerEventArgs.cs
similarity index 100%
rename from src/Discord.Net/Events/ServerEventArgs.cs
rename to src/Discord.Net/ServerEventArgs.cs
diff --git a/src/Discord.Net/ServiceManager.cs b/src/Discord.Net/ServiceManager.cs
index 0e6533b90..cb1e8e89a 100644
--- a/src/Discord.Net/ServiceManager.cs
+++ b/src/Discord.Net/ServiceManager.cs
@@ -3,7 +3,7 @@ using System.Collections.Generic;
namespace Discord
{
- public class ServiceManager
+ public sealed class ServiceManager
{
private readonly Dictionary _services;
diff --git a/src/Discord.Net/TaskManager.cs b/src/Discord.Net/TaskManager.cs
index 252259922..f49d7107d 100644
--- a/src/Discord.Net/TaskManager.cs
+++ b/src/Discord.Net/TaskManager.cs
@@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Discord
{
/// Helper class used to manage several tasks and keep them in sync. If any single task errors or stops, all other tasks will also be stopped.
- public class TaskManager
+ public sealed class TaskManager
{
private readonly object _lock;
private readonly Func _stopAction;
@@ -22,7 +22,7 @@ namespace Discord
public Exception Exception => _stopReason?.SourceException;
private ExceptionDispatchInfo _stopReason;
- public TaskManager()
+ internal TaskManager()
{
_lock = new object();
}
diff --git a/src/Discord.Net/Events/UserEventArgs.cs b/src/Discord.Net/UserEventArgs.cs
similarity index 99%
rename from src/Discord.Net/Events/UserEventArgs.cs
rename to src/Discord.Net/UserEventArgs.cs
index d97f58795..bf7dd2cac 100644
--- a/src/Discord.Net/Events/UserEventArgs.cs
+++ b/src/Discord.Net/UserEventArgs.cs
@@ -4,6 +4,7 @@ namespace Discord
public class UserEventArgs : EventArgs
{
public User User { get; }
+
public Server Server => User.Server;
public UserEventArgs(User user) { User = user; }
diff --git a/test/Discord.Net.Tests/Tests.cs b/test/Discord.Net.Tests/Tests.cs
index 1fee99ebe..e3d3977ad 100644
--- a/test/Discord.Net.Tests/Tests.cs
+++ b/test/Discord.Net.Tests/Tests.cs
@@ -1,5 +1,4 @@
-using Discord.Legacy;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;