From f850d62c89d9051ad5342d0928c2e4bc4f23cc1c Mon Sep 17 00:00:00 2001 From: Kwoth Date: Fri, 3 Feb 2017 11:36:58 +0100 Subject: [PATCH] sneaky game will say a number of rewarded users at the end --- .../Modules/Gambling/Commands/CurrencyEvents.cs | 4 +++- .../Games/Commands/PlantAndPickCommands.cs | 2 +- src/NadekoBot/Services/IImagesService.cs | 3 ++- src/NadekoBot/Services/Impl/ImagesService.cs | 17 ++++++++++++----- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs b/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs index 927f8a72..bea309af 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/CurrencyEvents.cs @@ -78,6 +78,7 @@ namespace NadekoBot.Modules.Gambling _secretCode += _sneakyGameStatusChars[rng.Next(0, _sneakyGameStatusChars.Length)]; } + var game = NadekoBot.Client.Game?.Name; await NadekoBot.Client.SetGameAsync($"type {_secretCode} for " + NadekoBot.BotConfig.CurrencyPluralName) .ConfigureAwait(false); try @@ -94,10 +95,11 @@ namespace NadekoBot.Modules.Gambling await Task.Delay(num * 1000); NadekoBot.Client.MessageReceived -= SneakyGameMessageReceivedEventHandler; + var cnt = _sneakyGameAwardedUsers.Count; _sneakyGameAwardedUsers.Clear(); _secretCode = String.Empty; - await NadekoBot.Client.SetGameAsync($"SneakyGame event ended.") + await NadekoBot.Client.SetGameAsync($"SneakyGame event ended. {cnt} users received a reward.") .ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs index ab40b511..0ae16be6 100644 --- a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs @@ -231,7 +231,7 @@ namespace NadekoBot.Modules.Games private static Tuple GetRandomCurrencyImage() { var rng = new NadekoRandom(); - var images = NadekoBot.Images.CurrencyImages; + var images = NadekoBot.Images.Currency; return images[rng.Next(0, images.Count)]; } diff --git a/src/NadekoBot/Services/IImagesService.cs b/src/NadekoBot/Services/IImagesService.cs index 192ee842..7d98cd06 100644 --- a/src/NadekoBot/Services/IImagesService.cs +++ b/src/NadekoBot/Services/IImagesService.cs @@ -13,7 +13,8 @@ namespace NadekoBot.Services Stream Heads { get; } Stream Tails { get; } - IImmutableList> CurrencyImages { get; } + IImmutableList> Currency { get; } + IImmutableList> Dice { get; } Task Reload(); } diff --git a/src/NadekoBot/Services/Impl/ImagesService.cs b/src/NadekoBot/Services/Impl/ImagesService.cs index f63e2eb5..80898dc1 100644 --- a/src/NadekoBot/Services/Impl/ImagesService.cs +++ b/src/NadekoBot/Services/Impl/ImagesService.cs @@ -19,16 +19,22 @@ namespace NadekoBot.Services.Impl private const string tailsPath = "data/images/coins/tails.png"; private const string currencyImagesPath = "data/currency_images"; + private const string diceImagesPath = "data/images/dice"; private byte[] heads; public Stream Heads => new MemoryStream(heads, false); private byte[] tails; public Stream Tails => new MemoryStream(tails, false); - //todo tuple - private IReadOnlyDictionary currencyImages; - public IImmutableList> CurrencyImages => - currencyImages.Select(x => new Tuple(x.Key, (Stream)new MemoryStream(x.Value, false))) + //todo C#7 + private IReadOnlyDictionary currency; + public IImmutableList> Currency => + currency.Select(x => new Tuple(x.Key, new MemoryStream(x.Value, false))) + .ToImmutableArray(); + + private IReadOnlyDictionary dice; + public IImmutableList> Dice => + dice.Select(x => new Tuple(x.Key, new MemoryStream(x.Value, false))) .ToImmutableArray(); private ImagesService() @@ -52,7 +58,8 @@ namespace NadekoBot.Services.Impl heads = File.ReadAllBytes(headsPath); tails = File.ReadAllBytes(tailsPath); - currencyImages = Directory.GetFiles(currencyImagesPath).ToDictionary(x => Path.GetFileName(x), x => File.ReadAllBytes(x)); + currency = Directory.GetFiles(currencyImagesPath).ToDictionary(x => Path.GetFileName(x), x => File.ReadAllBytes(x)); + dice = Directory.GetFiles(diceImagesPath).ToDictionary(x => Path.GetFileName(x), x => File.ReadAllBytes(x)); _log.Info($"Images loaded after {sw.Elapsed.TotalSeconds:F2}s!"); } catch (Exception ex)