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:
Master Kwoth 2017-11-29 13:53:16 +07:00
parent e266489076
commit 4ab2ac1f1d
17 changed files with 76 additions and 36 deletions

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NadekoBot.Common.Attributes
{
public class NadekoOptions : Attribute
{
public Type OptionType { get; set; }
public NadekoOptions(Type t)
{
this.OptionType = t;
}
}
}

View File

@ -7,7 +7,7 @@ namespace NadekoBot.Common.Attributes
{
public class OwnerOnlyAttribute : PreconditionAttribute
{
public override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo executingCommand, IServiceProvider services)
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo executingCommand, IServiceProvider services)
{
var creds = (IBotCredentials)services.GetService(typeof(IBotCredentials));

View File

@ -6,7 +6,7 @@ namespace NadekoBot.Common
{
public class NoPublicBot : PreconditionAttribute
{
public override Task<PreconditionResult> CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services)
public override Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services)
{
#if GLOBAL_NADEKo
return Task.FromResult(PreconditionResult.FromError("Not available on the public bot"));

View File

@ -15,7 +15,7 @@ namespace NadekoBot.Common.TypeReaders
{
}
public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services)
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
{
var _cmds = ((INServiceProvider)services).GetService<CommandService>();
var _cmdHandler = ((INServiceProvider)services).GetService<CommandHandler>();
@ -45,7 +45,7 @@ namespace NadekoBot.Common.TypeReaders
_cmds = cmds;
}
public override async Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services)
public override async Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
{
input = input.ToUpperInvariant();
@ -67,7 +67,7 @@ namespace NadekoBot.Common.TypeReaders
}
}
var cmd = await new CommandTypeReader(_client, _cmds).Read(context, input, services);
var cmd = await new CommandTypeReader(_client, _cmds).ReadAsync(context, input, services);
if (cmd.IsSuccess)
{
return TypeReaderResult.FromSuccess(new CommandOrCrInfo(((CommandInfo)cmd.Values.First().Value).Name));

View File

@ -13,7 +13,7 @@ namespace NadekoBot.Common.TypeReaders
{
}
public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider services)
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider services)
{
var _gts = (GuildTimezoneService)services.GetService(typeof(GuildTimezoneService));
if (!DateTime.TryParse(input, out var dt))

View File

@ -17,7 +17,7 @@ namespace NadekoBot.Common.TypeReaders
_client = client;
}
public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider _)
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider _)
{
input = input.Trim().ToLowerInvariant();
var guilds = _client.Guilds;

View File

@ -17,7 +17,7 @@ namespace NadekoBot.Common.TypeReaders
_cmds = cmds;
}
public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider _)
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider _)
{
input = input.ToUpperInvariant();
var module = _cmds.Modules.GroupBy(m => m.GetTopLevelModule()).FirstOrDefault(m => m.Key.Name.ToUpperInvariant() == input)?.Key;
@ -37,7 +37,7 @@ namespace NadekoBot.Common.TypeReaders
_cmds = cmds;
}
public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider _)
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider _)
{
input = input.ToLowerInvariant();
var module = _cmds.Modules.GroupBy(m => m.GetTopLevelModule()).FirstOrDefault(m => m.Key.Name.ToLowerInvariant() == input)?.Key;

View File

@ -16,7 +16,7 @@ namespace NadekoBot.Common.TypeReaders
{
}
public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider _)
public override Task<TypeReaderResult> ReadAsync(ICommandContext context, string input, IServiceProvider _)
{
input = input.ToUpperInvariant();
switch (input)

View File

@ -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));
}

View File

@ -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

View File

@ -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;
}
}
}

View File

@ -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) =>

View File

@ -9,24 +9,24 @@
<ItemGroup>
<PackageReference Include="AngleSharp" Version="0.9.9" />
<PackageReference Include="CommandLineParser" Version="2.1.1-beta" />
<PackageReference Include="Discord.Net" Version="2.0.0-alpha-build-00839" />
<PackageReference Include="Discord.Net" Version="2.0.0-beta-00854" />
<PackageReference Include="CoreCLR-NCalc" Version="2.1.3" />
<PackageReference Include="Google.Apis.Urlshortener.v1" Version="1.29.1.138" />
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.29.1.976" />
<PackageReference Include="Google.Apis.Customsearch.v1" Version="1.29.1.896" />
<PackageReference Include="Google.Apis.Urlshortener.v1" Version="1.30.0.138" />
<PackageReference Include="Google.Apis.YouTube.v3" Version="1.30.0.1035" />
<PackageReference Include="Google.Apis.Customsearch.v1" Version="1.30.0.896" />
<PackageReference Include="ImageSharp" Version="1.0.0-alpha9-00194" />
<PackageReference Include="ImageSharp.Drawing" Version="1.0.0-alpha9-00189" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.0.0" />
<PackageReference Include="Microsoft.SyndicationFeed.ReaderWriter" Version="1.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="NLog" Version="5.0.0-beta10" />
<PackageReference Include="Microsoft.SyndicationFeed.ReaderWriter" Version="1.0.2" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.1-beta1" />
<PackageReference Include="NLog" Version="5.0.0-beta11" />
<PackageReference Include="StackExchange.Redis" Version="1.2.6" />
<PackageReference Include="System.ValueTuple" Version="4.4.0" />
</ItemGroup>

View File

@ -51,6 +51,7 @@ namespace NadekoBot.Core.Services.Database.Repositories.Impl
.Include(gc => gc.NsfwBlacklistedTags)
.Include(gc => gc.XpSettings)
.ThenInclude(x => x.ExclusionList)
.Include(gc => gc.MusicSettings)
.ToList();
/// <summary>

View File

@ -21,7 +21,7 @@ namespace NadekoBot.Core.Services.Impl
private readonly IBotCredentials _creds;
private readonly DateTime _started;
public const string BotVersion = "2.5.8";
public const string BotVersion = "2.6.0";
public string Author => "Kwoth#2560";
public string Library => "Discord.Net";

View File

@ -269,6 +269,7 @@
"help_server_permission": "Requires {0} server permission.",
"help_table_of_contents": "Table of contents",
"help_usage": "Usage",
"help_options": "Options",
"nsfw_autohentai_started": "Autohentai started. Reposting every {0}s with one of the following tags:\n{1}",
"nsfw_tag": "Tag",
"gambling_animal_race": "Animal race",
@ -277,7 +278,7 @@
"gambling_animal_race_join": "{0} joined as a {1}",
"gambling_animal_race_join_bet": "{0} joined as a {1} and bet {2}!",
"gambling_animal_race_join_instr": "Type {0}jr to join the race.",
"gambling_animal_race_starting": "Starting in 20 seconds or when the room is full.",
"gambling_animal_race_starting": "Starting in {0} seconds or when the room is full.",
"gambling_animal_race_starting_with_x": "Starting with {0} participants.",
"gambling_animal_race_won": "{0} as {1} Won the race!",
"gambling_animal_race_won_money": "{0} as {1} Won the race and {2}!",
@ -412,6 +413,7 @@
"music_rpl_disabled": "Repeat playlist disabled.",
"music_rpl_enabled": "Repeat playlist enabled.",
"music_set_music_channel": "I will now output playing, finished, paused and removed songs in this channel.",
"music_unset_music_channel": "I will now output playing, finished, paused and removed songs in the channel music was started from.",
"music_skipped_to": "Skipped to `{0}:{1}`",
"music_song_moved": "Song moved",
"music_time_format": "{0}h {1}m {2}s",

View File

@ -2381,6 +2381,13 @@
"{0}smch"
]
},
"unsetmusicchannel": {
"Cmd": "unsetmusicchannel usmch",
"Desc": "Bot will output playing, finished, paused and removed songs to the channel where the first song was queued in.",
"Usage": [
"{0}smch"
]
},
"reloadimages": {
"Cmd": "reloadimages",
"Desc": "Reloads images bot is using. Safe to use even when bot is being used heavily.",