.drawnew added
This commit is contained in:
parent
11250a6d0d
commit
e69776beb1
@ -3,6 +3,7 @@ using Discord.Commands;
|
|||||||
using NadekoBot.Attributes;
|
using NadekoBot.Attributes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using NadekoBot.Modules.Gambling.Models;
|
using NadekoBot.Modules.Gambling.Models;
|
||||||
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -19,16 +20,15 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
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)]
|
private async Task<(Stream ImageStream, string ToSend)> InternalDraw(int num, ulong? guildId = null)
|
||||||
public async Task Draw(int num = 1)
|
|
||||||
{
|
{
|
||||||
if (num < 1)
|
if (num < 1 || num > 10)
|
||||||
num = 1;
|
throw new ArgumentOutOfRangeException(nameof(num));
|
||||||
var cards = _allDecks.GetOrAdd(Context.Guild, (s) => new Cards());
|
|
||||||
|
Cards cards = guildId == null ? new Cards() : _allDecks.GetOrAdd(Context.Guild, (s) => new Cards());
|
||||||
var images = new List<Image>();
|
var images = new List<Image>();
|
||||||
var cardObjects = new List<Cards.Card>();
|
var cardObjects = new List<Cards.Card>();
|
||||||
if (num > 10) num = 10;
|
|
||||||
for (var i = 0; i < num; i++)
|
for (var i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
if (cards.CardPool.Count == 0 && i != 0)
|
if (cards.CardPool.Count == 0 && i != 0)
|
||||||
@ -51,11 +51,37 @@ namespace NadekoBot.Modules.Gambling
|
|||||||
MemoryStream bitmapStream = new MemoryStream();
|
MemoryStream bitmapStream = new MemoryStream();
|
||||||
images.Merge().Save(bitmapStream);
|
images.Merge().Save(bitmapStream);
|
||||||
bitmapStream.Position = 0;
|
bitmapStream.Position = 0;
|
||||||
|
|
||||||
var toSend = $"{Context.User.Mention}";
|
var toSend = $"{Context.User.Mention}";
|
||||||
if (cardObjects.Count == 5)
|
if (cardObjects.Count == 5)
|
||||||
toSend += $" drew `{Cards.GetHandValue(cardObjects)}`";
|
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]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
@ -1174,11 +1174,20 @@
|
|||||||
<value>draw</value>
|
<value>draw</value>
|
||||||
</data>
|
</data>
|
||||||
<data name="draw_desc" xml:space="preserve">
|
<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>
|
||||||
<data name="draw_usage" xml:space="preserve">
|
<data name="draw_usage" xml:space="preserve">
|
||||||
<value>`{0}draw` or `{0}draw 5`</value>
|
<value>`{0}draw` or `{0}draw 5`</value>
|
||||||
</data>
|
</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">
|
<data name="shuffleplaylist_cmd" xml:space="preserve">
|
||||||
<value>playlistshuffle plsh</value>
|
<value>playlistshuffle plsh</value>
|
||||||
</data>
|
</data>
|
||||||
|
@ -17,7 +17,7 @@ namespace NadekoBot.Services.Impl
|
|||||||
private readonly IBotCredentials _creds;
|
private readonly IBotCredentials _creds;
|
||||||
private readonly DateTime _started;
|
private readonly DateTime _started;
|
||||||
|
|
||||||
public const string BotVersion = "1.41.4";
|
public const string BotVersion = "1.42";
|
||||||
|
|
||||||
public string Author => "Kwoth#2560";
|
public string Author => "Kwoth#2560";
|
||||||
public string Library => "Discord.Net";
|
public string Library => "Discord.Net";
|
||||||
|
Loading…
Reference in New Issue
Block a user