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 8 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
8 changes: 4 additions & 4 deletions src/Miunie.Avalonia/Miunie.Avalonia.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
<CodeAnalysisRuleSet>../.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
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
4 changes: 2 additions & 2 deletions src/Miunie.ConsoleApp/Miunie.ConsoleApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<LangVersion>8.0</LangVersion>
<CodeAnalysisRuleSet>../.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<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
13 changes: 8 additions & 5 deletions src/Miunie.Core.XUnit.Tests/Miunie.Core.XUnit.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>

<IsPackable>false</IsPackable>
<CodeAnalysisRuleSet>../.ruleset</CodeAnalysisRuleSet>
<LangVersion>8.0</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
}
}
51 changes: 51 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.

26 changes: 26 additions & 0 deletions src/Miunie.Core/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,28 @@ 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>You'll figure it out.{{OR}}
You know what? I've never used this command.{{OR}}
Yeah, you're on your own with this one, buddy.{{OR}}
I got nothing here.{{OR}}
Just mess around with this, you'll figure it out eventually.</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>This is kind of difficult to explain...{{OR}}
How am I supposed to put this into words?{{OR}}
It's a command, I think? Not sure.</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 +280,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 HelpCommandProvider GetHelpProvider(ILanguageProvider lang)
=> new HelpCommandProvider(_commandService, lang);

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

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

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

[Command("help")]
[Summary("I'm here for you.")]
[Examples("help")]
public async Task GetHelp()
{
await _helpService.ShowDefaultHelpAsync(Context.Channel);
}

[Command("help")]
[Summary("Gets help for a specified command.")]
[Examples("help repo")]
public async Task GetHelp([Remainder]string input)
{
await _helpService.ShowCommandHelpAsync(Context.Channel, input);
}
}
}
4 changes: 4 additions & 0 deletions src/Miunie.Discord/CommandModules/MiscCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
using Discord.Commands;
using Discord.WebSocket;
using Miunie.Core;
using Miunie.Discord.Attributes;
using Miunie.Discord.Convertors;
using System.Threading.Tasks;

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

[Command("what do you think?")]
[Summary("What do I think? I guess you'll have to find out~")]
[Examples("what do you think?")]
public async Task SendRandomYesNoMaybeAnswer()
{
var c = _entityConvertor.ConvertChannel(Context.Channel as SocketGuildChannel);
Expand Down
14 changes: 14 additions & 0 deletions src/Miunie.Discord/CommandModules/ProfileCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
using Discord.WebSocket;
using Miunie.Core;
using Miunie.Core.Entities.Discord;
using Miunie.Discord.Attributes;
using Miunie.Discord.Convertors;
using System.Threading.Tasks;

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

[Command("profile")]
[Summary("Pull up a dank profile!")]
[Examples("profile", "profile @Miunie")]
public async Task ShowProfileAsync(MiunieUser user = null)
{
if (user is null)
Expand All @@ -46,6 +50,8 @@ public async Task ShowProfileAsync(MiunieUser user = null)
}

[Command("rep log")]
[Summary("Pull up your current reputation log~")]
[Examples("rep log", "rep log 1")]
public async Task ShowReputationLogAsync(int page = 1)
{
var source = _entityConvertor.ConvertUser(Context.User as SocketGuildUser);
Expand All @@ -54,6 +60,8 @@ public async Task ShowReputationLogAsync(int page = 1)
}

[Command("rep log for")]
[Summary("Pull up a reputation log for the specified user!")]
[Examples("rep log for @Miunie", "rep log for @Mackie 1")]
public async Task ShowReputationLogAsync(MiunieUser user, int page = 1)
{
var source = _entityConvertor.ConvertUser(Context.User as SocketGuildUser);
Expand All @@ -62,6 +70,8 @@ public async Task ShowReputationLogAsync(MiunieUser user, int page = 1)
}

[Command("+rep")]
[Summary("Give a good ol' positive reputation for a user!")]
[Examples("+rep @Miunie")]
public async Task AddReputationAsync(MiunieUser user)
{
var source = _entityConvertor.ConvertUser(Context.User as SocketGuildUser);
Expand All @@ -70,6 +80,8 @@ public async Task AddReputationAsync(MiunieUser user)
}

[Command("-rep")]
[Summary("Give a cold-blooded negative reputation for a user...")]
[Examples("-rep @You")]
public async Task RemoveReputationAsync(MiunieUser user)
{
var source = _entityConvertor.ConvertUser(Context.User as SocketGuildUser);
Expand All @@ -78,6 +90,8 @@ public async Task RemoveReputationAsync(MiunieUser user)
}

[Command("guild")]
[Summary("Pull up information about this guild.")]
[Examples("guild")]
public async Task ShowGuildInfoAsync()
{
var guild = _entityConvertor.ConvertGuild(Context.Guild);
Expand Down
Loading