2016-08-29 22:00:19 +00:00
|
|
|
using Discord;
|
|
|
|
using Discord.Commands;
|
2016-09-14 12:23:09 +00:00
|
|
|
using NadekoBot.Extensions;
|
|
|
|
using NadekoBot.Services;
|
2016-10-20 03:35:00 +00:00
|
|
|
using System;
|
2017-02-04 08:34:51 +00:00
|
|
|
using System.Collections.Generic;
|
2016-09-14 12:23:09 +00:00
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
using NadekoBot.Common;
|
|
|
|
using NadekoBot.Common.Attributes;
|
2016-12-17 04:09:04 +00:00
|
|
|
using Image = ImageSharp.Image;
|
2017-07-18 16:26:55 +00:00
|
|
|
using ImageSharp;
|
2016-08-29 22:00:19 +00:00
|
|
|
|
|
|
|
namespace NadekoBot.Modules.Gambling
|
2016-09-14 12:23:09 +00:00
|
|
|
{
|
|
|
|
public partial class Gambling
|
2016-08-29 22:00:19 +00:00
|
|
|
{
|
2016-09-14 12:23:09 +00:00
|
|
|
[Group]
|
2017-02-15 10:03:40 +00:00
|
|
|
public class FlipCoinCommands : NadekoSubmodule
|
2016-09-14 12:23:09 +00:00
|
|
|
{
|
2017-02-02 20:59:01 +00:00
|
|
|
private readonly IImagesService _images;
|
2017-07-20 03:10:39 +00:00
|
|
|
private readonly IBotConfigProvider _bc;
|
2017-05-29 04:13:22 +00:00
|
|
|
private readonly CurrencyService _cs;
|
2017-02-02 20:59:01 +00:00
|
|
|
|
2017-05-24 20:28:16 +00:00
|
|
|
private readonly NadekoRandom rng = new NadekoRandom();
|
2017-02-02 20:59:01 +00:00
|
|
|
|
2017-07-20 03:10:39 +00:00
|
|
|
public FlipCoinCommands(IImagesService images, CurrencyService cs, IBotConfigProvider bc)
|
2017-02-02 20:59:01 +00:00
|
|
|
{
|
2017-05-24 20:28:16 +00:00
|
|
|
_images = images;
|
|
|
|
_bc = bc;
|
2017-05-29 04:13:22 +00:00
|
|
|
_cs = cs;
|
2017-02-02 20:59:01 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 03:09:44 +00:00
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
2016-12-21 08:33:47 +00:00
|
|
|
public async Task Flip(int count = 1)
|
2016-09-14 12:23:09 +00:00
|
|
|
{
|
|
|
|
if (count == 1)
|
|
|
|
{
|
|
|
|
if (rng.Next(0, 2) == 1)
|
2017-02-04 08:34:51 +00:00
|
|
|
{
|
|
|
|
using (var heads = _images.Heads.ToStream())
|
|
|
|
{
|
2017-05-25 02:24:43 +00:00
|
|
|
await Context.Channel.SendFileAsync(heads, "heads.jpg", Context.User.Mention + " " + GetText("flipped", Format.Bold(GetText("heads")))).ConfigureAwait(false);
|
2017-02-04 08:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-14 12:23:09 +00:00
|
|
|
else
|
2017-02-04 08:34:51 +00:00
|
|
|
{
|
|
|
|
using (var tails = _images.Tails.ToStream())
|
|
|
|
{
|
2017-05-25 02:24:43 +00:00
|
|
|
await Context.Channel.SendFileAsync(tails, "tails.jpg", Context.User.Mention + " " + GetText("flipped", Format.Bold(GetText("tails")))).ConfigureAwait(false);
|
2017-02-04 08:34:51 +00:00
|
|
|
}
|
|
|
|
}
|
2016-09-14 12:23:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (count > 10 || count < 1)
|
|
|
|
{
|
2017-02-15 10:03:40 +00:00
|
|
|
await ReplyErrorLocalized("flip_invalid", 10).ConfigureAwait(false);
|
2016-09-14 12:23:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-07-18 16:26:55 +00:00
|
|
|
var imgs = new Image<Rgba32>[count];
|
2017-02-20 22:46:34 +00:00
|
|
|
for (var i = 0; i < count; i++)
|
2016-09-14 12:23:09 +00:00
|
|
|
{
|
2017-02-20 22:46:34 +00:00
|
|
|
using (var heads = _images.Heads.ToStream())
|
|
|
|
using (var tails = _images.Tails.ToStream())
|
2017-02-04 08:34:51 +00:00
|
|
|
{
|
2017-02-20 22:46:34 +00:00
|
|
|
if (rng.Next(0, 10) < 5)
|
|
|
|
{
|
2017-07-18 16:26:55 +00:00
|
|
|
imgs[i] = Image.Load(heads);
|
2017-02-20 22:46:34 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-18 16:26:55 +00:00
|
|
|
imgs[i] = Image.Load(tails);
|
2017-02-20 22:46:34 +00:00
|
|
|
}
|
2017-02-04 08:34:51 +00:00
|
|
|
}
|
2016-09-14 12:23:09 +00:00
|
|
|
}
|
2017-02-20 22:46:34 +00:00
|
|
|
await Context.Channel.SendFileAsync(imgs.Merge().ToStream(), $"{count} coins.png").ConfigureAwait(false);
|
2016-09-14 12:23:09 +00:00
|
|
|
}
|
|
|
|
|
2017-05-29 04:13:22 +00:00
|
|
|
public enum BetFlipGuess
|
2016-09-14 12:23:09 +00:00
|
|
|
{
|
2017-05-29 04:13:22 +00:00
|
|
|
H = 1,
|
|
|
|
Head = 1,
|
|
|
|
Heads = 1,
|
|
|
|
T = 2,
|
|
|
|
Tail = 2,
|
|
|
|
Tails = 2
|
|
|
|
}
|
2016-08-29 22:00:19 +00:00
|
|
|
|
2017-05-29 04:13:22 +00:00
|
|
|
[NadekoCommand, Usage, Description, Aliases]
|
|
|
|
public async Task Betflip(int amount, BetFlipGuess guess)
|
|
|
|
{
|
2017-07-20 03:10:39 +00:00
|
|
|
if (amount < _bc.BotConfig.MinimumBetAmount)
|
2016-10-24 10:44:28 +00:00
|
|
|
{
|
2017-07-20 03:10:39 +00:00
|
|
|
await ReplyErrorLocalized("min_bet_limit", _bc.BotConfig.MinimumBetAmount + _bc.BotConfig.CurrencySign).ConfigureAwait(false);
|
2016-09-14 12:23:09 +00:00
|
|
|
return;
|
2016-10-24 10:44:28 +00:00
|
|
|
}
|
2017-05-29 04:13:22 +00:00
|
|
|
var removed = await _cs.RemoveAsync(Context.User, "Betflip Gamble", amount, false).ConfigureAwait(false);
|
2016-12-21 11:52:01 +00:00
|
|
|
if (!removed)
|
2016-09-14 12:23:09 +00:00
|
|
|
{
|
2017-07-20 03:10:39 +00:00
|
|
|
await ReplyErrorLocalized("not_enough", _bc.BotConfig.CurrencyPluralName).ConfigureAwait(false);
|
2016-09-14 12:23:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-05-29 04:13:22 +00:00
|
|
|
BetFlipGuess result;
|
2017-02-04 08:34:51 +00:00
|
|
|
IEnumerable<byte> imageToSend;
|
2016-09-14 12:23:09 +00:00
|
|
|
if (rng.Next(0, 2) == 1)
|
|
|
|
{
|
2017-02-02 20:59:01 +00:00
|
|
|
imageToSend = _images.Heads;
|
2017-05-29 04:13:22 +00:00
|
|
|
result = BetFlipGuess.Heads;
|
2016-09-14 12:23:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-02 20:59:01 +00:00
|
|
|
imageToSend = _images.Tails;
|
2017-05-29 04:13:22 +00:00
|
|
|
result = BetFlipGuess.Tails;
|
2016-09-14 12:23:09 +00:00
|
|
|
}
|
2016-08-29 22:00:19 +00:00
|
|
|
|
2016-09-14 12:23:09 +00:00
|
|
|
string str;
|
2017-05-29 04:13:22 +00:00
|
|
|
if (guess == result)
|
2016-10-20 03:35:00 +00:00
|
|
|
{
|
2017-07-20 03:10:39 +00:00
|
|
|
var toWin = (int)Math.Round(amount * _bc.BotConfig.BetflipMultiplier);
|
|
|
|
str = Context.User.Mention + " " + GetText("flip_guess", toWin + _bc.BotConfig.CurrencySign);
|
2017-05-29 04:13:22 +00:00
|
|
|
await _cs.AddAsync(Context.User, "Betflip Gamble", toWin, false).ConfigureAwait(false);
|
2016-09-14 12:23:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-15 10:03:40 +00:00
|
|
|
str = Context.User.Mention + " " + GetText("better_luck");
|
2016-09-14 12:23:09 +00:00
|
|
|
}
|
2017-02-04 08:34:51 +00:00
|
|
|
using (var toSend = imageToSend.ToStream())
|
|
|
|
{
|
|
|
|
await Context.Channel.SendFileAsync(toSend, "result.png", str).ConfigureAwait(false);
|
|
|
|
}
|
2016-09-14 12:23:09 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-29 22:00:19 +00:00
|
|
|
}
|
2016-09-14 12:23:09 +00:00
|
|
|
}
|