This repository has been archived by the owner on Oct 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Help Command and Refactor (#275)
* Implement help command basics * Update all dependencies and StyleCop pass This ensures that all projects within Miunie are now set to the latest .NET Core, .NET Standard, and C# Language versions. All dependencies specified in Miunie were updated to their most recent counterparts. All classes mentioned were modified to follow StyleCop standards. One readonly value was made in EmbedConstructor to simplify .WithColor() when creating new embeds. All existing summaries were moved into HelpStrings.resx. HelpService now attempts to fetch a summary for the specified ID in SummaryAttribute for a CommandInfo, and will now use ILanguageProvider for default string values. * Set LangVersion to 8.0 and refactor This update should fix all issues previously mentioned and make some methods easier to handle. Changes - Created StringExtensions, which contains two methods of ValueOrDefault(this string, string) and JoinOrDefault(this IEnumerable<string>, string, string). - Created TExtensions, which contains one method of StringJoinOrDefault(this IEnumerable<T>, Func<T, string>, string, string). - Set all LangVersion properties to 8.0. - Modified HelpCommand, MiscCommands, ProfileCommand, RemoteRepositoryCommand, and TimeCommand to store their direct summaries and include examples. - Modified HelpCommandProvider to include three new methods of GetAllModuleSections(), GetSection(ModuleInfo), and GetSection(CommandInfo). - Modified HelpCommandProvider.Search to use GetSection(Command). - Modified HelpCommandProvider.GetDefault to use GetAllModuleSections(). - Modified HelpCommandProvider.GetExamples(CommandInfo) to use .StringJoinOrDefault(). - Modified HelpResult.Sections to implement IEnumerable<HelpSection> instead. - Modified HelpResult.Sections to expose the set property. - Modified Strings.resx to make HELP_SUMMARY_EMPTY and HELP_EXAMPLE_EMPTY include multiple response values. - Modified EmbedConstructor.GetHelpEmbed(HelpResult) to use MiuniePinkColor for its EmbedBuilder. - Renamed EmbedConstructor.DefaultEmbedColor to MiuniePinkColor and removed comment. - Renamed HelpService to HelpCommandProvider. - Renamed CommandService.GetHelpService(ILanguageProvider) to CommandService.GetHelpProvider(ILanguageProvider). - Reverted all .NET Standard targets back to 2.0. - Deleted HelpStrings.resx. * Replace collection count property A quick change that fixes the previous string[].Length to now use the required IEnumerable<string>.Count(). * Apply implicit declaration where needed Another minor fix that applies implicit declaration where it was needed, alongside adding a blank line in between a variable and a for each statement. * Minor refactor in code - Created new method GetModuleCommandBlocks(ModuleInfo) in HelpCommandProvider. - Modified ProfileCommand to use "to" instead of "for" in both summaries. - Modified HelpCommandProvider.GetDefault() to use _commandService.Modules.Select() instead. - Modified HelpCommandProvider.GetSection(ModuleInfo) to use GetModuleCommandBlocks(). - Removed HelpCommandProvider.GetAllModuleHelpSections(). * Change search method format - Modified HelpCommandProvider.Search(string) to use the similar .Select() method used in GetDefault(). * Adjust methods and dependencies - Modify Container.AddMiunieTypes(this IServiceCollection) to include CommandService - Modify method GetHelp() in HelpCommand to handle sending the message result - Modify method GetHelp(string) in HelpCommand to handle sending the message result - Renamed HelpCommandProvider to CommandHelpProvider - Rename method GetDefault() to ForAllCommands() in CommandHelpProvider - Rename method Search(string) to FromInput(string) in CommandHelpProvider - Remove method GetHelpProvider(ILanguageProvider) from CommandHandler - Remove method ShowDefaultHelpAsync(IMessageChannel) in CommandHelpProvider - Remove method ShowCommandHelpAsync(IMessageChannel, string) from CommandHelpProvider - Delete StringExtensions - Delete TExtensions * Rename private variables This quick formatting fix properly renames the specified variables, as brought to light by 1n5an1ty. * Properly rename private variables This push now correctly renames the private variables mentioned. * Update src/Miunie.Discord/Providers/CommandHelpProvider.cs Co-authored-by: Petr Sedláček <[email protected]>
- Loading branch information
1 parent
617d05b
commit a5e912f
Showing
26 changed files
with
473 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// This file is part of Miunie. | ||
// | ||
// Miunie is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Miunie is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Miunie. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
using System; | ||
|
||
namespace Miunie.Discord.Attributes | ||
{ | ||
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] | ||
public class ExamplesAttribute : Attribute | ||
{ | ||
public ExamplesAttribute(params string[] examples) | ||
{ | ||
Examples = examples; | ||
} | ||
|
||
public string[] Examples { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// This file is part of Miunie. | ||
// | ||
// Miunie is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Miunie is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Miunie. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
using Discord.Commands; | ||
using Miunie.Core.Providers; | ||
using Miunie.Discord.Attributes; | ||
using Miunie.Discord.Embeds; | ||
using System.Threading.Tasks; | ||
|
||
namespace Miunie.Discord.CommandModules | ||
{ | ||
[Name("Help")] | ||
public class HelpCommand : ModuleBase<SocketCommandContext> | ||
{ | ||
private readonly CommandHelpProvider _helpProvider; | ||
|
||
public HelpCommand(CommandService commandService, ILanguageProvider lang) | ||
{ | ||
_helpProvider = new CommandHelpProvider(commandService, lang); | ||
} | ||
|
||
[Command("help")] | ||
[Summary("I'm here for you.")] | ||
[Examples("help")] | ||
public async Task GetHelp() | ||
{ | ||
var helpResult = _helpProvider.ForAllCommands(); | ||
_ = await Context.Channel.SendMessageAsync(embed: EmbedConstructor.CreateHelpEmbed(helpResult)); | ||
} | ||
|
||
[Command("help")] | ||
[Summary("Gets help for a specified command.")] | ||
[Examples("help repo")] | ||
public async Task GetHelp([Remainder]string input) | ||
{ | ||
var helpResult = _helpProvider.FromInput(input); | ||
_ = await Context.Channel.SendMessageAsync(embed: EmbedConstructor.CreateHelpEmbed(helpResult)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.