diff --git a/src/EllieBot/Modules/Gambling/Gambling.cs b/src/EllieBot/Modules/Gambling/Gambling.cs index 930c709..eb0026b 100644 --- a/src/EllieBot/Modules/Gambling/Gambling.cs +++ b/src/EllieBot/Modules/Gambling/Gambling.cs @@ -15,11 +15,13 @@ using EllieBot.Modules.Gambling.Rps; using EllieBot.Common.TypeReaders; using EllieBot.Modules.Patronage; using SixLabors.Fonts; +using SixLabors.Fonts.Unicode; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Drawing.Processing; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using Color = SixLabors.ImageSharp.Color; +using Random = System.Random; namespace EllieBot.Modules.Gambling; @@ -60,6 +62,7 @@ public partial class Gambling : GamblingModule _remind = remind; _gamblingTxTracker = gamblingTxTracker; _ps = patronage; + _rng = new EllieRandom(); _enUsCulture = new CultureInfo("en-US", false).NumberFormat; _enUsCulture.NumberDecimalDigits = 0; @@ -162,45 +165,57 @@ public partial class Gambling : GamblingModule if (Config.Timely.RequirePassword) { - var password = _service.GeneratePassword(); + // var password = _service.GeneratePassword(); + // + // var img = new Image(100, 40); + // + // var font = _fonts.NotoSans.CreateFont(30); + // var outlinePen = new SolidPen(Color.Black, 1f); + // var strikeoutRun = new RichTextRun + // { + // Start = 0, + // End = password.GetGraphemeCount(), + // Font = font, + // StrikeoutPen = new SolidPen(Color.White, 3), + // TextDecorations = TextDecorations.Strikeout + // }; + // // draw password on the image + // img.Mutate(x => + // { + // x.DrawText(new RichTextOptions(font) + // { + // HorizontalAlignment = HorizontalAlignment.Center, + // VerticalAlignment = VerticalAlignment.Center, + // FallbackFontFamilies = _fonts.FallBackFonts, + // Origin = new(50, 20), + // TextRuns = [strikeoutRun] + // }, + // password, + // Brushes.Solid(Color.White), + // outlinePen); + // }); + // using var stream = await img.ToStreamAsync(); + // var captcha = await Response() + // .Embed(_sender.CreateEmbed() + // .WithOkColor() + // .WithImageUrl("attachment://timely.png")) + // .File(stream, "timely.png") + // .SendAsync(); + // try + // { + // var userInput = await GetUserInputAsync(ctx.User.Id, ctx.Channel.Id); + // if (userInput?.ToLowerInvariant() != password?.ToLowerInvariant()) + // { + // return; + // } + // } + // finally + // { + // _ = captcha.DeleteAsync(); + // } - var img = new Image(100, 40); - - var font = _fonts.NotoSans.CreateFont(30); - var outlinePen = new SolidPen(Color.Black, 1f); - // draw password on the image - img.Mutate(x => - { - x.DrawText(new RichTextOptions(font) - { - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - FallbackFontFamilies = _fonts.FallBackFonts, - Origin = new(50, 20) - }, - password, - Brushes.Solid(Color.White), - outlinePen); - }); - using var stream = await img.ToStreamAsync(); - var captcha = await Response() - .Embed(_sender.CreateEmbed() - .WithOkColor() - .WithImageUrl("attachment://timely.png")) - .File(stream, "timely.png") - .SendAsync(); - try - { - var userInput = await GetUserInputAsync(ctx.User.Id, ctx.Channel.Id); - if (userInput?.ToLowerInvariant() != password?.ToLowerInvariant()) - { - return; - } - } - finally - { - _ = captcha.DeleteAsync(); - } + // await Response() + // .Interaction(_inter.Create(ctx.User.Id,new ButtonBuilder("Timely", $"timely:{rng}" Emoji.Parse("⏰")),null)) } if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } remainder) @@ -814,6 +829,8 @@ public partial class Gambling : GamblingModule private static readonly ImmutableArray _emojis = new[] { "⬆", "↖", "⬅", "↙", "⬇", "↘", "➡", "↗" }.ToImmutableArray(); + private readonly EllieRandom _rng; + [Cmd] public async Task LuckyLadder([OverrideTypeReader(typeof(BalanceTypeReader))] long amount) diff --git a/src/EllieBot/Modules/Gambling/PlantPick/PlantPickService.cs b/src/EllieBot/Modules/Gambling/PlantPick/PlantPickService.cs index 01dfae0..cd08bf1 100644 --- a/src/EllieBot/Modules/Gambling/PlantPick/PlantPickService.cs +++ b/src/EllieBot/Modules/Gambling/PlantPick/PlantPickService.cs @@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore; using EllieBot.Common.ModuleBehaviors; using EllieBot.Db.Models; using SixLabors.Fonts; +using SixLabors.Fonts.Unicode; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Drawing.Processing; using SixLabors.ImageSharp.PixelFormats; @@ -163,8 +164,26 @@ public class PlantPickService : IEService, IExecNoCommand new PointF(size.Width + 5, size.Height + 10), new PointF(0, size.Height + 10)); + var strikeoutRun = new RichTextRun + { + Start = 0, + End = pass.GetGraphemeCount(), + Font = font, + StrikeoutPen = new SolidPen(Color.White, 5), + TextDecorations = TextDecorations.Strikeout + }; + // draw the password over the background - x.DrawText(pass, font, Color.White, new(0, 0)); + x.DrawText(new RichTextOptions(font) + { + Origin = new(0, 0), + TextRuns = + [ + strikeoutRun + ] + }, + pass, + new SolidBrush(Color.White)); }); // return image as a stream for easy sending var format = img.Metadata.DecodedImageFormat;