Added pull again button to slot, fixed a double 'you don't have enough' message

This commit is contained in:
Kwoth
2022-08-09 23:15:27 +02:00
parent e9c7293014
commit e0e4d697c3

View File

@@ -27,12 +27,6 @@ public partial class Gambling
private static decimal totalBet; private static decimal totalBet;
private static decimal totalPaidOut; private static decimal totalPaidOut;
private static readonly ConcurrentHashSet<ulong> _runningUsers = new();
//here is a payout chart
//https://lh6.googleusercontent.com/-i1hjAJy_kN4/UswKxmhrbPI/AAAAAAAAB1U/82wq_4ZZc-Y/DE6B0895-6FC1-48BE-AC4F-14D1B91AB75B.jpg
//thanks to judge for helping me with this
private readonly IImageCache _images; private readonly IImageCache _images;
private readonly FontProvider _fonts; private readonly FontProvider _fonts;
private readonly DbService _db; private readonly DbService _db;
@@ -84,18 +78,13 @@ public partial class Gambling
await ctx.Channel.TriggerTypingAsync(); await ctx.Channel.TriggerTypingAsync();
if (!_runningUsers.Add(ctx.User.Id))
return;
try
{
if (await InternalSlotAsync(amount) is not SlotResult result) if (await InternalSlotAsync(amount) is not SlotResult result)
{ {
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign)); await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
return; return;
} }
var msg = GetSlotMessageInternal(result); var text = GetSlotMessageTextInternal(result);
using var image = await GenerateSlotImageAsync(amount, result); using var image = await GenerateSlotImageAsync(amount, result);
await using var imgStream = await image.ToStreamAsync(); await using var imgStream = await image.ToStreamAsync();
@@ -103,24 +92,20 @@ public partial class Gambling
var eb = _eb.Create(ctx) var eb = _eb.Create(ctx)
.WithAuthor(ctx.User) .WithAuthor(ctx.User)
.WithDescription(Format.Bold(msg)) .WithDescription(Format.Bold(text))
.WithImageUrl($"attachment://result.png") .WithImageUrl($"attachment://result.png")
.WithOkColor(); .WithOkColor();
//new(Emoji.Parse("🔁"), "slot:again", "Pull Again"); var bb = new ButtonBuilder(emote: Emoji.Parse("🔁"), customId: "slot:again", label: "Pull Again");
await ctx.Channel.SendFileAsync(imgStream, var si = new SimpleInteraction<ShmartNumber>(bb, (_, amount) => Slot(amount), amount);
"result.png",
embed: eb.Build()
// components: inter.CreateComponent()
);
// await inter.RunAsync(resMsg); var inter = _inter.Create(ctx.User.Id, si);
} var msg = await ctx.Channel.SendFileAsync(imgStream,
finally "result.png",
{ embed: eb.Build(),
await Task.Delay(1000); components: inter.CreateComponent()
_runningUsers.TryRemove(ctx.User.Id); );
} await inter.RunAsync(msg);
} }
// private SlotInteraction CreateSlotInteractionIntenal(long amount) // private SlotInteraction CreateSlotInteractionIntenal(long amount)
@@ -171,7 +156,7 @@ public partial class Gambling
// }); // });
// } // }
private string GetSlotMessageInternal(SlotResult result) private string GetSlotMessageTextInternal(SlotResult result)
{ {
var multi = result.Multiplier.ToString("0.##"); var multi = result.Multiplier.ToString("0.##");
var msg = result.WinType switch var msg = result.WinType switch
@@ -191,7 +176,6 @@ public partial class Gambling
if (!maybeResult.TryPickT0(out var result, out var error)) if (!maybeResult.TryPickT0(out var result, out var error))
{ {
await ReplyErrorLocalizedAsync(strs.not_enough(CurrencySign));
return null; return null;
} }