From 11ed2aaba8a7828efd450b0649351ce2511349ee Mon Sep 17 00:00:00 2001 From: Toastie Date: Thu, 7 Nov 2024 19:04:47 +1300 Subject: [PATCH] .divorce no longer has a cooldown Added .waifuclaims / .claims command which lists your waifus (name, price and ids) Timely now shows patreon multiplier bonus if there is any, (alongside boost) --- src/EllieBot/Modules/Gambling/Gambling.cs | 13 +++-- .../Gambling/Waifus/WaifuClaimCommands.cs | 49 +++++++++++++++---- .../Modules/Gambling/Waifus/WaifuService.cs | 47 ++++++++++++++---- src/EllieBot/data/aliases.yml | 5 ++ .../data/strings/commands/commands.en-US.yml | 6 +++ 5 files changed, 98 insertions(+), 22 deletions(-) diff --git a/src/EllieBot/Modules/Gambling/Gambling.cs b/src/EllieBot/Modules/Gambling/Gambling.cs index e49a6b5..358eef2 100644 --- a/src/EllieBot/Modules/Gambling/Gambling.cs +++ b/src/EllieBot/Modules/Gambling/Gambling.cs @@ -354,11 +354,16 @@ public partial class Gambling : GamblingModule await _cs.AddAsync(ctx.User.Id, val, new("timely", "claim")); - if (booster) + var msg = GetText(strs.timely(N(val), period)); + if (booster || percentBonus > float.Epsilon) { - var msg = GetText(strs.timely(N(val), period)) - + "\n\n" - + $"*+{N(Config.BoostBonus.BaseTimelyBonus)} bonus for boosting {userInfo.guild}!*"; + msg += "\n\n"; + if (booster) + msg += $"*+{N(Config.BoostBonus.BaseTimelyBonus)} bonus for boosting {userInfo.guild}!*"; + + if (percentBonus > float.Epsilon) + msg += + $"*+{percentBonus:P0} bonus for the [Patreon](https://patreon.com/elliebot) pledge! <:hart:746995901758832712>*"; await Response().Confirm(msg).Interaction(inter).SendAsync(); } diff --git a/src/EllieBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs b/src/EllieBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs index 9fca94e..12d93e1 100644 --- a/src/EllieBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs +++ b/src/EllieBot/Modules/Gambling/Waifus/WaifuClaimCommands.cs @@ -37,6 +37,45 @@ public partial class Gambling await Response().Error(strs.waifu_reset_fail).SendAsync(); } + [Cmd] + [RequireContext(ContextType.Guild)] + public async Task WaifuClaims() + { + await Response() + .Paginated() + .PageItems(async (page) => await _service.GetClaimsAsync(ctx.User.Id, page)) + .Page((items, page) => + { + var eb = _sender.CreateEmbed() + .WithOkColor() + .WithTitle("Waifus"); + + if (items.Count == 0) + { + eb + .WithPendingColor() + .WithDescription(GetText(strs.empty_page)); + + return eb; + } + + for (var i = 0; i < items.Count; i++) + { + var item = items[i]; + eb.AddField($"`#{(page * 9) + 1 + i}` {N(item.Price)}", + $""" + {item.Username} + ||{item.UserId}|| + """, + true + ); + } + + return eb; + }) + .SendAsync(); + } + [Cmd] [RequireContext(ContextType.Guild)] public async Task WaifuClaim(long amount, [Leftover] IUser target) @@ -144,7 +183,7 @@ public partial class Gambling if (targetId == ctx.User.Id) return; - var (w, result, amount, remaining) = await _service.DivorceWaifuAsync(ctx.User, targetId); + var (w, result, amount) = await _service.DivorceWaifuAsync(ctx.User, targetId); if (result == DivorceResult.SucessWithPenalty) { @@ -157,14 +196,6 @@ public partial class Gambling await Response().Confirm(strs.waifu_divorced_notlike(N(amount))).SendAsync(); else if (result == DivorceResult.NotYourWife) await Response().Error(strs.waifu_not_yours).SendAsync(); - else if (remaining is { } rem) - { - await Response() - .Error(strs.waifu_recent_divorce( - Format.Bold(((int)rem.TotalHours).ToString()), - Format.Bold(rem.Minutes.ToString()))) - .SendAsync(); - } } [Cmd] diff --git a/src/EllieBot/Modules/Gambling/Waifus/WaifuService.cs b/src/EllieBot/Modules/Gambling/Waifus/WaifuService.cs index f99c607..e929ce9 100644 --- a/src/EllieBot/Modules/Gambling/Waifus/WaifuService.cs +++ b/src/EllieBot/Modules/Gambling/Waifus/WaifuService.cs @@ -318,25 +318,20 @@ public class WaifuService : IEService, IReadyExecutor private static TypedKey GetAffinityKey(ulong userId) => new($"waifu:affinity:{userId}"); - public async Task<(WaifuInfo, DivorceResult, long, TimeSpan?)> DivorceWaifuAsync(IUser user, ulong targetId) + public async Task<(WaifuInfo, DivorceResult, long)> DivorceWaifuAsync(IUser user, ulong targetId) { DivorceResult result; - TimeSpan? remaining = null; long amount = 0; WaifuInfo w; await using (var uow = _db.GetDbContext()) { w = uow.Set().ByWaifuUserId(targetId); if (w?.Claimer is null || w.Claimer.UserId != user.Id) + { result = DivorceResult.NotYourWife; + } else { - remaining = await _cache.GetRatelimitAsync(GetDivorceKey(user.Id), 6.Hours()); - if (remaining is TimeSpan rem) - { - result = DivorceResult.Cooldown; - return (w, result, amount, rem); - } amount = w.Price / 2; @@ -369,7 +364,7 @@ public class WaifuService : IEService, IReadyExecutor await uow.SaveChangesAsync(); } - return (w, result, amount, remaining); + return (w, result, amount); } public async Task GiftWaifuAsync( @@ -630,4 +625,38 @@ public class WaifuService : IEService, IReadyExecutor .FirstOrDefault()) .ToListAsyncEF(); } + + public async Task> GetClaimsAsync(ulong userId, int page) + { + await using var ctx = _db.GetDbContext(); + + var wid = ctx.GetTable() + .Where(x => x.UserId == userId) + .Select(x => x.Id) + .FirstOrDefault(); + + if (wid == 0) + return []; + + return await ctx.GetTable() + .Where(x => x.ClaimerId == wid) + .LeftJoin(ctx.GetTable(), + (wi, du) => wi.WaifuId == du.Id, + (wi, du) => new WaifuClaimsResult( + du.Username, + du.UserId, + wi.Price + )) + .OrderByDescending(x => x.Price) + .Skip(page * 9) + .Take(9) + .ToListAsyncLinqToDB(); + } +} + +public sealed class WaifuClaimsResult(string username, ulong userId, long price) +{ + public string Username { get; } = username; + public ulong UserId { get; } = userId; + public long Price { get; } = price; } \ No newline at end of file diff --git a/src/EllieBot/data/aliases.yml b/src/EllieBot/data/aliases.yml index 7f79353..54f6a45 100644 --- a/src/EllieBot/data/aliases.yml +++ b/src/EllieBot/data/aliases.yml @@ -863,6 +863,11 @@ affinity: waifuclaim: - waifuclaim - claim + - wc +waifuclaims: + - waifuclaims + - claims + - wcs waifureset: - waifureset waifutransfer: diff --git a/src/EllieBot/data/strings/commands/commands.en-US.yml b/src/EllieBot/data/strings/commands/commands.en-US.yml index d3918ca..fd9ab58 100644 --- a/src/EllieBot/data/strings/commands/commands.en-US.yml +++ b/src/EllieBot/data/strings/commands/commands.en-US.yml @@ -2738,6 +2738,12 @@ waifuclaim: desc: "The cost of claiming the waifu." target: desc: "The user to whom the claim is being made, allowing the waifu to be claimed from their collection." +waifuclaims: + desc: Shows all of your currently claimed waifus. + ex: + - '' + params: + - { } waifureset: desc: Resets your waifu stats, except current waifus. ex: