.drawnew added
This commit is contained in:
parent
11250a6d0d
commit
e69776beb1
@ -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<IGuild, Cards> _allDecks = new ConcurrentDictionary<IGuild, Cards>();
|
||||
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<Image>();
|
||||
var cardObjects = new List<Cards.Card>();
|
||||
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]
|
||||
|
@ -1174,11 +1174,20 @@
|
||||
<value>draw</value>
|
||||
</data>
|
||||
<data name="draw_desc" xml:space="preserve">
|
||||
<value>Draws a card from the deck.If you supply number X, she draws up to 5 cards from the deck.</value>
|
||||
<value>Draws a card from this server's deck. You can draw up to 10 cards by supplying a number of cards to draw.</value>
|
||||
</data>
|
||||
<data name="draw_usage" xml:space="preserve">
|
||||
<value>`{0}draw` or `{0}draw 5`</value>
|
||||
</data>
|
||||
<data name="drawnew_cmd" xml:space="preserve">
|
||||
<value>drawnew</value>
|
||||
</data>
|
||||
<data name="drawnew_desc" xml:space="preserve">
|
||||
<value>Draws a card from the NEW deck of cards. You can draw up to 10 cards by supplying a number of cards to draw.</value>
|
||||
</data>
|
||||
<data name="drawnew_usage" xml:space="preserve">
|
||||
<value>`{0}drawnew` or `{0}drawnew 5`</value>
|
||||
</data>
|
||||
<data name="shuffleplaylist_cmd" xml:space="preserve">
|
||||
<value>playlistshuffle plsh</value>
|
||||
</data>
|
||||
|
@ -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";
|
||||
|
Loading…
Reference in New Issue
Block a user