.sad, .smch now persist restarts. .usmch added to unset music channel, since destroying a player won't reset it, Added --start-delay option for .race command
This commit is contained in:
@ -10,6 +10,8 @@ using NadekoBot.Common.Attributes;
|
||||
using NadekoBot.Modules.Gambling.Common.AnimalRacing.Exceptions;
|
||||
using NadekoBot.Modules.Gambling.Common.AnimalRacing;
|
||||
using NadekoBot.Modules.Gambling.Services;
|
||||
using NadekoBot.Core.Modules.Gambling.Common.AnimalRacing;
|
||||
using CommandLine;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling
|
||||
{
|
||||
@ -33,9 +35,13 @@ namespace NadekoBot.Modules.Gambling
|
||||
|
||||
[NadekoCommand, Usage, Description, Aliases]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public Task Race()
|
||||
public Task Race(params string[] args)
|
||||
{
|
||||
var ar = new AnimalRace(_cs, _bc.BotConfig.RaceAnimals.Shuffle().ToArray());
|
||||
var options = new RaceOptions();
|
||||
var res = Parser.Default.ParseArguments<RaceOptions>(args);
|
||||
res.MapResult(x => options, x => options);
|
||||
|
||||
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"));
|
||||
|
||||
|
@ -9,6 +9,7 @@ using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using NadekoBot.Core.Modules.Gambling.Common.AnimalRacing;
|
||||
|
||||
namespace NadekoBot.Modules.Gambling.Common.AnimalRacing
|
||||
{
|
||||
@ -36,12 +37,15 @@ namespace NadekoBot.Modules.Gambling.Common.AnimalRacing
|
||||
private readonly SemaphoreSlim _locker = new SemaphoreSlim(1, 1);
|
||||
private readonly HashSet<AnimalRacingUser> _users = new HashSet<AnimalRacingUser>();
|
||||
private readonly CurrencyService _currency;
|
||||
private readonly RaceOptions _options;
|
||||
private readonly Queue<RaceAnimal> _animalsQueue;
|
||||
public int MaxUsers { get; }
|
||||
|
||||
public AnimalRace(CurrencyService currency, RaceAnimal[] availableAnimals)
|
||||
public AnimalRace(RaceOptions options, CurrencyService currency, RaceAnimal[] availableAnimals)
|
||||
{
|
||||
NormalizeOptions(options);
|
||||
this._currency = currency;
|
||||
this._options = options;
|
||||
this._animalsQueue = new Queue<RaceAnimal>(availableAnimals);
|
||||
this.MaxUsers = availableAnimals.Length;
|
||||
|
||||
@ -49,11 +53,17 @@ 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(_startingDelayMiliseconds).ConfigureAwait(false);
|
||||
await Task.Delay(_options.StartDelay * 1000).ConfigureAwait(false);
|
||||
|
||||
await _locker.WaitAsync().ConfigureAwait(false);
|
||||
try
|
||||
|
@ -0,0 +1,10 @@
|
||||
using CommandLine;
|
||||
|
||||
namespace NadekoBot.Core.Modules.Gambling.Common.AnimalRacing
|
||||
{
|
||||
public class RaceOptions
|
||||
{
|
||||
[Option("start-delay", Default = 20, Required = false)]
|
||||
public int StartDelay { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user