fixed captcha cutting off

This commit is contained in:
Toastie 2025-01-31 13:11:19 +13:00
parent 34ba6e782b
commit 491e9b5a6f
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7
2 changed files with 3 additions and 36 deletions

View file

@ -162,7 +162,7 @@ public partial class Gambling : GamblingModule<GamblingService>
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<GamblingService>
await ClaimTimely();
}
private Image<Rgba32> GetPasswordImage(string password)
{
var img = new Image<Rgba32>(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;

View file

@ -16,7 +16,7 @@ public sealed class CaptchaService(FontProvider fonts, IBotCache cache, IPatrona
public Image<Rgba32> GetPasswordImage(string password)
{
var img = new Image<Rgba32>(50, 24);
var img = new Image<Rgba32>(60, 34);
var font = fonts.NotoSans.CreateFont(22);
var outlinePen = new SolidPen(Color.Black, 0.5f);
@ -38,7 +38,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,