From 0fdccea31c3e16dd648d6a361e7b04d0ca66bd8a Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 30 Jan 2025 10:50:26 +0000 Subject: [PATCH] fix: fixed captcha cutting off --- src/NadekoBot/Modules/Gambling/Gambling.cs | 35 +------------------ .../Modules/Games/Fish/CaptchaService.cs | 4 +-- 2 files changed, 3 insertions(+), 36 deletions(-) diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 359c4a528..6b1f9953e 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -162,7 +162,7 @@ public partial class Gambling : GamblingModule if (password is not null) { - var img = GetPasswordImage(password); + var img = _captchaService.GetPasswordImage(password); await using var stream = await img.ToStreamAsync(); var toSend = Response() .File(stream, "timely.png"); @@ -194,39 +194,6 @@ public partial class Gambling : GamblingModule await ClaimTimely(); } - private Image GetPasswordImage(string password) - { - var img = new Image(50, 24); - - var font = _fonts.NotoSans.CreateFont(22); - var outlinePen = new SolidPen(Color.Black, 0.5f); - var strikeoutRun = new RichTextRun - { - Start = 0, - End = password.GetGraphemeCount(), - Font = font, - StrikeoutPen = new SolidPen(Color.White, 4), - 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(25, 12), - TextRuns = [strikeoutRun] - }, - password, - Brushes.Solid(Color.White), - outlinePen); - }); - - return img; - } - private async Task ClaimTimely() { var period = Config.Timely.Cooldown; diff --git a/src/NadekoBot/Modules/Games/Fish/CaptchaService.cs b/src/NadekoBot/Modules/Games/Fish/CaptchaService.cs index eb12d6724..c74d8d537 100644 --- a/src/NadekoBot/Modules/Games/Fish/CaptchaService.cs +++ b/src/NadekoBot/Modules/Games/Fish/CaptchaService.cs @@ -17,7 +17,7 @@ public sealed class CaptchaService(FontProvider fonts, IBotCache cache, IPatrona public Image GetPasswordImage(string password) { - var img = new Image(50, 24); + var img = new Image(60, 34); var font = fonts.NotoSans.CreateFont(22); var outlinePen = new SolidPen(Color.Black, 0.5f); @@ -39,7 +39,7 @@ public sealed class CaptchaService(FontProvider fonts, IBotCache cache, IPatrona HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, FallbackFontFamilies = fonts.FallBackFonts, - Origin = new(25, 12), + Origin = new(30, 15), TextRuns = [strikeoutRun] }, password,