Updated Gambling module

This commit is contained in:
Toastie (DCS Team) 2024-06-27 16:16:52 +12:00
parent f9b21520fb
commit 3181f4dcaa
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
10 changed files with 53 additions and 30 deletions

View file

@ -3,6 +3,7 @@ using EllieBot.Common.TypeReaders;
using EllieBot.Modules.Gambling.Common; using EllieBot.Modules.Gambling.Common;
using EllieBot.Modules.Gambling.Common.Blackjack; using EllieBot.Modules.Gambling.Common.Blackjack;
using EllieBot.Modules.Gambling.Services; using EllieBot.Modules.Gambling.Services;
using EllieBot.Modules.Utility;
namespace EllieBot.Modules.Gambling; namespace EllieBot.Modules.Gambling;

View file

@ -93,7 +93,7 @@ public class Blackjack
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error(ex, "REPORT THE MESSAGE BELOW IN Ellie's Home SERVER PLEASE"); Log.Error(ex, "REPORT THE MESSAGE BELOW IN #NadekoLog SERVER PLEASE");
State = GameState.Ended; State = GameState.Ended;
_ = GameEnded?.Invoke(this); _ = GameEnded?.Invoke(this);
} }

View file

@ -1,7 +1,6 @@
#nullable disable #nullable disable
using LinqToDB; using LinqToDB;
using LinqToDB.EntityFrameworkCore; using LinqToDB.EntityFrameworkCore;
using EllieBot.Db;
using EllieBot.Db.Models; using EllieBot.Db.Models;
using EllieBot.Modules.Gambling.Bank; using EllieBot.Modules.Gambling.Bank;
using EllieBot.Modules.Gambling.Common; using EllieBot.Modules.Gambling.Common;
@ -14,6 +13,7 @@ using System.Text;
using EllieBot.Modules.Gambling.Rps; using EllieBot.Modules.Gambling.Rps;
using EllieBot.Common.TypeReaders; using EllieBot.Common.TypeReaders;
using EllieBot.Modules.Patronage; using EllieBot.Modules.Patronage;
using EllieBot.Modules.Utility;
namespace EllieBot.Modules.Gambling; namespace EllieBot.Modules.Gambling;
@ -27,9 +27,9 @@ public partial class Gambling : GamblingModule<GamblingService>
private readonly DownloadTracker _tracker; private readonly DownloadTracker _tracker;
private readonly GamblingConfigService _configService; private readonly GamblingConfigService _configService;
private readonly IBankService _bank; private readonly IBankService _bank;
private readonly IPatronageService _ps;
private readonly IRemindService _remind; private readonly IRemindService _remind;
private readonly GamblingTxTracker _gamblingTxTracker; private readonly GamblingTxTracker _gamblingTxTracker;
private readonly IPatronageService _ps;
private IUserMessage rdMsg; private IUserMessage rdMsg;
@ -41,8 +41,8 @@ public partial class Gambling : GamblingModule<GamblingService>
DownloadTracker tracker, DownloadTracker tracker,
GamblingConfigService configService, GamblingConfigService configService,
IBankService bank, IBankService bank,
IPatronageService ps,
IRemindService remind, IRemindService remind,
IPatronageService patronage,
GamblingTxTracker gamblingTxTracker) GamblingTxTracker gamblingTxTracker)
: base(configService) : base(configService)
{ {
@ -51,9 +51,9 @@ public partial class Gambling : GamblingModule<GamblingService>
_cs = currency; _cs = currency;
_client = client; _client = client;
_bank = bank; _bank = bank;
_ps = ps;
_remind = remind; _remind = remind;
_gamblingTxTracker = gamblingTxTracker; _gamblingTxTracker = gamblingTxTracker;
_ps = patronage;
_enUsCulture = new CultureInfo("en-US", false).NumberFormat; _enUsCulture = new CultureInfo("en-US", false).NumberFormat;
_enUsCulture.NumberDecimalDigits = 0; _enUsCulture.NumberDecimalDigits = 0;
@ -133,12 +133,6 @@ public partial class Gambling : GamblingModule<GamblingService>
await Response().Embed(embed).SendAsync(); await Response().Embed(embed).SendAsync();
} }
private static readonly FeatureLimitKey _timelyKey = new FeatureLimitKey()
{
Key = "timely:extra_percent",
PrettyName = "Timely"
};
private async Task RemindTimelyAction(SocketMessageComponent smc, DateTime when) private async Task RemindTimelyAction(SocketMessageComponent smc, DateTime when)
{ {
var tt = TimestampTag.FromDateTime(when, TimestampTagStyles.Relative); var tt = TimestampTag.FromDateTime(when, TimestampTagStyles.Relative);
@ -154,6 +148,7 @@ public partial class Gambling : GamblingModule<GamblingService>
await smc.RespondConfirmAsync(_sender, GetText(strs.remind_timely(tt)), ephemeral: true); await smc.RespondConfirmAsync(_sender, GetText(strs.remind_timely(tt)), ephemeral: true);
} }
// Creates timely reminder button, parameter in hours.
private EllieInteractionBase CreateRemindMeInteraction(int period) private EllieInteractionBase CreateRemindMeInteraction(int period)
=> _inter => _inter
.Create(ctx.User.Id, .Create(ctx.User.Id,
@ -163,6 +158,17 @@ public partial class Gambling : GamblingModule<GamblingService>
customId: "timely:remind_me"), customId: "timely:remind_me"),
(smc) => RemindTimelyAction(smc, DateTime.UtcNow.Add(TimeSpan.FromHours(period))) (smc) => RemindTimelyAction(smc, DateTime.UtcNow.Add(TimeSpan.FromHours(period)))
); );
// Creates timely reminder button, parameter in milliseconds.
private EllieInteractionBase CreateRemindMeInteraction(double ms)
=> _inter
.Create(ctx.User.Id,
new ButtonBuilder(
label: "Remind me",
emote: Emoji.Parse("⏰"),
customId: "timely:remind_me"),
(smc) => RemindTimelyAction(smc, DateTime.UtcNow.Add(TimeSpan.FromMilliseconds(ms)))
);
[Cmd] [Cmd]
public async Task Timely() public async Task Timely()
@ -175,25 +181,31 @@ public partial class Gambling : GamblingModule<GamblingService>
return; return;
} }
var inter = CreateRemindMeInteraction(period); if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } remainder)
if (await _service.ClaimTimelyAsync(ctx.User.Id, period) is { } rem)
{ {
// Get correct time form remainder
var interaction = CreateRemindMeInteraction(remainder.TotalMilliseconds);
// Removes timely button if there is a timely reminder in DB // Removes timely button if there is a timely reminder in DB
if (_service.UserHasTimelyReminder(ctx.User.Id)) if (_service.UserHasTimelyReminder(ctx.User.Id))
{ {
inter = null; interaction = null;
} }
var now = DateTime.UtcNow; var now = DateTime.UtcNow;
var relativeTag = TimestampTag.FromDateTime(now.Add(rem), TimestampTagStyles.Relative); var relativeTag = TimestampTag.FromDateTime(now.Add(remainder), TimestampTagStyles.Relative);
await Response().Pending(strs.timely_already_claimed(relativeTag)).Interaction(inter).SendAsync(); await Response().Pending(strs.timely_already_claimed(relativeTag)).Interaction(interaction).SendAsync();
return; return;
} }
var result = await _ps.TryGetFeatureLimitAsync(_timelyKey, ctx.User.Id, 0); var patron = await _ps.GetPatronAsync(ctx.User.Id);
val = (int)(val * (1 + (result.Quota! * 0.01f))); var percentBonus = (_ps.PercentBonus(patron) / 100f);
val += (int)(val * percentBonus);
var inter = CreateRemindMeInteraction(period);
await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim")); await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim"));
@ -892,6 +904,7 @@ public partial class Gambling : GamblingModule<GamblingService>
private static readonly ImmutableArray<string> _emojis = private static readonly ImmutableArray<string> _emojis =
new[] { "⬆", "↖", "⬅", "↙", "⬇", "↘", "➡", "↗" }.ToImmutableArray(); new[] { "⬆", "↖", "⬅", "↙", "⬇", "↘", "➡", "↗" }.ToImmutableArray();
[Cmd] [Cmd]
public async Task LuckyLadder([OverrideTypeReader(typeof(BalanceTypeReader))] long amount) public async Task LuckyLadder([OverrideTypeReader(typeof(BalanceTypeReader))] long amount)
{ {

View file

@ -247,7 +247,14 @@ public partial class Gambling
} }
else else
{ {
var cmd = entry.Command.Replace("%you%", ctx.User.Id.ToString()); var buyer = (IGuildUser)ctx.User;
var cmd = entry.Command
.Replace("%you%", buyer.Mention)
.Replace("%you.mention%", buyer.Mention)
.Replace("%you.username%", buyer.Username)
.Replace("%you.name%", buyer.GlobalName ?? buyer.Username)
.Replace("%you.nick%", buyer.DisplayName);
var eb = _sender.CreateEmbed() var eb = _sender.CreateEmbed()
.WithPendingColor() .WithPendingColor()
.WithTitle("Executing shop command") .WithTitle("Executing shop command")
@ -259,6 +266,7 @@ public partial class Gambling
GetProfitAmount(entry.Price), GetProfitAmount(entry.Price),
new("shop", "sell", entry.Name)); new("shop", "sell", entry.Name));
await Task.Delay(250);
await _cmdHandler.TryRunCommand(guild, await _cmdHandler.TryRunCommand(guild,
channel, channel,
new DoAsUserMessage( new DoAsUserMessage(

View file

@ -9,6 +9,7 @@ using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using EllieBot.Modules.Gambling; using EllieBot.Modules.Gambling;
using EllieBot.Common.TypeReaders; using EllieBot.Common.TypeReaders;
using EllieBot.Modules.Utility;
using Color = SixLabors.ImageSharp.Color; using Color = SixLabors.ImageSharp.Color;
using Image = SixLabors.ImageSharp.Image; using Image = SixLabors.ImageSharp.Image;

View file

@ -5,7 +5,7 @@ public class WaifuInfo : DbEntity
{ {
public int WaifuId { get; set; } public int WaifuId { get; set; }
public DiscordUser Waifu { get; set; } public DiscordUser Waifu { get; set; }
public int? ClaimerId { get; set; } public int? ClaimerId { get; set; }
public DiscordUser Claimer { get; set; } public DiscordUser Claimer { get; set; }

View file

@ -66,12 +66,12 @@ public static class WaifuExtensions
await ctx.Set<WaifuInfo>() await ctx.Set<WaifuInfo>()
.ToLinqToDBTable() .ToLinqToDBTable()
.InsertOrUpdateAsync(() => new() .InsertOrUpdateAsync(() => new()
{ {
AffinityId = null, AffinityId = null,
ClaimerId = null, ClaimerId = null,
Price = 1, Price = 1,
WaifuId = ctx.Set<DiscordUser>().Where(x => x.UserId == userId).Select(x => x.Id).First() WaifuId = ctx.Set<DiscordUser>().Where(x => x.UserId == userId).Select(x => x.Id).First()
}, },
_ => new(), _ => new(),
() => new() () => new()
{ {

View file

@ -1,4 +1,4 @@
#nullable disable #nullable disable
namespace EllieBot.Db.Models; namespace EllieBot.Db.Models;
public class WaifuItem : DbEntity public class WaifuItem : DbEntity

View file

@ -1,4 +1,4 @@
#nullable disable #nullable disable
namespace EllieBot.Db.Models; namespace EllieBot.Db.Models;
public class WaifuUpdate : DbEntity public class WaifuUpdate : DbEntity

View file

@ -34,7 +34,7 @@ public class RollDuelGame
private readonly ICurrencyService _cs; private readonly ICurrencyService _cs;
private readonly Timer _timeoutTimer; private readonly Timer _timeoutTimer;
private readonly EllieRandom _rng = new(); private readonly NadekoRandom _rng = new();
private readonly SemaphoreSlim _locker = new(1, 1); private readonly SemaphoreSlim _locker = new(1, 1);
public RollDuelGame( public RollDuelGame(