From 4848f307d36229c6f32b73fe9e4db3167f477124 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Mon, 29 Aug 2016 14:56:43 +0100 Subject: [PATCH 01/24] Fix #244 and use the correct string --- src/Discord.Net.Commands/Map/CommandMap.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Discord.Net.Commands/Map/CommandMap.cs b/src/Discord.Net.Commands/Map/CommandMap.cs index f75a0f12f..66cce7406 100644 --- a/src/Discord.Net.Commands/Map/CommandMap.cs +++ b/src/Discord.Net.Commands/Map/CommandMap.cs @@ -23,9 +23,9 @@ namespace Discord.Commands string name; if (nextSpace == -1) - name = command.Text; + name = text; else - name = command.Text.Substring(0, nextSpace); + name = text.Substring(0, nextSpace); lock (this) { @@ -42,9 +42,9 @@ namespace Discord.Commands string name; if (nextSpace == -1) - name = command.Text; + name = text; else - name = command.Text.Substring(0, nextSpace); + name = text.Substring(0, nextSpace); lock (this) { From bd8a601e17e321f069ba09262f34ce51bd7ceb68 Mon Sep 17 00:00:00 2001 From: Joe4evr Date: Mon, 29 Aug 2016 16:17:52 +0200 Subject: [PATCH 02/24] Replace locking on 'this'. --- src/Discord.Net.Commands/Map/CommandMap.cs | 7 ++++--- src/Discord.Net.Commands/Map/CommandMapNode.cs | 5 +++-- .../WebSocket/Entities/Users/SocketGlobalUser.cs | 9 +++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Discord.Net.Commands/Map/CommandMap.cs b/src/Discord.Net.Commands/Map/CommandMap.cs index 66cce7406..a5a1f8bc4 100644 --- a/src/Discord.Net.Commands/Map/CommandMap.cs +++ b/src/Discord.Net.Commands/Map/CommandMap.cs @@ -7,6 +7,7 @@ namespace Discord.Commands internal class CommandMap { static readonly char[] _whitespaceChars = new char[] { ' ', '\r', '\n' }; + private readonly object _lockObj = new object(); private readonly ConcurrentDictionary _nodes; @@ -27,7 +28,7 @@ namespace Discord.Commands else name = text.Substring(0, nextSpace); - lock (this) + lock (_lockObj) { var nextNode = _nodes.GetOrAdd(name, x => new CommandMapNode(x)); nextNode.AddCommand(nextSpace == -1 ? "" : text, nextSpace + 1, command); @@ -46,7 +47,7 @@ namespace Discord.Commands else name = text.Substring(0, nextSpace); - lock (this) + lock (_lockObj) { CommandMapNode nextNode; if (_nodes.TryGetValue(name, out nextNode)) @@ -69,7 +70,7 @@ namespace Discord.Commands else name = text.Substring(0, nextSpace); - lock (this) + lock (_lockObj) { CommandMapNode nextNode; if (_nodes.TryGetValue(name, out nextNode)) diff --git a/src/Discord.Net.Commands/Map/CommandMapNode.cs b/src/Discord.Net.Commands/Map/CommandMapNode.cs index 1ce0b4724..5ef42544e 100644 --- a/src/Discord.Net.Commands/Map/CommandMapNode.cs +++ b/src/Discord.Net.Commands/Map/CommandMapNode.cs @@ -8,6 +8,7 @@ namespace Discord.Commands { private readonly ConcurrentDictionary _nodes; private readonly string _name; + private readonly object _lockObj = new object(); private ImmutableArray _commands; public bool IsEmpty => _commands.Length == 0 && _nodes.Count == 0; @@ -24,7 +25,7 @@ namespace Discord.Commands int nextSpace = text.IndexOf(' ', index); string name; - lock (this) + lock (_lockObj) { if (text == "") _commands = _commands.Add(command); @@ -45,7 +46,7 @@ namespace Discord.Commands int nextSpace = text.IndexOf(' ', index); string name; - lock (this) + lock (_lockObj) { if (text == "") _commands = _commands.Remove(command); diff --git a/src/Discord.Net/WebSocket/Entities/Users/SocketGlobalUser.cs b/src/Discord.Net/WebSocket/Entities/Users/SocketGlobalUser.cs index 3835dcc46..3b23f7985 100644 --- a/src/Discord.Net/WebSocket/Entities/Users/SocketGlobalUser.cs +++ b/src/Discord.Net/WebSocket/Entities/Users/SocketGlobalUser.cs @@ -8,6 +8,7 @@ namespace Discord.WebSocket internal class SocketGlobalUser : User, ISocketUser { internal override bool IsAttached => true; + private readonly object _lockObj = new object(); private ushort _references; @@ -25,13 +26,13 @@ namespace Discord.WebSocket { checked { - lock (this) + lock (_lockObj) _references++; } } public void RemoveRef(DiscordSocketClient discord) { - lock (this) + lock (_lockObj) { if (--_references == 0) discord.RemoveUser(Id); @@ -40,14 +41,14 @@ namespace Discord.WebSocket public override void Update(Model model, UpdateSource source) { - lock (this) + lock (_lockObj) base.Update(model, source); } public void Update(PresenceModel model, UpdateSource source) { //Race conditions are okay here. Multiple shards racing already cant guarantee presence in order. - //lock (this) + //lock (_lockObj) //{ var game = model.Game != null ? new Game(model.Game) : null; Presence = new Presence(game, model.Status); From c15d460c51107e63551882c170e7df7b27bf31d3 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Mon, 29 Aug 2016 15:34:46 -0400 Subject: [PATCH 03/24] contribution guide for docs --- docs/CONTRIBUTING.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 docs/CONTRIBUTING.md diff --git a/docs/CONTRIBUTING.md b/docs/CONTRIBUTING.md new file mode 100644 index 000000000..468ff7bd4 --- /dev/null +++ b/docs/CONTRIBUTING.md @@ -0,0 +1,15 @@ +# Contributing to Docs + +I don't really have any strict conditions for writing documentation, but just keep these few guidelines in mind: + +* Keep code samples in the `guides/samples` folder +* When referencing an object in the API, link to it's page in the API documentation. +* Documentation should be written in clear and proper English* + +\* If anyone is interested in translating documentation into other languages, please open an issue or contact me on Discord (`foxbot#0282`). + +### Compiling + +Documentation is compiled into a static site using [DocFx](dotnet.github.io/docfx/). You **must** install a version of DocFx that supports .NET Core. The latest build of that is [2.1.0-cli-alpha](https://github.com/dotnet/docfx/releases/tag/v2.1.0-cli-alpha). + +After making changes, compile your changes into the static site with `docfx`. You can also view your changes live with `docfx --serve`. \ No newline at end of file From fd9ec3ca1686bfb11e4c81a831356f43bafc0322 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Mon, 29 Aug 2016 22:20:32 +0100 Subject: [PATCH 04/24] Add Sanitize function to escape Markdown (#249) --- src/Discord.Net/Format.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Discord.Net/Format.cs b/src/Discord.Net/Format.cs index 8b1d06bf8..d31f0ad0a 100644 --- a/src/Discord.Net/Format.cs +++ b/src/Discord.Net/Format.cs @@ -2,6 +2,9 @@ { public static class Format { + // Characters which need escaping + private static string[] SensitiveCharacters = { "*", "_", "~", "`", "\\" }; + /// Returns a markdown-formatted string with bold formatting. public static string Bold(string text) => $"**{text}**"; /// Returns a markdown-formatted string with italics formatting. @@ -19,5 +22,15 @@ else return $"`{text}`"; } + + /// Sanitizes the string, safely escaping any Markdown sequences. + public static string Sanitize(string text) + { + foreach (string unsafeChar in SensitiveCharacters) + { + text = text.Replace(unsafeChar, $"\\{unsafeChar}"); + } + return text; + } } } From 42e127ac85edb1ad4dab8f07a6f1b2730ed6c9e1 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Tue, 30 Aug 2016 00:26:34 +0100 Subject: [PATCH 05/24] Resolve #251 --- src/Discord.Net.Commands/CommandParser.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Discord.Net.Commands/CommandParser.cs b/src/Discord.Net.Commands/CommandParser.cs index 7338f6995..77e19109a 100644 --- a/src/Discord.Net.Commands/CommandParser.cs +++ b/src/Discord.Net.Commands/CommandParser.cs @@ -150,6 +150,8 @@ namespace Discord.Commands for (int i = argList.Count; i < command.Parameters.Count; i++) { var param = command.Parameters[i]; + if (param.IsMultiple) + continue; if (!param.IsOptional) return ParseResult.FromError(CommandError.BadArgCount, "The input text has too few parameters."); argList.Add(TypeReaderResult.FromSuccess(param.DefaultValue)); From 1ab763e157a2484165a302fc1aa81b0404c2ecde Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Wed, 31 Aug 2016 13:51:09 +0100 Subject: [PATCH 06/24] Allow parameterless commands to build correctly Resolves #253 --- src/Discord.Net.Commands/Command.cs | 10 +++++++++- src/Discord.Net.Commands/Module.cs | 8 ++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net.Commands/Command.cs b/src/Discord.Net.Commands/Command.cs index 61eff4877..9df0bcc9d 100644 --- a/src/Discord.Net.Commands/Command.cs +++ b/src/Discord.Net.Commands/Command.cs @@ -38,7 +38,15 @@ namespace Discord.Commands _instance = instance; Name = source.Name; - Text = groupPrefix + attribute.Text; + + if (attribute.Text == null) + Text = groupPrefix; + + if (groupPrefix != "") + groupPrefix += " "; + + if (attribute.Text != null) + Text = groupPrefix + attribute.Text; var aliasesBuilder = ImmutableArray.CreateBuilder(); diff --git a/src/Discord.Net.Commands/Module.cs b/src/Discord.Net.Commands/Module.cs index 0624e6ef3..eff1f9787 100644 --- a/src/Discord.Net.Commands/Module.cs +++ b/src/Discord.Net.Commands/Module.cs @@ -48,8 +48,6 @@ namespace Discord.Commands private void SearchClass(TypeInfo parentType, object instance, List commands, string groupPrefix, IDependencyMap dependencyMap) { - if (groupPrefix != "") - groupPrefix += " "; foreach (var method in parentType.DeclaredMethods) { var cmdAttr = method.GetCustomAttribute(); @@ -63,9 +61,15 @@ namespace Discord.Commands { string nextGroupPrefix; if (groupAttrib.Prefix != null) + { + if (groupPrefix != "") + groupPrefix += " "; nextGroupPrefix = groupPrefix + groupAttrib.Prefix ?? type.Name; + } else + { nextGroupPrefix = groupPrefix; + } SearchClass(type, ReflectionUtils.CreateObject(type, Service, dependencyMap), commands, nextGroupPrefix, dependencyMap); } } From cddc39dfa1489817114eadcc88b62f62dbc239c2 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Wed, 31 Aug 2016 15:05:31 +0100 Subject: [PATCH 07/24] Don't add multiple spaces for multiple groups --- src/Discord.Net.Commands/Module.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net.Commands/Module.cs b/src/Discord.Net.Commands/Module.cs index eff1f9787..7b74ffb87 100644 --- a/src/Discord.Net.Commands/Module.cs +++ b/src/Discord.Net.Commands/Module.cs @@ -63,8 +63,9 @@ namespace Discord.Commands if (groupAttrib.Prefix != null) { if (groupPrefix != "") - groupPrefix += " "; - nextGroupPrefix = groupPrefix + groupAttrib.Prefix ?? type.Name; + nextGroupPrefix = groupPrefix + " " + groupAttrib.Prefix ?? type.Name; + else + nextGroupPrefix = groupAttrib.Prefix ?? type.Name; } else { From c05f44a5445b449051488199071985835326d020 Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Wed, 31 Aug 2016 15:28:38 +0100 Subject: [PATCH 08/24] Allow command groups to work correctly --- src/Discord.Net.Commands/Module.cs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/Discord.Net.Commands/Module.cs b/src/Discord.Net.Commands/Module.cs index 7b74ffb87..7b8113252 100644 --- a/src/Discord.Net.Commands/Module.cs +++ b/src/Discord.Net.Commands/Module.cs @@ -60,17 +60,12 @@ namespace Discord.Commands if (groupAttrib != null) { string nextGroupPrefix; - if (groupAttrib.Prefix != null) - { - if (groupPrefix != "") - nextGroupPrefix = groupPrefix + " " + groupAttrib.Prefix ?? type.Name; - else - nextGroupPrefix = groupAttrib.Prefix ?? type.Name; - } + + if (groupPrefix != "") + nextGroupPrefix = groupPrefix + " " + (groupAttrib.Prefix ?? type.Name.ToLowerInvariant()); else - { - nextGroupPrefix = groupPrefix; - } + nextGroupPrefix = groupAttrib.Prefix ?? type.Name.ToLowerInvariant(); + SearchClass(type, ReflectionUtils.CreateObject(type, Service, dependencyMap), commands, nextGroupPrefix, dependencyMap); } } From 3df4201c8cd6232df04a0485963722ebdbe2bbfc Mon Sep 17 00:00:00 2001 From: Mushroom Date: Sun, 4 Sep 2016 00:29:46 +0100 Subject: [PATCH 09/24] Optimize rest of lib for release builds --- src/Discord.Net/project.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net/project.json b/src/Discord.Net/project.json index 52fbc34c9..48ea66840 100644 --- a/src/Discord.Net/project.json +++ b/src/Discord.Net/project.json @@ -16,7 +16,8 @@ "buildOptions": { "allowUnsafe": true, "warningsAsErrors": false, - "xmlDoc": true + "xmlDoc": true, + "optimize": true }, "configurations": { From b749be8a2fefbbb7a26c6c2abb7474762a196a1a Mon Sep 17 00:00:00 2001 From: Mushroom Date: Sun, 4 Sep 2016 00:55:26 +0100 Subject: [PATCH 10/24] Optimize on release builds only --- src/Discord.Net/project.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net/project.json b/src/Discord.Net/project.json index 48ea66840..07d62f480 100644 --- a/src/Discord.Net/project.json +++ b/src/Discord.Net/project.json @@ -16,15 +16,15 @@ "buildOptions": { "allowUnsafe": true, "warningsAsErrors": false, - "xmlDoc": true, - "optimize": true + "xmlDoc": true }, "configurations": { "Release": { "buildOptions": { "define": [ "RELEASE" ], - "nowarn": [ "CS1573", "CS1591" ] + "nowarn": [ "CS1573", "CS1591" ], + "optimize": true } } }, From 550e0c8cf1e082e349e7972daf5759ebff7f4f35 Mon Sep 17 00:00:00 2001 From: RogueException Date: Sat, 3 Sep 2016 21:30:03 -0300 Subject: [PATCH 11/24] Removed tabs --- src/Discord.Net/project.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord.Net/project.json b/src/Discord.Net/project.json index 07d62f480..16fdb8aef 100644 --- a/src/Discord.Net/project.json +++ b/src/Discord.Net/project.json @@ -24,7 +24,7 @@ "buildOptions": { "define": [ "RELEASE" ], "nowarn": [ "CS1573", "CS1591" ], - "optimize": true + "optimize": true } } }, From 169b09aadd5ea29faa35abe0fc90b0bd51ed2815 Mon Sep 17 00:00:00 2001 From: Auxe Date: Mon, 5 Sep 2016 19:14:55 -0500 Subject: [PATCH 12/24] Fixed channel being null --- src/Discord.Net/WebSocket/DiscordSocketClient.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Discord.Net/WebSocket/DiscordSocketClient.cs b/src/Discord.Net/WebSocket/DiscordSocketClient.cs index a77110c66..f7344c012 100644 --- a/src/Discord.Net/WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net/WebSocket/DiscordSocketClient.cs @@ -793,6 +793,7 @@ namespace Discord.WebSocket if (guild != null) { guild.AddChannel(data, DataStore); + channel = DataStore.GetChannel(data.Id); if (!guild.IsSynced) { From 4919c8f5914434dff866f97a2a26f1293eaf6db1 Mon Sep 17 00:00:00 2001 From: Auxe Date: Mon, 5 Sep 2016 19:32:58 -0500 Subject: [PATCH 13/24] Made the requested changes --- src/Discord.Net/WebSocket/DiscordSocketClient.cs | 2 +- src/Discord.Net/WebSocket/Entities/Guilds/SocketGuild.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Discord.Net/WebSocket/DiscordSocketClient.cs b/src/Discord.Net/WebSocket/DiscordSocketClient.cs index f7344c012..5d5d87ebd 100644 --- a/src/Discord.Net/WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net/WebSocket/DiscordSocketClient.cs @@ -793,7 +793,7 @@ namespace Discord.WebSocket if (guild != null) { guild.AddChannel(data, DataStore); - channel = DataStore.GetChannel(data.Id); + channel = guild.AddChannel(data, DataStore); if (!guild.IsSynced) { diff --git a/src/Discord.Net/WebSocket/Entities/Guilds/SocketGuild.cs b/src/Discord.Net/WebSocket/Entities/Guilds/SocketGuild.cs index ea0eb07a9..75f8fded2 100644 --- a/src/Discord.Net/WebSocket/Entities/Guilds/SocketGuild.cs +++ b/src/Discord.Net/WebSocket/Entities/Guilds/SocketGuild.cs @@ -148,11 +148,12 @@ namespace Discord.WebSocket public override Task GetChannelAsync(ulong id) => Task.FromResult(GetChannel(id)); public override Task> GetChannelsAsync() => Task.FromResult>(Channels); - public void AddChannel(ChannelModel model, DataStore dataStore, ConcurrentHashSet channels = null) + public ISocketGuildChannel AddChannel(ChannelModel model, DataStore dataStore, ConcurrentHashSet channels = null) { var channel = ToChannel(model); (channels ?? _channels).TryAdd(model.Id); dataStore.AddChannel(channel); + return channel; } public ISocketGuildChannel GetChannel(ulong id) { From 9f9a65135d6a74389e79d2edf1ab911e6e250cbe Mon Sep 17 00:00:00 2001 From: Auxe Date: Mon, 5 Sep 2016 19:37:31 -0500 Subject: [PATCH 14/24] Removed a duplicate statement --- src/Discord.Net/WebSocket/DiscordSocketClient.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Discord.Net/WebSocket/DiscordSocketClient.cs b/src/Discord.Net/WebSocket/DiscordSocketClient.cs index 5d5d87ebd..fec02d465 100644 --- a/src/Discord.Net/WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net/WebSocket/DiscordSocketClient.cs @@ -792,7 +792,6 @@ namespace Discord.WebSocket var guild = DataStore.GetGuild(data.GuildId.Value); if (guild != null) { - guild.AddChannel(data, DataStore); channel = guild.AddChannel(data, DataStore); if (!guild.IsSynced) From d2b37c38d676516b28440b8870717092d6920df2 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Tue, 6 Sep 2016 18:43:25 +0200 Subject: [PATCH 15/24] Fixed Optional argument in Message Updated event --- src/Discord.Net/WebSocket/DiscordSocketClient.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net/WebSocket/DiscordSocketClient.cs b/src/Discord.Net/WebSocket/DiscordSocketClient.cs index fec02d465..8baeba583 100644 --- a/src/Discord.Net/WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net/WebSocket/DiscordSocketClient.cs @@ -1262,7 +1262,10 @@ namespace Discord.WebSocket after = channel.CreateMessage(author, data); } if (after != null) - await _messageUpdatedEvent.InvokeAsync(Optional.Create(before), after).ConfigureAwait(false); + if (before == null) + await _messageUpdatedEvent.InvokeAsync(Optional.Create(), after).ConfigureAwait(false); + else + await _messageUpdatedEvent.InvokeAsync(Optional.Create(before), after).ConfigureAwait(false); } else { From afc30bf412113b45381e96a9fca532a07f0a5bf0 Mon Sep 17 00:00:00 2001 From: Khionu Terabite Date: Tue, 6 Sep 2016 16:01:36 -0400 Subject: [PATCH 16/24] Renamed the Description/Summary Attributes to Summary/Remarks, as per the discussion in 239 --- .../{DescriptionAttribute.cs => RemarksAttribute.cs} | 6 +++--- .../Attributes/SummaryAttribute.cs | 2 +- src/Discord.Net.Commands/Command.cs | 10 +++++----- src/Discord.Net.Commands/Module.cs | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) rename src/Discord.Net.Commands/Attributes/{DescriptionAttribute.cs => RemarksAttribute.cs} (57%) diff --git a/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs b/src/Discord.Net.Commands/Attributes/RemarksAttribute.cs similarity index 57% rename from src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs rename to src/Discord.Net.Commands/Attributes/RemarksAttribute.cs index 9940c40f3..e5b0d2142 100644 --- a/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/RemarksAttribute.cs @@ -2,13 +2,13 @@ namespace Discord.Commands { - // Full summary of method + // Extension of the Cosmetic Summary, for Groups and Commands [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] - public class DescriptionAttribute : Attribute + public class RemarksAttribute : Attribute { public string Text { get; } - public DescriptionAttribute(string text) + public RemarksAttribute(string text) { Text = text; } diff --git a/src/Discord.Net.Commands/Attributes/SummaryAttribute.cs b/src/Discord.Net.Commands/Attributes/SummaryAttribute.cs index b7a4e3d43..06c75af42 100644 --- a/src/Discord.Net.Commands/Attributes/SummaryAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/SummaryAttribute.cs @@ -2,7 +2,7 @@ namespace Discord.Commands { - // Brief summary of method/module/parameter + // Cosmetic Description for Groups, Commands, and Parameters [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter)] public class SummaryAttribute : Attribute { diff --git a/src/Discord.Net.Commands/Command.cs b/src/Discord.Net.Commands/Command.cs index 9df0bcc9d..b191b5786 100644 --- a/src/Discord.Net.Commands/Command.cs +++ b/src/Discord.Net.Commands/Command.cs @@ -21,8 +21,8 @@ namespace Discord.Commands public MethodInfo Source { get; } public Module Module { get; } public string Name { get; } - public string Description { get; } public string Summary { get; } + public string Remarks { get; } public string Text { get; } public bool HasVarArgs { get; } public IReadOnlyList Aliases { get; } @@ -62,14 +62,14 @@ namespace Discord.Commands if (nameAttr != null) Name = nameAttr.Text; - var description = source.GetCustomAttribute(); - if (description != null) - Description = description.Text; - var summary = source.GetCustomAttribute(); if (summary != null) Summary = summary.Text; + var remarksAttr = source.GetCustomAttribute(); + if (remarksAttr != null) + Remarks = remarksAttr.Text; + Parameters = BuildParameters(source); HasVarArgs = Parameters.Count > 0 ? Parameters[Parameters.Count - 1].IsMultiple : false; Preconditions = BuildPreconditions(source); diff --git a/src/Discord.Net.Commands/Module.cs b/src/Discord.Net.Commands/Module.cs index 7b8113252..9d61ca522 100644 --- a/src/Discord.Net.Commands/Module.cs +++ b/src/Discord.Net.Commands/Module.cs @@ -13,7 +13,7 @@ namespace Discord.Commands public string Name { get; } public string Prefix { get; } public string Summary { get; } - public string Description { get; } + public string Remarks { get; } public IEnumerable Commands { get; } internal object Instance { get; } @@ -35,9 +35,9 @@ namespace Discord.Commands if (summaryAttr != null) Summary = summaryAttr.Text; - var descriptionAttr = source.GetCustomAttribute(); - if (descriptionAttr != null) - Description = descriptionAttr.Text; + var remarksAttr = source.GetCustomAttribute(); + if (remarksAttr != null) + Remarks = remarksAttr.Text; List commands = new List(); SearchClass(source, instance, commands, Prefix, dependencyMap); From 022a44b712d382c4883f752e7be5520633ee72fc Mon Sep 17 00:00:00 2001 From: Khionu Terabite Date: Tue, 6 Sep 2016 16:06:09 -0400 Subject: [PATCH 17/24] Revert "Renamed the Description/Summary Attributes to Summary/Remarks, as per the discussion in 239" This reverts commit afc30bf412113b45381e96a9fca532a07f0a5bf0. --- .../{RemarksAttribute.cs => DescriptionAttribute.cs} | 6 +++--- .../Attributes/SummaryAttribute.cs | 2 +- src/Discord.Net.Commands/Command.cs | 10 +++++----- src/Discord.Net.Commands/Module.cs | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) rename src/Discord.Net.Commands/Attributes/{RemarksAttribute.cs => DescriptionAttribute.cs} (57%) diff --git a/src/Discord.Net.Commands/Attributes/RemarksAttribute.cs b/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs similarity index 57% rename from src/Discord.Net.Commands/Attributes/RemarksAttribute.cs rename to src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs index e5b0d2142..9940c40f3 100644 --- a/src/Discord.Net.Commands/Attributes/RemarksAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs @@ -2,13 +2,13 @@ namespace Discord.Commands { - // Extension of the Cosmetic Summary, for Groups and Commands + // Full summary of method [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] - public class RemarksAttribute : Attribute + public class DescriptionAttribute : Attribute { public string Text { get; } - public RemarksAttribute(string text) + public DescriptionAttribute(string text) { Text = text; } diff --git a/src/Discord.Net.Commands/Attributes/SummaryAttribute.cs b/src/Discord.Net.Commands/Attributes/SummaryAttribute.cs index 06c75af42..b7a4e3d43 100644 --- a/src/Discord.Net.Commands/Attributes/SummaryAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/SummaryAttribute.cs @@ -2,7 +2,7 @@ namespace Discord.Commands { - // Cosmetic Description for Groups, Commands, and Parameters + // Brief summary of method/module/parameter [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter)] public class SummaryAttribute : Attribute { diff --git a/src/Discord.Net.Commands/Command.cs b/src/Discord.Net.Commands/Command.cs index b191b5786..9df0bcc9d 100644 --- a/src/Discord.Net.Commands/Command.cs +++ b/src/Discord.Net.Commands/Command.cs @@ -21,8 +21,8 @@ namespace Discord.Commands public MethodInfo Source { get; } public Module Module { get; } public string Name { get; } + public string Description { get; } public string Summary { get; } - public string Remarks { get; } public string Text { get; } public bool HasVarArgs { get; } public IReadOnlyList Aliases { get; } @@ -62,14 +62,14 @@ namespace Discord.Commands if (nameAttr != null) Name = nameAttr.Text; + var description = source.GetCustomAttribute(); + if (description != null) + Description = description.Text; + var summary = source.GetCustomAttribute(); if (summary != null) Summary = summary.Text; - var remarksAttr = source.GetCustomAttribute(); - if (remarksAttr != null) - Remarks = remarksAttr.Text; - Parameters = BuildParameters(source); HasVarArgs = Parameters.Count > 0 ? Parameters[Parameters.Count - 1].IsMultiple : false; Preconditions = BuildPreconditions(source); diff --git a/src/Discord.Net.Commands/Module.cs b/src/Discord.Net.Commands/Module.cs index 9d61ca522..7b8113252 100644 --- a/src/Discord.Net.Commands/Module.cs +++ b/src/Discord.Net.Commands/Module.cs @@ -13,7 +13,7 @@ namespace Discord.Commands public string Name { get; } public string Prefix { get; } public string Summary { get; } - public string Remarks { get; } + public string Description { get; } public IEnumerable Commands { get; } internal object Instance { get; } @@ -35,9 +35,9 @@ namespace Discord.Commands if (summaryAttr != null) Summary = summaryAttr.Text; - var remarksAttr = source.GetCustomAttribute(); - if (remarksAttr != null) - Remarks = remarksAttr.Text; + var descriptionAttr = source.GetCustomAttribute(); + if (descriptionAttr != null) + Description = descriptionAttr.Text; List commands = new List(); SearchClass(source, instance, commands, Prefix, dependencyMap); From b6c634b8b51539d7700c75da2ffd4bf41ac02fab Mon Sep 17 00:00:00 2001 From: Khionu Terabite Date: Tue, 6 Sep 2016 16:19:43 -0400 Subject: [PATCH 18/24] Renamed Description/Summary Attributes to Summary/Remarks, as per discussion in #239 --- .../{DescriptionAttribute.cs => RemarksAttribute.cs} | 6 +++--- .../Attributes/SummaryAttribute.cs | 2 +- src/Discord.Net.Commands/Command.cs | 10 +++++----- src/Discord.Net.Commands/Module.cs | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) rename src/Discord.Net.Commands/Attributes/{DescriptionAttribute.cs => RemarksAttribute.cs} (55%) diff --git a/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs b/src/Discord.Net.Commands/Attributes/RemarksAttribute.cs similarity index 55% rename from src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs rename to src/Discord.Net.Commands/Attributes/RemarksAttribute.cs index 9940c40f3..44db18a79 100644 --- a/src/Discord.Net.Commands/Attributes/DescriptionAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/RemarksAttribute.cs @@ -2,13 +2,13 @@ namespace Discord.Commands { - // Full summary of method + // Extension of the Cosmetic Summary, for Groups, Commands, and Parameters [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)] - public class DescriptionAttribute : Attribute + public class RemarksAttribute : Attribute { public string Text { get; } - public DescriptionAttribute(string text) + public RemarksAttribute(string text) { Text = text; } diff --git a/src/Discord.Net.Commands/Attributes/SummaryAttribute.cs b/src/Discord.Net.Commands/Attributes/SummaryAttribute.cs index b7a4e3d43..46d52f3d9 100644 --- a/src/Discord.Net.Commands/Attributes/SummaryAttribute.cs +++ b/src/Discord.Net.Commands/Attributes/SummaryAttribute.cs @@ -2,7 +2,7 @@ namespace Discord.Commands { - // Brief summary of method/module/parameter + // Cosmetic Summary, for Groups and Commands [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Parameter)] public class SummaryAttribute : Attribute { diff --git a/src/Discord.Net.Commands/Command.cs b/src/Discord.Net.Commands/Command.cs index 9df0bcc9d..b191b5786 100644 --- a/src/Discord.Net.Commands/Command.cs +++ b/src/Discord.Net.Commands/Command.cs @@ -21,8 +21,8 @@ namespace Discord.Commands public MethodInfo Source { get; } public Module Module { get; } public string Name { get; } - public string Description { get; } public string Summary { get; } + public string Remarks { get; } public string Text { get; } public bool HasVarArgs { get; } public IReadOnlyList Aliases { get; } @@ -62,14 +62,14 @@ namespace Discord.Commands if (nameAttr != null) Name = nameAttr.Text; - var description = source.GetCustomAttribute(); - if (description != null) - Description = description.Text; - var summary = source.GetCustomAttribute(); if (summary != null) Summary = summary.Text; + var remarksAttr = source.GetCustomAttribute(); + if (remarksAttr != null) + Remarks = remarksAttr.Text; + Parameters = BuildParameters(source); HasVarArgs = Parameters.Count > 0 ? Parameters[Parameters.Count - 1].IsMultiple : false; Preconditions = BuildPreconditions(source); diff --git a/src/Discord.Net.Commands/Module.cs b/src/Discord.Net.Commands/Module.cs index 7b8113252..9d61ca522 100644 --- a/src/Discord.Net.Commands/Module.cs +++ b/src/Discord.Net.Commands/Module.cs @@ -13,7 +13,7 @@ namespace Discord.Commands public string Name { get; } public string Prefix { get; } public string Summary { get; } - public string Description { get; } + public string Remarks { get; } public IEnumerable Commands { get; } internal object Instance { get; } @@ -35,9 +35,9 @@ namespace Discord.Commands if (summaryAttr != null) Summary = summaryAttr.Text; - var descriptionAttr = source.GetCustomAttribute(); - if (descriptionAttr != null) - Description = descriptionAttr.Text; + var remarksAttr = source.GetCustomAttribute(); + if (remarksAttr != null) + Remarks = remarksAttr.Text; List commands = new List(); SearchClass(source, instance, commands, Prefix, dependencyMap); From a2b4f47acfdfd11073f11e5dfc22e9f61fc18c99 Mon Sep 17 00:00:00 2001 From: Christopher F Date: Sat, 10 Sep 2016 14:26:24 -0400 Subject: [PATCH 19/24] [docs] replace description with summary Resolves #280 --- docs/guides/samples/module.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/guides/samples/module.cs b/docs/guides/samples/module.cs index 9de35aa6e..282a322c9 100644 --- a/docs/guides/samples/module.cs +++ b/docs/guides/samples/module.cs @@ -6,9 +6,9 @@ using Discord.WebSocket; public class Info { // ~say hello -> hello - [Command("say"), Description("Echos a message.")] + [Command("say"), Summary("Echos a message.")] public async Task Say(IUserMessage msg, - [Unparsed, Description("The text to echo")] string echo) + [Unparsed, Summary("The text to echo")] string echo) { await msg.Channel.SendMessageAsync(echo); } @@ -19,9 +19,9 @@ public class Info public class Sample { // ~sample square 20 -> - [Command("square"), Description("Squares a number.")] + [Command("square"), Summary("Squares a number.")] public async Task Square(IUserMessage msg, - [Description("The number to square.")] int num) + [Summary("The number to square.")] int num) { await msg.Channel.SendMessageAsync($"{num}^2 = {Math.Pow(num, 2)}"); } @@ -32,10 +32,10 @@ public class Sample // ~sample userinfo Khionu --> Khionu#8708 // ~sample userinfo 96642168176807936 --> Khionu#8708 // ~sample whois 96642168176807936 --> Khionu#8708 - [Command("userinfo"), Description("Returns info about the current user, or the user parameter, if one passed.")] + [Command("userinfo"), Summary("Returns info about the current user, or the user parameter, if one passed.")] [Alias("user", "whois")] public async Task UserInfo(IUserMessage msg, - [Description("The (optional) user to get info for")] IUser user = null) + [Summary("The (optional) user to get info for")] IUser user = null) { var userInfo = user ?? await Program.Client.GetCurrentUserAsync(); await msg.Channel.SendMessageAsync($"{userInfo.Username}#{userInfo.Discriminator}"); From 4f0a29bbd7cab5a78f92f985d89f427fcf2a346a Mon Sep 17 00:00:00 2001 From: Pat Murphy Date: Tue, 13 Sep 2016 19:21:35 -0700 Subject: [PATCH 20/24] fixing a comment typo --- src/Discord.Net/WebSocket/DiscordSocketClient.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Discord.Net/WebSocket/DiscordSocketClient.cs b/src/Discord.Net/WebSocket/DiscordSocketClient.cs index fec02d465..9bd217ac1 100644 --- a/src/Discord.Net/WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net/WebSocket/DiscordSocketClient.cs @@ -38,7 +38,7 @@ namespace Discord.WebSocket private int _nextAudioId; private bool _canReconnect; - /// Gets the shard if of this client. + /// Gets the shard id of this client. public int ShardId { get; } /// Gets the current connection state of this client. public ConnectionState ConnectionState { get; private set; } From accb3e27b82740115ade62251cd5dba584db0b6f Mon Sep 17 00:00:00 2001 From: FiniteReality Date: Thu, 15 Sep 2016 18:43:06 +0100 Subject: [PATCH 21/24] Add PriorityAttribute and sortby priority in Search --- .../Attributes/PriorityAttribute.cs | 18 ++++++++++++++++++ src/Discord.Net.Commands/Command.cs | 4 ++++ src/Discord.Net.Commands/CommandService.cs | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/Discord.Net.Commands/Attributes/PriorityAttribute.cs diff --git a/src/Discord.Net.Commands/Attributes/PriorityAttribute.cs b/src/Discord.Net.Commands/Attributes/PriorityAttribute.cs new file mode 100644 index 000000000..5120bb7d1 --- /dev/null +++ b/src/Discord.Net.Commands/Attributes/PriorityAttribute.cs @@ -0,0 +1,18 @@ +using System; + +namespace Discord.Commands +{ + /// Sets priority of commands + [AttributeUsage(AttributeTargets.Method)] + public class PriorityAttribute : Attribute + { + /// The priority which has been set for the command + public int Priority { get; } + + /// Creates a new with the given priority. + public PriorityAttribute(int priority) + { + Priority = priority; + } + } +} diff --git a/src/Discord.Net.Commands/Command.cs b/src/Discord.Net.Commands/Command.cs index b191b5786..b7b7da401 100644 --- a/src/Discord.Net.Commands/Command.cs +++ b/src/Discord.Net.Commands/Command.cs @@ -24,6 +24,7 @@ namespace Discord.Commands public string Summary { get; } public string Remarks { get; } public string Text { get; } + public int Priority { get; } public bool HasVarArgs { get; } public IReadOnlyList Aliases { get; } public IReadOnlyList Parameters { get; } @@ -70,6 +71,9 @@ namespace Discord.Commands if (remarksAttr != null) Remarks = remarksAttr.Text; + var priorityAttr = source.GetCustomAttribute(); + Priority = priorityAttr?.Priority ?? 0; + Parameters = BuildParameters(source); HasVarArgs = Parameters.Count > 0 ? Parameters[Parameters.Count - 1].IsMultiple : false; Preconditions = BuildPreconditions(source); diff --git a/src/Discord.Net.Commands/CommandService.cs b/src/Discord.Net.Commands/CommandService.cs index 814277b04..344950e68 100644 --- a/src/Discord.Net.Commands/CommandService.cs +++ b/src/Discord.Net.Commands/CommandService.cs @@ -180,7 +180,7 @@ namespace Discord.Commands public SearchResult Search(IUserMessage message, string input) { string lowerInput = input.ToLowerInvariant(); - var matches = _map.GetCommands(input).ToImmutableArray(); + var matches = _map.GetCommands(input).OrderByDescending(x => x.Priority).ToImmutableArray(); if (matches.Length > 0) return SearchResult.FromSuccess(input, matches); From 44b20ef9ca32abdd0595567e2bf94326c9d0f387 Mon Sep 17 00:00:00 2001 From: Flamanis Date: Tue, 20 Sep 2016 00:13:57 -0500 Subject: [PATCH 22/24] Update migrating.md --- docs/migrating.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/migrating.md b/docs/migrating.md index f73d5e8c0..c69b8a59c 100644 --- a/docs/migrating.md +++ b/docs/migrating.md @@ -1,6 +1,6 @@ # Migrating from 0.9 -**1.0.0 is the biggest breaking change the library has gone through, do to massive +**1.0.0 is the biggest breaking change the library has gone through, due to massive changes in the design of the library.** >A medium to advanced understanding is recommended when working with this library. @@ -78,4 +78,4 @@ provide java-esque, synchronus `GetXXX` methods to replace the asynchronus metho This functionality may be changed at a later date, we are currently reviewing this implementation and alternative methods. -For your reference, you may want to look through the extension classes located in @Discord.WebSocket \ No newline at end of file +For your reference, you may want to look through the extension classes located in @Discord.WebSocket From 336e6d20d9654a4c59aba66bb1befa775694989c Mon Sep 17 00:00:00 2001 From: RogueException Date: Tue, 20 Sep 2016 17:46:12 -0300 Subject: [PATCH 23/24] Fixed braces --- src/Discord.Net/WebSocket/DiscordSocketClient.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Discord.Net/WebSocket/DiscordSocketClient.cs b/src/Discord.Net/WebSocket/DiscordSocketClient.cs index 5018c9d86..3bd5df7de 100644 --- a/src/Discord.Net/WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net/WebSocket/DiscordSocketClient.cs @@ -1262,10 +1262,12 @@ namespace Discord.WebSocket after = channel.CreateMessage(author, data); } if (after != null) + { if (before == null) await _messageUpdatedEvent.InvokeAsync(Optional.Create(), after).ConfigureAwait(false); else await _messageUpdatedEvent.InvokeAsync(Optional.Create(before), after).ConfigureAwait(false); + } } else { From ae186f8d9eb8647dfbc4c8e2bd6f135359271aae Mon Sep 17 00:00:00 2001 From: RogueException Date: Tue, 20 Sep 2016 17:46:32 -0300 Subject: [PATCH 24/24] Updated solution --- Discord.Net.sln | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Discord.Net.sln b/Discord.Net.sln index 11960606b..13e9585f9 100644 --- a/Discord.Net.sln +++ b/Discord.Net.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.25123.0 +VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Discord.Net", "src\Discord.Net\Discord.Net.xproj", "{91E9E7BD-75C9-4E98-84AA-2C271922E5C2}" EndProject