Draw commands done

This commit is contained in:
Kwoth 2017-02-15 11:17:55 +01:00
parent 45f69bac58
commit 5ed0ee4ef8
3 changed files with 38 additions and 9 deletions

View File

@ -4,8 +4,6 @@ using ImageSharp;
using NadekoBot.Attributes;
using NadekoBot.Extensions;
using NadekoBot.Modules.Gambling.Models;
using NLog;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
@ -19,15 +17,15 @@ namespace NadekoBot.Modules.Gambling
[Group]
public class DrawCommands : NadekoSubmodule
{
private static readonly ConcurrentDictionary<IGuild, Cards> AllDecks = new ConcurrentDictionary<IGuild, Cards>();
private static readonly ConcurrentDictionary<IGuild, Cards> _allDecks = new ConcurrentDictionary<IGuild, Cards>();
private const string cardsPath = "data/images/cards";
private const string _cardsPath = "data/images/cards";
[NadekoCommand, Usage, Description, Aliases]
[RequireContext(ContextType.Guild)]
public async Task Draw(int num = 1)
{
var cards = AllDecks.GetOrAdd(Context.Guild, (s) => new Cards());
var cards = _allDecks.GetOrAdd(Context.Guild, (s) => new Cards());
var images = new List<Image>();
var cardObjects = new List<Cards.Card>();
if (num > 5) num = 5;
@ -35,12 +33,19 @@ namespace NadekoBot.Modules.Gambling
{
if (cards.CardPool.Count == 0 && i != 0)
{
try { await Context.Channel.SendErrorAsync("No more cards in a deck.").ConfigureAwait(false); } catch { }
try
{
await ReplyErrorLocalized("no_more_cards").ConfigureAwait(false);
}
catch
{
// ignored
}
break;
}
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();
@ -59,7 +64,7 @@ namespace NadekoBot.Modules.Gambling
{
//var channel = (ITextChannel)Context.Channel;
AllDecks.AddOrUpdate(Context.Guild,
_allDecks.AddOrUpdate(Context.Guild,
(g) => new Cards(),
(g, c) =>
{
@ -67,7 +72,7 @@ namespace NadekoBot.Modules.Gambling
return c;
});
await Context.Channel.SendConfirmAsync("Deck reshuffled.").ConfigureAwait(false);
await ReplyConfirmLocalized("deck_reshuffled").ConfigureAwait(false);
}
}
}

View File

@ -2108,6 +2108,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Deck reshuffled..
/// </summary>
public static string gambling_deck_reshuffled {
get {
return ResourceManager.GetString("gambling_deck_reshuffled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You guessed it! You won {0}.
/// </summary>
@ -2198,6 +2207,15 @@ namespace NadekoBot.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to No more cards in the deck..
/// </summary>
public static string gambling_no_more_cards {
get {
return ResourceManager.GetString("gambling_no_more_cards", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to You don&apos;t have enough {0}.
/// </summary>

View File

@ -882,6 +882,9 @@ Reason: {1}</value>
<data name="gambling_br_win" xml:space="preserve">
<value>Congratulations! You won {0} for rolling above {1}</value>
</data>
<data name="gambling_deck_reshuffled" xml:space="preserve">
<value>Deck reshuffled.</value>
</data>
<data name="gambling_flipped" xml:space="preserve">
<value>flipped {0}.</value>
<comment>User flipped tails.</comment>
@ -918,6 +921,9 @@ Reason: {1}</value>
<data name="gambling_not_enough" xml:space="preserve">
<value>You don't have enough {0}</value>
</data>
<data name="gambling_no_more_cards" xml:space="preserve">
<value>No more cards in the deck.</value>
</data>
<data name="gambling_raffled_user" xml:space="preserve">
<value>Raffled User</value>
</data>