New usage format for command strings.

This commit is contained in:
Master Kwoth 2017-09-18 09:24:42 +02:00
parent 64523b95e6
commit e12c29dda5
6 changed files with 1355 additions and 422 deletions

View File

@ -1,14 +1,24 @@
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Discord.Commands; using Discord.Commands;
using NadekoBot.Services.Impl; using NadekoBot.Services.Impl;
using System.Linq;
using Discord;
namespace NadekoBot.Common.Attributes namespace NadekoBot.Common.Attributes
{ {
public class Usage : RemarksAttribute public class Usage : RemarksAttribute
{ {
public Usage([CallerMemberName] string memberName="") : base(Localization.LoadCommand(memberName.ToLowerInvariant()).Usage) public Usage([CallerMemberName] string memberName="") : base(Usage.GetUsage(memberName))
{ {
} }
public static string GetUsage(string memberName)
{
var usage = Localization.LoadCommand(memberName.ToLowerInvariant()).Usage;
return string.Join(" or ", usage
.Select(x => Format.Code(x)));
}
} }
} }

View File

@ -3,7 +3,7 @@
public class CommandData public class CommandData
{ {
public string Cmd { get; set; } public string Cmd { get; set; }
public string Usage { get; set; }
public string Desc { get; set; } public string Desc { get; set; }
public string[] Usage { get; set; }
} }
} }

View File

@ -56,7 +56,7 @@ namespace NadekoBot.Modules.Gambling
switch (e) switch (e)
{ {
case CurrencyEvent.Reaction: case CurrencyEvent.Reaction:
await reactionEvent(Context, arg).ConfigureAwait(false); await ReactionEvent(Context, arg).ConfigureAwait(false);
break; break;
case CurrencyEvent.SneakyGameStatus: case CurrencyEvent.SneakyGameStatus:
await SneakyGameStatusEvent(Context, arg).ConfigureAwait(false); await SneakyGameStatusEvent(Context, arg).ConfigureAwait(false);
@ -128,7 +128,7 @@ namespace NadekoBot.Modules.Gambling
return Task.CompletedTask; return Task.CompletedTask;
} }
public async Task reactionEvent(ICommandContext context, int amount) public async Task ReactionEvent(ICommandContext context, int amount)
{ {
if (amount <= 0) if (amount <= 0)
amount = 100; amount = 100;

View File

@ -61,6 +61,17 @@ namespace NadekoBot
if (shardId < 0) if (shardId < 0)
throw new ArgumentOutOfRangeException(nameof(shardId)); throw new ArgumentOutOfRangeException(nameof(shardId));
//var obj = JsonConvert.DeserializeObject<Dictionary<string, CommandData2>>(File.ReadAllText("./data/command_strings.json"))
// .ToDictionary(x => x.Key, x => new CommandData2
// {
// Cmd = x.Value.Cmd,
// Desc = x.Value.Desc,
// Usage = x.Value.Usage.Select(y => y.Substring(1, y.Length - 2)).ToArray(),
// });
//File.WriteAllText("./data/command_strings.json", JsonConvert.SerializeObject(obj, Formatting.Indented));
LogSetup.SetupLogger(); LogSetup.SetupLogger();
_log = LogManager.GetCurrentClassLogger(); _log = LogManager.GetCurrentClassLogger();
TerribleElevatedPermissionCheck(); TerribleElevatedPermissionCheck();

View File

@ -137,7 +137,7 @@ namespace NadekoBot.Services.Impl
{ {
Cmd = key, Cmd = key,
Desc = key, Desc = key,
Usage = key, Usage = new[] { key },
}; };
return toReturn; return toReturn;

File diff suppressed because it is too large Load Diff