re-added --start-time (-s) to .race, updated libraries, version upped to 2.6.0, added 'options' field to help if command has extra options (only .race atm)
This commit is contained in:
@ -35,12 +35,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
[NadekoOptions(typeof(RaceOptions))]
|
||||
public Task Race(params string[] args)
|
||||
{
|
||||
var options = new RaceOptions();
|
||||
var res = Parser.Default.ParseArguments<RaceOptions>(args);
|
||||
res.MapResult(x => options, x => options);
|
||||
|
||||
options = res.MapResult(x => x, x => options);
|
||||
options.NormalizeOptions();
|
||||
var ar = new AnimalRace(options, _cs, _bc.BotConfig.RaceAnimals.Shuffle().ToArray());
|
||||
if (!_service.AnimalRaces.TryAdd(Context.Guild.Id, ar))
|
||||
return Context.Channel.SendErrorAsync(GetText("animal_race"), GetText("animal_race_already_started"));
|
||||
@ -90,7 +91,7 @@ namespace NadekoBot.Modules.Gambling
|
||||
ar.OnStarted += Ar_OnStarted;
|
||||
_client.MessageReceived += _client_MessageReceived;
|
||||
|
||||
return Context.Channel.SendConfirmAsync(GetText("animal_race"), GetText("animal_race_starting"),
|
||||
return Context.Channel.SendConfirmAsync(GetText("animal_race"), GetText("animal_race_starting", options.StartTime),
|
||||
footer: GetText("animal_race_join_instr", Prefix));
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,6 @@ namespace NadekoBot.Modules.Gambling.Common.AnimalRacing
|
||||
|
||||
public AnimalRace(RaceOptions options, CurrencyService currency, RaceAnimal[] availableAnimals)
|
||||
{
|
||||
NormalizeOptions(options);
|
||||
this._currency = currency;
|
||||
this._options = options;
|
||||
this._animalsQueue = new Queue<RaceAnimal>(availableAnimals);
|
||||
@ -53,17 +52,11 @@ namespace NadekoBot.Modules.Gambling.Common.AnimalRacing
|
||||
CurrentPhase = Phase.Ended;
|
||||
}
|
||||
|
||||
private void NormalizeOptions(RaceOptions options)
|
||||
{
|
||||
if (options.StartDelay < 10 || options.StartDelay > 120)
|
||||
options.StartDelay = 20;
|
||||
}
|
||||
|
||||
public void Initialize() //lame name
|
||||
{
|
||||
var _t = Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(_options.StartDelay * 1000).ConfigureAwait(false);
|
||||
await Task.Delay(_options.StartTime * 1000).ConfigureAwait(false);
|
||||
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
try
|
||||
|
@ -4,7 +4,13 @@ namespace NadekoBot.Core.Modules.Gambling.Common.AnimalRacing
|
||||
{
|
||||
public class RaceOptions
|
||||
{
|
||||
[Option("start-delay", Default = 20, Required = false)]
|
||||
public int StartDelay { get; set; }
|
||||
[Option('s', "start-time", Default = 20, Required = false)]
|
||||
public int StartTime { get; set; } = 20;
|
||||
|
||||
public void NormalizeOptions()
|
||||
{
|
||||
if (this.StartTime < 10 || this.StartTime > 120)
|
||||
this.StartTime = 20;
|
||||
}
|
||||
}
|
||||
}
|
@ -11,6 +11,7 @@ using NadekoBot.Core.Services;
|
||||
using NadekoBot.Core.Services.Impl;
|
||||
using NadekoBot.Common;
|
||||
using NLog;
|
||||
using CommandLine;
|
||||
|
||||
namespace NadekoBot.Modules.Help.Services
|
||||
{
|
||||
@ -56,11 +57,22 @@ namespace NadekoBot.Modules.Help.Services
|
||||
var alias = com.Aliases.Skip(1).FirstOrDefault();
|
||||
if (alias != null)
|
||||
str += string.Format(" **/ `{0}`**", prefix + alias);
|
||||
return new EmbedBuilder()
|
||||
var em = new EmbedBuilder()
|
||||
.AddField(fb => fb.WithName(str).WithValue($"{com.RealSummary(prefix)} {GetCommandRequirements(com, guild)}").WithIsInline(true))
|
||||
.AddField(fb => fb.WithName(GetText("usage", guild)).WithValue(com.RealRemarks(prefix)).WithIsInline(false))
|
||||
.WithFooter(efb => efb.WithText(GetText("module", guild, com.Module.GetTopLevelModule().Name)))
|
||||
.WithColor(NadekoBot.OkColor);
|
||||
|
||||
var opt = (NadekoOptions)com.Attributes.FirstOrDefault(x => x is NadekoOptions);
|
||||
if (opt != null)
|
||||
{
|
||||
var x = Activator.CreateInstance(opt.OptionType);
|
||||
var hs = Parser.Default.FormatCommandLine(x);
|
||||
if(!string.IsNullOrWhiteSpace(hs))
|
||||
em.AddField(GetText("options", guild), string.Join("\n--", hs.Split(" --")), false);
|
||||
}
|
||||
|
||||
return em;
|
||||
}
|
||||
|
||||
public string GetCommandRequirements(CommandInfo cmd, IGuild guild) =>
|
||||
|
Reference in New Issue
Block a user