diff --git a/NadekoBot.Core/Common/Attributes/NadekoOptions.cs b/NadekoBot.Core/Common/Attributes/NadekoOptions.cs new file mode 100644 index 00000000..5ac1c301 --- /dev/null +++ b/NadekoBot.Core/Common/Attributes/NadekoOptions.cs @@ -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; + } + } +} diff --git a/NadekoBot.Core/Common/Attributes/OwnerOnlyAttribute.cs b/NadekoBot.Core/Common/Attributes/OwnerOnlyAttribute.cs index 25bbe17d..3d58efe2 100644 --- a/NadekoBot.Core/Common/Attributes/OwnerOnlyAttribute.cs +++ b/NadekoBot.Core/Common/Attributes/OwnerOnlyAttribute.cs @@ -7,7 +7,7 @@ namespace NadekoBot.Common.Attributes { public class OwnerOnlyAttribute : PreconditionAttribute { - public override Task CheckPermissions(ICommandContext context, CommandInfo executingCommand, IServiceProvider services) + public override Task CheckPermissionsAsync(ICommandContext context, CommandInfo executingCommand, IServiceProvider services) { var creds = (IBotCredentials)services.GetService(typeof(IBotCredentials)); diff --git a/NadekoBot.Core/Common/NoPublicBotPrecondition.cs b/NadekoBot.Core/Common/NoPublicBotPrecondition.cs index 95f35566..fef0a1a6 100644 --- a/NadekoBot.Core/Common/NoPublicBotPrecondition.cs +++ b/NadekoBot.Core/Common/NoPublicBotPrecondition.cs @@ -6,7 +6,7 @@ namespace NadekoBot.Common { public class NoPublicBot : PreconditionAttribute { - public override Task CheckPermissions(ICommandContext context, CommandInfo command, IServiceProvider services) + public override Task CheckPermissionsAsync(ICommandContext context, CommandInfo command, IServiceProvider services) { #if GLOBAL_NADEKo return Task.FromResult(PreconditionResult.FromError("Not available on the public bot")); diff --git a/NadekoBot.Core/Common/TypeReaders/BotCommandTypeReader.cs b/NadekoBot.Core/Common/TypeReaders/BotCommandTypeReader.cs index 32e4ee6b..43e9ae25 100644 --- a/NadekoBot.Core/Common/TypeReaders/BotCommandTypeReader.cs +++ b/NadekoBot.Core/Common/TypeReaders/BotCommandTypeReader.cs @@ -15,7 +15,7 @@ namespace NadekoBot.Common.TypeReaders { } - public override Task Read(ICommandContext context, string input, IServiceProvider services) + public override Task ReadAsync(ICommandContext context, string input, IServiceProvider services) { var _cmds = ((INServiceProvider)services).GetService(); var _cmdHandler = ((INServiceProvider)services).GetService(); @@ -45,7 +45,7 @@ namespace NadekoBot.Common.TypeReaders _cmds = cmds; } - public override async Task Read(ICommandContext context, string input, IServiceProvider services) + public override async Task 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)); diff --git a/NadekoBot.Core/Common/TypeReaders/GuildDateTimeTypeReader.cs b/NadekoBot.Core/Common/TypeReaders/GuildDateTimeTypeReader.cs index 3103cbf3..91474348 100644 --- a/NadekoBot.Core/Common/TypeReaders/GuildDateTimeTypeReader.cs +++ b/NadekoBot.Core/Common/TypeReaders/GuildDateTimeTypeReader.cs @@ -13,7 +13,7 @@ namespace NadekoBot.Common.TypeReaders { } - public override Task Read(ICommandContext context, string input, IServiceProvider services) + public override Task ReadAsync(ICommandContext context, string input, IServiceProvider services) { var _gts = (GuildTimezoneService)services.GetService(typeof(GuildTimezoneService)); if (!DateTime.TryParse(input, out var dt)) diff --git a/NadekoBot.Core/Common/TypeReaders/GuildTypeReader.cs b/NadekoBot.Core/Common/TypeReaders/GuildTypeReader.cs index cad1a8e4..a6f8c96c 100644 --- a/NadekoBot.Core/Common/TypeReaders/GuildTypeReader.cs +++ b/NadekoBot.Core/Common/TypeReaders/GuildTypeReader.cs @@ -17,7 +17,7 @@ namespace NadekoBot.Common.TypeReaders _client = client; } - public override Task Read(ICommandContext context, string input, IServiceProvider _) + public override Task ReadAsync(ICommandContext context, string input, IServiceProvider _) { input = input.Trim().ToLowerInvariant(); var guilds = _client.Guilds; diff --git a/NadekoBot.Core/Common/TypeReaders/ModuleTypeReader.cs b/NadekoBot.Core/Common/TypeReaders/ModuleTypeReader.cs index e7f49ec7..535e871a 100644 --- a/NadekoBot.Core/Common/TypeReaders/ModuleTypeReader.cs +++ b/NadekoBot.Core/Common/TypeReaders/ModuleTypeReader.cs @@ -17,7 +17,7 @@ namespace NadekoBot.Common.TypeReaders _cmds = cmds; } - public override Task Read(ICommandContext context, string input, IServiceProvider _) + public override Task 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 Read(ICommandContext context, string input, IServiceProvider _) + public override Task 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; diff --git a/NadekoBot.Core/Common/TypeReaders/PermissionActionTypeReader.cs b/NadekoBot.Core/Common/TypeReaders/PermissionActionTypeReader.cs index c9455b98..667fa22b 100644 --- a/NadekoBot.Core/Common/TypeReaders/PermissionActionTypeReader.cs +++ b/NadekoBot.Core/Common/TypeReaders/PermissionActionTypeReader.cs @@ -16,7 +16,7 @@ namespace NadekoBot.Common.TypeReaders { } - public override Task Read(ICommandContext context, string input, IServiceProvider _) + public override Task ReadAsync(ICommandContext context, string input, IServiceProvider _) { input = input.ToUpperInvariant(); switch (input) diff --git a/NadekoBot.Core/Modules/Gambling/AnimalRacingCommands.cs b/NadekoBot.Core/Modules/Gambling/AnimalRacingCommands.cs index 9ec347ac..1a712dd2 100644 --- a/NadekoBot.Core/Modules/Gambling/AnimalRacingCommands.cs +++ b/NadekoBot.Core/Modules/Gambling/AnimalRacingCommands.cs @@ -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(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)); } diff --git a/NadekoBot.Core/Modules/Gambling/Common/AnimalRacing/AnimalRace.cs b/NadekoBot.Core/Modules/Gambling/Common/AnimalRacing/AnimalRace.cs index f00e072b..d05feb96 100644 --- a/NadekoBot.Core/Modules/Gambling/Common/AnimalRacing/AnimalRace.cs +++ b/NadekoBot.Core/Modules/Gambling/Common/AnimalRacing/AnimalRace.cs @@ -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(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 diff --git a/NadekoBot.Core/Modules/Gambling/Common/AnimalRacing/RaceOptions.cs b/NadekoBot.Core/Modules/Gambling/Common/AnimalRacing/RaceOptions.cs index cf13dd17..cf88546a 100644 --- a/NadekoBot.Core/Modules/Gambling/Common/AnimalRacing/RaceOptions.cs +++ b/NadekoBot.Core/Modules/Gambling/Common/AnimalRacing/RaceOptions.cs @@ -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; + } } } \ No newline at end of file diff --git a/NadekoBot.Core/Modules/Help/Services/HelpService.cs b/NadekoBot.Core/Modules/Help/Services/HelpService.cs index 23416b1a..1773510c 100644 --- a/NadekoBot.Core/Modules/Help/Services/HelpService.cs +++ b/NadekoBot.Core/Modules/Help/Services/HelpService.cs @@ -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) => diff --git a/NadekoBot.Core/NadekoBot.Core.csproj b/NadekoBot.Core/NadekoBot.Core.csproj index 6e7cc1d0..81dbc320 100644 --- a/NadekoBot.Core/NadekoBot.Core.csproj +++ b/NadekoBot.Core/NadekoBot.Core.csproj @@ -9,24 +9,24 @@ - + - - - + + + - - - + + + - - - + + + diff --git a/NadekoBot.Core/Services/Database/Repositories/Impl/GuildConfigRepository.cs b/NadekoBot.Core/Services/Database/Repositories/Impl/GuildConfigRepository.cs index 59ee27b7..a1290a8b 100644 --- a/NadekoBot.Core/Services/Database/Repositories/Impl/GuildConfigRepository.cs +++ b/NadekoBot.Core/Services/Database/Repositories/Impl/GuildConfigRepository.cs @@ -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(); /// diff --git a/NadekoBot.Core/Services/Impl/StatsService.cs b/NadekoBot.Core/Services/Impl/StatsService.cs index df9e4740..12c8d618 100644 --- a/NadekoBot.Core/Services/Impl/StatsService.cs +++ b/NadekoBot.Core/Services/Impl/StatsService.cs @@ -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"; diff --git a/src/NadekoBot/_strings/ResponseStrings.en-US.json b/src/NadekoBot/_strings/ResponseStrings.en-US.json index 7707615d..ae2ce42e 100644 --- a/src/NadekoBot/_strings/ResponseStrings.en-US.json +++ b/src/NadekoBot/_strings/ResponseStrings.en-US.json @@ -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", diff --git a/src/NadekoBot/_strings/cmd/command_strings.json b/src/NadekoBot/_strings/cmd/command_strings.json index 250db1ee..0ad251b0 100644 --- a/src/NadekoBot/_strings/cmd/command_strings.json +++ b/src/NadekoBot/_strings/cmd/command_strings.json @@ -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.",