From e69776beb1fe6b6d2c3b6f75d7bfd7f0bddf6030 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Sun, 11 Jun 2017 16:07:27 +0200 Subject: [PATCH] .drawnew added --- .../Modules/Gambling/Commands/DrawCommand.cs | 44 +++++++++++++++---- src/NadekoBot/Resources/CommandStrings.resx | 11 ++++- src/NadekoBot/Services/Impl/StatsService.cs | 2 +- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs index 71fc5285..f2fe5f4c 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/DrawCommand.cs @@ -3,6 +3,7 @@ using Discord.Commands; using NadekoBot.Attributes; using NadekoBot.Extensions; using NadekoBot.Modules.Gambling.Models; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; @@ -19,16 +20,15 @@ namespace NadekoBot.Modules.Gambling private static readonly ConcurrentDictionary _allDecks = new ConcurrentDictionary(); private const string _cardsPath = "data/images/cards"; - [NadekoCommand, Usage, Description, Aliases] - [RequireContext(ContextType.Guild)] - public async Task Draw(int num = 1) + + private async Task<(Stream ImageStream, string ToSend)> InternalDraw(int num, ulong? guildId = null) { - if (num < 1) - num = 1; - var cards = _allDecks.GetOrAdd(Context.Guild, (s) => new Cards()); + if (num < 1 || num > 10) + throw new ArgumentOutOfRangeException(nameof(num)); + + Cards cards = guildId == null ? new Cards() : _allDecks.GetOrAdd(Context.Guild, (s) => new Cards()); var images = new List(); var cardObjects = new List(); - if (num > 10) num = 10; for (var i = 0; i < num; i++) { if (cards.CardPool.Count == 0 && i != 0) @@ -45,17 +45,43 @@ namespace NadekoBot.Modules.Gambling } var currentCard = cards.DrawACard(); cardObjects.Add(currentCard); - using (var stream = File.OpenRead(Path.Combine(_cardsPath, currentCard.ToString().ToLowerInvariant()+ ".jpg").Replace(' ','_'))) + using (var stream = File.OpenRead(Path.Combine(_cardsPath, currentCard.ToString().ToLowerInvariant() + ".jpg").Replace(' ', '_'))) images.Add(new Image(stream)); } MemoryStream bitmapStream = new MemoryStream(); images.Merge().Save(bitmapStream); bitmapStream.Position = 0; + var toSend = $"{Context.User.Mention}"; if (cardObjects.Count == 5) toSend += $" drew `{Cards.GetHandValue(cardObjects)}`"; - await Context.Channel.SendFileAsync(bitmapStream, images.Count + " cards.jpg", toSend).ConfigureAwait(false); + return (bitmapStream, toSend); + } + + [NadekoCommand, Usage, Description, Aliases] + [RequireContext(ContextType.Guild)] + public async Task Draw(int num = 1) + { + if (num < 1) + num = 1; + if (num > 10) + num = 10; + + var data = await InternalDraw(num, Context.Guild.Id).ConfigureAwait(false); + await Context.Channel.SendFileAsync(data.ImageStream, num + " cards.jpg", data.ToSend).ConfigureAwait(false); + } + + [NadekoCommand, Usage, Description, Aliases] + public async Task DrawNew(int num = 1) + { + if (num < 1) + num = 1; + if (num > 10) + num = 10; + + var data = await InternalDraw(num).ConfigureAwait(false); + await Context.Channel.SendFileAsync(data.ImageStream, num + " cards.jpg", data.ToSend).ConfigureAwait(false); } [NadekoCommand, Usage, Description, Aliases] diff --git a/src/NadekoBot/Resources/CommandStrings.resx b/src/NadekoBot/Resources/CommandStrings.resx index 962d9312..11efd82c 100644 --- a/src/NadekoBot/Resources/CommandStrings.resx +++ b/src/NadekoBot/Resources/CommandStrings.resx @@ -1174,11 +1174,20 @@ draw - Draws a card from the deck.If you supply number X, she draws up to 5 cards from the deck. + Draws a card from this server's deck. You can draw up to 10 cards by supplying a number of cards to draw. `{0}draw` or `{0}draw 5` + + drawnew + + + Draws a card from the NEW deck of cards. You can draw up to 10 cards by supplying a number of cards to draw. + + + `{0}drawnew` or `{0}drawnew 5` + playlistshuffle plsh diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index 4c0fa5ed..60d7b39c 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -17,7 +17,7 @@ namespace NadekoBot.Services.Impl private readonly IBotCredentials _creds; private readonly DateTime _started; - public const string BotVersion = "1.41.4"; + public const string BotVersion = "1.42"; public string Author => "Kwoth#2560"; public string Library => "Discord.Net";