button for timely
This commit is contained in:
parent
d1bc423b99
commit
7f9a939285
2 changed files with 75 additions and 39 deletions
|
@ -15,11 +15,13 @@ using EllieBot.Modules.Gambling.Rps;
|
||||||
using EllieBot.Common.TypeReaders;
|
using EllieBot.Common.TypeReaders;
|
||||||
using EllieBot.Modules.Patronage;
|
using EllieBot.Modules.Patronage;
|
||||||
using SixLabors.Fonts;
|
using SixLabors.Fonts;
|
||||||
|
using SixLabors.Fonts.Unicode;
|
||||||
using SixLabors.ImageSharp;
|
using SixLabors.ImageSharp;
|
||||||
using SixLabors.ImageSharp.Drawing.Processing;
|
using SixLabors.ImageSharp.Drawing.Processing;
|
||||||
using SixLabors.ImageSharp.PixelFormats;
|
using SixLabors.ImageSharp.PixelFormats;
|
||||||
using SixLabors.ImageSharp.Processing;
|
using SixLabors.ImageSharp.Processing;
|
||||||
using Color = SixLabors.ImageSharp.Color;
|
using Color = SixLabors.ImageSharp.Color;
|
||||||
|
using Random = System.Random;
|
||||||
|
|
||||||
namespace EllieBot.Modules.Gambling;
|
namespace EllieBot.Modules.Gambling;
|
||||||
|
|
||||||
|
@ -60,6 +62,7 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
_remind = remind;
|
_remind = remind;
|
||||||
_gamblingTxTracker = gamblingTxTracker;
|
_gamblingTxTracker = gamblingTxTracker;
|
||||||
_ps = patronage;
|
_ps = patronage;
|
||||||
|
_rng = new EllieRandom();
|
||||||
|
|
||||||
_enUsCulture = new CultureInfo("en-US", false).NumberFormat;
|
_enUsCulture = new CultureInfo("en-US", false).NumberFormat;
|
||||||
_enUsCulture.NumberDecimalDigits = 0;
|
_enUsCulture.NumberDecimalDigits = 0;
|
||||||
|
@ -162,45 +165,57 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
|
|
||||||
if (Config.Timely.RequirePassword)
|
if (Config.Timely.RequirePassword)
|
||||||
{
|
{
|
||||||
var password = _service.GeneratePassword();
|
// var password = _service.GeneratePassword();
|
||||||
|
//
|
||||||
|
// var img = new Image<Rgba32>(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<Rgba32>(100, 40);
|
// await Response()
|
||||||
|
// .Interaction(_inter.Create(ctx.User.Id,new ButtonBuilder("Timely", $"timely:{rng}" Emoji.Parse("⏰")),null))
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } remainder)
|
if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } remainder)
|
||||||
|
@ -814,6 +829,8 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
private static readonly ImmutableArray<string> _emojis =
|
private static readonly ImmutableArray<string> _emojis =
|
||||||
new[] { "⬆", "↖", "⬅", "↙", "⬇", "↘", "➡", "↗" }.ToImmutableArray();
|
new[] { "⬆", "↖", "⬅", "↙", "⬇", "↘", "➡", "↗" }.ToImmutableArray();
|
||||||
|
|
||||||
|
private readonly EllieRandom _rng;
|
||||||
|
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
public async Task LuckyLadder([OverrideTypeReader(typeof(BalanceTypeReader))] long amount)
|
public async Task LuckyLadder([OverrideTypeReader(typeof(BalanceTypeReader))] long amount)
|
||||||
|
|
|
@ -5,6 +5,7 @@ using Microsoft.EntityFrameworkCore;
|
||||||
using EllieBot.Common.ModuleBehaviors;
|
using EllieBot.Common.ModuleBehaviors;
|
||||||
using EllieBot.Db.Models;
|
using EllieBot.Db.Models;
|
||||||
using SixLabors.Fonts;
|
using SixLabors.Fonts;
|
||||||
|
using SixLabors.Fonts.Unicode;
|
||||||
using SixLabors.ImageSharp;
|
using SixLabors.ImageSharp;
|
||||||
using SixLabors.ImageSharp.Drawing.Processing;
|
using SixLabors.ImageSharp.Drawing.Processing;
|
||||||
using SixLabors.ImageSharp.PixelFormats;
|
using SixLabors.ImageSharp.PixelFormats;
|
||||||
|
@ -163,8 +164,26 @@ public class PlantPickService : IEService, IExecNoCommand
|
||||||
new PointF(size.Width + 5, size.Height + 10),
|
new PointF(size.Width + 5, size.Height + 10),
|
||||||
new PointF(0, 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
|
// 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
|
// return image as a stream for easy sending
|
||||||
var format = img.Metadata.DecodedImageFormat;
|
var format = img.Metadata.DecodedImageFormat;
|
||||||
|
|
Loading…
Reference in a new issue