Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Create Help Command and Refactor #275

Merged
merged 16 commits into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Miunie.Avalonia/Miunie.Avalonia.csproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>8.0</LangVersion>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<CodeAnalysisRuleSet>../.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
Expand All @@ -16,9 +16,9 @@
<AvaloniaResource Include="Assets\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="0.9.0" />
<PackageReference Include="Avalonia.Desktop" Version="0.9.0" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.9.0" />
<PackageReference Include="Avalonia" Version="0.9.3" />
<PackageReference Include="Avalonia.Desktop" Version="0.9.3" />
<PackageReference Include="Avalonia.ReactiveUI" Version="0.9.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
2 changes: 1 addition & 1 deletion src/Miunie.ConsoleApp/Miunie.ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 8 additions & 4 deletions src/Miunie.Core.XUnit.Tests/Miunie.Core.XUnit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@

<IsPackable>false</IsPackable>
<CodeAnalysisRuleSet>../.ruleset</CodeAnalysisRuleSet>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="Moq" Version="4.13.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
5 changes: 5 additions & 0 deletions src/Miunie.Core/Entities/PhraseKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum PhraseKey
SHOW_REMOTE_REPO,
USER_EMBED_TITLE,
USER_EMBED_NAME_TITLE,
USER_EMBED_HELP_TITLE,
USER_EMBED_IS_BOT,
USER_EMBED_IS_HUMAN,
USER_EMBED_REALNESS_TITLE,
Expand Down Expand Up @@ -54,6 +55,10 @@ public enum PhraseKey
INCORRECT_VERB,
REPUTATION_TAKEN_BOT,
REPUTATION_GIVEN_BOT,
HELP_EXAMPLE_EMPTY,
HELP_EXAMPLE_TITLE,
HELP_SUMMARY_EMPTY,
HELP_SUMMARY_TITLE,
GPL3_NOTICE
}
}
4 changes: 2 additions & 2 deletions src/Miunie.Core/Miunie.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.1</TargetFramework>
<CodeAnalysisRuleSet>../.ruleset</CodeAnalysisRuleSet>
<LangVersion>8.0</LangVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
45 changes: 45 additions & 0 deletions src/Miunie.Core/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/Miunie.Core/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,22 @@ Source code available at: {1}</value>
<value>**ABOUT THIS SERVER**</value>
<comment>No formatting options.</comment>
</data>
<data name="HELP_EXAMPLE_EMPTY" xml:space="preserve">
<value>No examples were provided.</value>
<comment>No formatting options.</comment>
</data>
<data name="HELP_EXAMPLE_TITLE" xml:space="preserve">
<value>**Examples**: </value>
<comment>No formatting options.</comment>
</data>
<data name="HELP_SUMMARY_EMPTY" xml:space="preserve">
<value>No summary was provided.</value>
<comment>No formatting options.</comment>
</data>
<data name="HELP_SUMMARY_TITLE" xml:space="preserve">
<value>**Summary**: </value>
<comment>No formatting options.</comment>
</data>
<data name="INCORRECT_VERB" xml:space="preserve">
<value>You better start making sense with other than '{0}'{{OR}}
Come again, I don't understand '{0}'{{OR}}
Expand Down Expand Up @@ -258,6 +274,10 @@ What are you trying to say with {0} {1}</value>
<value>:calendar_spiral: Creation date</value>
<comment>No formatting options.</comment>
</data>
<data name="USER_EMBED_HELP_TITLE" xml:space="preserve">
<value>**HELP MENU**</value>
<comment>No formatting options.</comment>
</data>
<data name="USER_EMBED_IS_BOT" xml:space="preserve">
<value>_A software person._{{OR}}
_A bot._ :robot:{{OR}}
Expand Down
1 change: 0 additions & 1 deletion src/Miunie.Discord/Adapters/DiscordMessagesAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
// along with Miunie. If not, see <https://www.gnu.org/licenses/>.

using Discord.WebSocket;
using Miunie.Core;
using Miunie.Core.Discord;
using Miunie.Core.Entities;
using Miunie.Core.Entities.Discord;
Expand Down
30 changes: 30 additions & 0 deletions src/Miunie.Discord/Attributes/ExamplesAttribute.cs
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; }
}
}
4 changes: 4 additions & 0 deletions src/Miunie.Discord/CommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Miunie.Core.Configuration;
using Miunie.Core.Entities.Discord;
using Miunie.Core.Logging;
using Miunie.Core.Providers;
using Miunie.Discord.Convertors;
using Miunie.Discord.TypeReaders;
using System;
Expand Down Expand Up @@ -53,6 +54,9 @@ public async Task InitializeAsync()
_ = await _commandService.AddModulesAsync(Assembly.GetExecutingAssembly(), _services);
}

public HelpService GetHelpService(ILanguageProvider lang)
=> new HelpService(_commandService, lang);

private async Task HandleCommandAsync(SocketMessage s)
{
if (_botConfig.CommandsEnabled == false)
Expand Down
46 changes: 46 additions & 0 deletions src/Miunie.Discord/CommandModules/HelpCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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 System.Threading.Tasks;

namespace Miunie.Discord.CommandModules
{
[Name("Help")]
public class HelpCommand : ModuleBase<SocketCommandContext>
{
private readonly HelpService _helpService;

public HelpCommand(CommandHandler commandHandler, ILanguageProvider lang)
{
_helpService = commandHandler.GetHelpService(lang);
}

[Command("help")]
[Summary("HELP_HELP")]
public async Task GetHelp()
{
await _helpService.ShowDefaultHelpAsync(Context.Channel);
}

[Command("help")]
[Summary("HELP_HELP_SEARCH")]
public async Task GetHelp([Remainder]string input)
{
await _helpService.ShowCommandHelpAsync(Context.Channel, input);
}
}
}
2 changes: 2 additions & 0 deletions src/Miunie.Discord/CommandModules/MiscCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace Miunie.Discord.CommandModules
{
[Name("Misc")]
public class MiscCommands : ModuleBase<SocketCommandContext>
{
private readonly MiscService _service;
Expand All @@ -33,6 +34,7 @@ public MiscCommands(MiscService service, EntityConvertor entityConvertor)
}

[Command("what do you think?")]
[Summary("HELP_WHAT_DO_YOU_THINK")]
public async Task SendRandomYesNoMaybeAnswer()
{
var c = _entityConvertor.ConvertChannel(Context.Channel as SocketGuildChannel);
Expand Down
7 changes: 7 additions & 0 deletions src/Miunie.Discord/CommandModules/ProfileCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace Miunie.Discord.CommandModules
{
[Name("Profile")]
public class ProfileCommand : ModuleBase<SocketCommandContext>
{
private readonly EntityConvertor _entityConvertor;
Expand All @@ -34,6 +35,7 @@ public ProfileCommand(EntityConvertor entityConvertor, ProfileService profileSer
}

[Command("profile")]
[Summary("HELP_PROFILE")]
public async Task ShowProfileAsync(MiunieUser user = null)
{
if (user is null)
Expand All @@ -46,6 +48,7 @@ public async Task ShowProfileAsync(MiunieUser user = null)
}

[Command("rep log")]
[Summary("HELP_REP_LOG")]
public async Task ShowReputationLogAsync(int page = 1)
{
var source = _entityConvertor.ConvertUser(Context.User as SocketGuildUser);
Expand All @@ -54,6 +57,7 @@ public async Task ShowReputationLogAsync(int page = 1)
}

[Command("rep log for")]
[Summary("HELP_REP_LOG_FOR")]
public async Task ShowReputationLogAsync(MiunieUser user, int page = 1)
{
var source = _entityConvertor.ConvertUser(Context.User as SocketGuildUser);
Expand All @@ -62,6 +66,7 @@ public async Task ShowReputationLogAsync(MiunieUser user, int page = 1)
}

[Command("+rep")]
[Summary("HELP_PLUS_REP")]
public async Task AddReputationAsync(MiunieUser user)
{
var source = _entityConvertor.ConvertUser(Context.User as SocketGuildUser);
Expand All @@ -70,6 +75,7 @@ public async Task AddReputationAsync(MiunieUser user)
}

[Command("-rep")]
[Summary("HELP_MINUS_REP")]
public async Task RemoveReputationAsync(MiunieUser user)
{
var source = _entityConvertor.ConvertUser(Context.User as SocketGuildUser);
Expand All @@ -78,6 +84,7 @@ public async Task RemoveReputationAsync(MiunieUser user)
}

[Command("guild")]
[Summary("HELP_GUILD")]
public async Task ShowGuildInfoAsync()
{
var guild = _entityConvertor.ConvertGuild(Context.Guild);
Expand Down
3 changes: 2 additions & 1 deletion src/Miunie.Discord/CommandModules/RemoteRepositoryCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace Miunie.Discord.CommandModules
{
[Name("Remote Repository")]
public class RemoteRepositoryCommand : ModuleBase<SocketCommandContext>
{
private readonly RemoteRepositoryService _remoteRepoService;
Expand All @@ -33,7 +34,7 @@ public RemoteRepositoryCommand(RemoteRepositoryService remoteRepoService, Entity
}

[Command("repo")]
[Summary("Shows the official remote repository hosting the code of this bot")]
[Summary("HELP_REPO")]
public async Task ShowRepository()
{
var channel = _entityConvertor.ConvertChannel(Context.Channel as SocketGuildChannel);
Expand Down
Loading