.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)
This commit is contained in:
Toastie (DCS Team) 2024-11-07 19:04:47 +13:00
parent 04a22e5995
commit 11ed2aaba8
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
5 changed files with 98 additions and 22 deletions

View file

@ -354,11 +354,16 @@ public partial class Gambling : GamblingModule<GamblingService>
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();
}

View file

@ -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]

View file

@ -318,25 +318,20 @@ public class WaifuService : IEService, IReadyExecutor
private static TypedKey<long> 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<WaifuInfo>().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<bool> GiftWaifuAsync(
@ -630,4 +625,38 @@ public class WaifuService : IEService, IReadyExecutor
.FirstOrDefault())
.ToListAsyncEF();
}
public async Task<IReadOnlyCollection<WaifuClaimsResult>> GetClaimsAsync(ulong userId, int page)
{
await using var ctx = _db.GetDbContext();
var wid = ctx.GetTable<DiscordUser>()
.Where(x => x.UserId == userId)
.Select(x => x.Id)
.FirstOrDefault();
if (wid == 0)
return [];
return await ctx.GetTable<WaifuInfo>()
.Where(x => x.ClaimerId == wid)
.LeftJoin(ctx.GetTable<DiscordUser>(),
(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;
}

View file

@ -863,6 +863,11 @@ affinity:
waifuclaim:
- waifuclaim
- claim
- wc
waifuclaims:
- waifuclaims
- claims
- wcs
waifureset:
- waifureset
waifutransfer:

View file

@ -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: