Draw commands done
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user