added pagination to .curtrs
This commit is contained in:
parent
37986ed0b2
commit
ad472fd52e
2 changed files with 152 additions and 130 deletions
src/EllieBot
|
@ -7,14 +7,23 @@ namespace EllieBot.Db;
|
||||||
|
|
||||||
public static class CurrencyTransactionExtensions
|
public static class CurrencyTransactionExtensions
|
||||||
{
|
{
|
||||||
public static Task<List<CurrencyTransaction>> GetPageFor(
|
public static async Task<IReadOnlyCollection<CurrencyTransaction>> GetPageFor(
|
||||||
this DbSet<CurrencyTransaction> set,
|
this DbSet<CurrencyTransaction> set,
|
||||||
ulong userId,
|
ulong userId,
|
||||||
int page)
|
int page)
|
||||||
=> set.ToLinqToDBTable()
|
{
|
||||||
|
var items = await set.ToLinqToDBTable()
|
||||||
.Where(x => x.UserId == userId)
|
.Where(x => x.UserId == userId)
|
||||||
.OrderByDescending(x => x.DateAdded)
|
.OrderByDescending(x => x.DateAdded)
|
||||||
.Skip(15 * page)
|
.Skip(15 * page)
|
||||||
.Take(15)
|
.Take(15)
|
||||||
.ToListAsyncLinqToDB();
|
.ToListAsyncLinqToDB();
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<int> GetCountFor(this DbSet<CurrencyTransaction> set, ulong userId)
|
||||||
|
=> await set.ToLinqToDBTable()
|
||||||
|
.Where(x => x.UserId == userId)
|
||||||
|
.CountAsyncLinqToDB();
|
||||||
}
|
}
|
|
@ -218,20 +218,20 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
var val = Config.Timely.Amount;
|
var val = Config.Timely.Amount;
|
||||||
var boostGuilds = Config.BoostBonus.GuildIds ?? new();
|
var boostGuilds = Config.BoostBonus.GuildIds ?? new();
|
||||||
var guildUsers = await boostGuilds
|
var guildUsers = await boostGuilds
|
||||||
.Select(async gid =>
|
.Select(async gid =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var guild = await _client.Rest.GetGuildAsync(gid, false);
|
var guild = await _client.Rest.GetGuildAsync(gid, false);
|
||||||
var user = await _client.Rest.GetGuildUserAsync(gid, ctx.User.Id);
|
var user = await _client.Rest.GetGuildUserAsync(gid, ctx.User.Id);
|
||||||
return (guild, user);
|
return (guild, user);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.WhenAll();
|
.WhenAll();
|
||||||
|
|
||||||
var userInfo = guildUsers.FirstOrDefault(x => x.user?.PremiumSince is not null);
|
var userInfo = guildUsers.FirstOrDefault(x => x.user?.PremiumSince is not null);
|
||||||
var booster = userInfo != default;
|
var booster = userInfo != default;
|
||||||
|
@ -296,8 +296,8 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm(strs.timely_set(Format.Bold(N(amount)), Format.Bold(period.ToString())))
|
.Confirm(strs.timely_set(Format.Bold(N(amount)), Format.Bold(period.ToString())))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,10 +316,10 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
|
|
||||||
var usr = membersArray[new EllieRandom().Next(0, membersArray.Length)];
|
var usr = membersArray[new EllieRandom().Next(0, membersArray.Length)];
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm("🎟 " + GetText(strs.raffled_user),
|
.Confirm("🎟 " + GetText(strs.raffled_user),
|
||||||
$"**{usr.Username}**",
|
$"**{usr.Username}**",
|
||||||
footer: $"ID: {usr.Id}")
|
footer: $"ID: {usr.Id}")
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
@ -337,10 +337,10 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
|
|
||||||
var usr = membersArray[new EllieRandom().Next(0, membersArray.Length)];
|
var usr = membersArray[new EllieRandom().Next(0, membersArray.Length)];
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm("🎟 " + GetText(strs.raffled_user),
|
.Confirm("🎟 " + GetText(strs.raffled_user),
|
||||||
$"**{usr.Username}**",
|
$"**{usr.Username}**",
|
||||||
footer: $"ID: {usr.Id}")
|
footer: $"ID: {usr.Id}")
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
@ -373,41 +373,54 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CurrencyTransaction> trs;
|
var embed = CreateEmbed()
|
||||||
|
.WithTitle(GetText(strs.transactions(
|
||||||
|
((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString()
|
||||||
|
?? $"{userId}")))
|
||||||
|
.WithOkColor();
|
||||||
|
|
||||||
|
int count;
|
||||||
await using (var uow = _db.GetDbContext())
|
await using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
trs = await uow.Set<CurrencyTransaction>().GetPageFor(userId, page);
|
count = await uow.Set<CurrencyTransaction>()
|
||||||
|
.GetCountFor(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
var embed = CreateEmbed()
|
await Response()
|
||||||
.WithTitle(GetText(strs.transactions(
|
.Paginated()
|
||||||
((SocketGuild)ctx.Guild)?.GetUser(userId)?.ToString()
|
.PageItems(async (curPage) =>
|
||||||
?? $"{userId}")))
|
|
||||||
.WithOkColor();
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
foreach (var tr in trs)
|
|
||||||
{
|
|
||||||
var change = tr.Amount >= 0 ? "🔵" : "🔴";
|
|
||||||
var kwumId = new kwum(tr.Id).ToString();
|
|
||||||
var date = $"#{Format.Code(kwumId)} `〖{GetFormattedCurtrDate(tr)}〗`";
|
|
||||||
|
|
||||||
sb.AppendLine($"\\{change} {date} {Format.Bold(N(tr.Amount))}");
|
|
||||||
var transactionString = GetHumanReadableTransaction(tr.Type, tr.Extra, tr.OtherId);
|
|
||||||
if (transactionString is not null)
|
|
||||||
{
|
{
|
||||||
sb.AppendLine(transactionString);
|
await using var uow = _db.GetDbContext();
|
||||||
}
|
return await uow.Set<CurrencyTransaction>()
|
||||||
|
.GetPageFor(userId, curPage);
|
||||||
if (!string.IsNullOrWhiteSpace(tr.Note))
|
})
|
||||||
|
.PageSize(15)
|
||||||
|
.TotalElements(count)
|
||||||
|
.Page((trs, _) =>
|
||||||
{
|
{
|
||||||
sb.AppendLine($"\t`Note:` {tr.Note.TrimTo(50)}");
|
var sb = new StringBuilder();
|
||||||
}
|
foreach (var tr in trs)
|
||||||
}
|
{
|
||||||
|
var change = tr.Amount >= 0 ? "🔵" : "🔴";
|
||||||
|
var kwumId = new kwum(tr.Id).ToString();
|
||||||
|
var date = $"#{Format.Code(kwumId)} `〖{GetFormattedCurtrDate(tr)}〗`";
|
||||||
|
|
||||||
embed.WithDescription(sb.ToString());
|
sb.AppendLine($"\\{change} {date} {Format.Bold(N(tr.Amount))}");
|
||||||
embed.WithFooter(GetText(strs.page(page + 1)));
|
var transactionString = GetHumanReadableTransaction(tr.Type, tr.Extra, tr.OtherId);
|
||||||
await Response().Embed(embed).SendAsync();
|
if (transactionString is not null)
|
||||||
|
{
|
||||||
|
sb.AppendLine(transactionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(tr.Note))
|
||||||
|
{
|
||||||
|
sb.AppendLine($"\t`Note:` {tr.Note.TrimTo(50)}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
embed.WithDescription(sb.ToString());
|
||||||
|
return Task.FromResult(embed);
|
||||||
|
}).SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetFormattedCurtrDate(CurrencyTransaction ct)
|
private static string GetFormattedCurtrDate(CurrencyTransaction ct)
|
||||||
|
@ -420,9 +433,9 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
|
|
||||||
var tr = await uow.Set<CurrencyTransaction>()
|
var tr = await uow.Set<CurrencyTransaction>()
|
||||||
.ToLinqToDBTable()
|
.ToLinqToDBTable()
|
||||||
.Where(x => x.Id == intId && x.UserId == ctx.User.Id)
|
.Where(x => x.Id == intId && x.UserId == ctx.User.Id)
|
||||||
.FirstOrDefaultAsync();
|
.FirstOrDefaultAsync();
|
||||||
|
|
||||||
if (tr is null)
|
if (tr is null)
|
||||||
{
|
{
|
||||||
|
@ -483,9 +496,9 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
var balance = await _bank.GetBalanceAsync(ctx.User.Id);
|
var balance = await _bank.GetBalanceAsync(ctx.User.Id);
|
||||||
|
|
||||||
await N(balance)
|
await N(balance)
|
||||||
.Pipe(strs.bank_balance)
|
.Pipe(strs.bank_balance)
|
||||||
.Pipe(GetText)
|
.Pipe(GetText)
|
||||||
.Pipe(text => smc.RespondConfirmAsync(_sender, text, ephemeral: true));
|
.Pipe(text => smc.RespondConfirmAsync(_sender, text, ephemeral: true));
|
||||||
}
|
}
|
||||||
|
|
||||||
private EllieInteractionBase CreateCashInteraction()
|
private EllieInteractionBase CreateCashInteraction()
|
||||||
|
@ -507,13 +520,13 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm(
|
.Confirm(
|
||||||
user.ToString()
|
user.ToString()
|
||||||
.Pipe(Format.Bold)
|
.Pipe(Format.Bold)
|
||||||
.With(cur)
|
.With(cur)
|
||||||
.Pipe(strs.has))
|
.Pipe(strs.has))
|
||||||
.Interaction(inter)
|
.Interaction(inter)
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
@ -594,10 +607,10 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
new("award", ctx.User.ToString()!, role.Name, ctx.User.Id));
|
new("award", ctx.User.ToString()!, role.Name, ctx.User.Id));
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm(strs.mass_award(N(amount),
|
.Confirm(strs.mass_award(N(amount),
|
||||||
Format.Bold(users.Count.ToString()),
|
Format.Bold(users.Count.ToString()),
|
||||||
Format.Bold(role.Name)))
|
Format.Bold(role.Name)))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
@ -613,10 +626,10 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
new("take", ctx.User.ToString()!, null, ctx.User.Id));
|
new("take", ctx.User.ToString()!, null, ctx.User.Id));
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm(strs.mass_take(N(amount),
|
.Confirm(strs.mass_take(N(amount),
|
||||||
Format.Bold(users.Count.ToString()),
|
Format.Bold(users.Count.ToString()),
|
||||||
Format.Bold(role.Name)))
|
Format.Bold(role.Name)))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Cmd]
|
[Cmd]
|
||||||
|
@ -639,8 +652,8 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Response()
|
await Response()
|
||||||
.Error(strs.take_fail(N(amount), Format.Bold(user.ToString()), CurrencySign))
|
.Error(strs.take_fail(N(amount), Format.Bold(user.ToString()), CurrencySign))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -662,8 +675,8 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await Response()
|
await Response()
|
||||||
.Error(strs.take_fail(N(amount), Format.Code(usrId.ToString()), CurrencySign))
|
.Error(strs.take_fail(N(amount), Format.Code(usrId.ToString()), CurrencySign))
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,12 +708,12 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
}
|
}
|
||||||
|
|
||||||
var eb = CreateEmbed()
|
var eb = CreateEmbed()
|
||||||
.WithAuthor(ctx.User)
|
.WithAuthor(ctx.User)
|
||||||
.WithDescription(Format.Bold(str))
|
.WithDescription(Format.Bold(str))
|
||||||
.AddField(GetText(strs.roll2), result.Roll.ToString(CultureInfo.InvariantCulture), true)
|
.AddField(GetText(strs.roll2), result.Roll.ToString(CultureInfo.InvariantCulture), true)
|
||||||
.AddField(GetText(strs.bet), N(amount), true)
|
.AddField(GetText(strs.bet), N(amount), true)
|
||||||
.AddField(GetText(strs.won), N((long)result.Won), true)
|
.AddField(GetText(strs.won), N((long)result.Won), true)
|
||||||
.WithOkColor();
|
.WithOkColor();
|
||||||
|
|
||||||
await Response().Embed(eb).SendAsync();
|
await Response().Embed(eb).SendAsync();
|
||||||
}
|
}
|
||||||
|
@ -741,11 +754,11 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
|
|
||||||
await using var uow = _db.GetDbContext();
|
await using var uow = _db.GetDbContext();
|
||||||
var cleanRichest = await uow.GetTable<DiscordUser>()
|
var cleanRichest = await uow.GetTable<DiscordUser>()
|
||||||
.Where(x => x.UserId.In(users))
|
.Where(x => x.UserId.In(users))
|
||||||
.OrderByDescending(x => x.CurrencyAmount)
|
.OrderByDescending(x => x.CurrencyAmount)
|
||||||
.Skip(curPage * perPage)
|
.Skip(curPage * perPage)
|
||||||
.Take(perPage)
|
.Take(perPage)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
return cleanRichest;
|
return cleanRichest;
|
||||||
}
|
}
|
||||||
|
@ -757,34 +770,34 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
}
|
}
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Paginated()
|
.Paginated()
|
||||||
.PageItems(GetTopRichest)
|
.PageItems(GetTopRichest)
|
||||||
.PageSize(9)
|
.PageSize(9)
|
||||||
.CurrentPage(page)
|
.CurrentPage(page)
|
||||||
.Page((toSend, curPage) =>
|
.Page((toSend, curPage) =>
|
||||||
{
|
{
|
||||||
var embed = CreateEmbed()
|
var embed = CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithTitle(CurrencySign + " " + GetText(strs.leaderboard));
|
.WithTitle(CurrencySign + " " + GetText(strs.leaderboard));
|
||||||
|
|
||||||
if (!toSend.Any())
|
if (!toSend.Any())
|
||||||
{
|
{
|
||||||
embed.WithDescription(GetText(strs.no_user_on_this_page));
|
embed.WithDescription(GetText(strs.no_user_on_this_page));
|
||||||
return Task.FromResult(embed);
|
return Task.FromResult(embed);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < toSend.Count; i++)
|
for (var i = 0; i < toSend.Count; i++)
|
||||||
{
|
{
|
||||||
var x = toSend[i];
|
var x = toSend[i];
|
||||||
var usrStr = x.ToString().TrimTo(20, true);
|
var usrStr = x.ToString().TrimTo(20, true);
|
||||||
|
|
||||||
var j = i;
|
var j = i;
|
||||||
embed.AddField("#" + ((9 * curPage) + j + 1) + " " + usrStr, N(x.CurrencyAmount), true);
|
embed.AddField("#" + ((9 * curPage) + j + 1) + " " + usrStr, N(x.CurrencyAmount), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Task.FromResult(embed);
|
return Task.FromResult(embed);
|
||||||
})
|
})
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum InputRpsPick : byte
|
public enum InputRpsPick : byte
|
||||||
|
@ -895,11 +908,11 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
}
|
}
|
||||||
|
|
||||||
var eb = CreateEmbed()
|
var eb = CreateEmbed()
|
||||||
.WithOkColor()
|
.WithOkColor()
|
||||||
.WithDescription(sb.ToString())
|
.WithDescription(sb.ToString())
|
||||||
.AddField(GetText(strs.bet), N(amount), true)
|
.AddField(GetText(strs.bet), N(amount), true)
|
||||||
.AddField(GetText(strs.won), $"{N((long)result.Won)}", true)
|
.AddField(GetText(strs.won), $"{N((long)result.Won)}", true)
|
||||||
.WithAuthor(ctx.User);
|
.WithAuthor(ctx.User);
|
||||||
|
|
||||||
|
|
||||||
await Response().Embed(eb).SendAsync();
|
await Response().Embed(eb).SendAsync();
|
||||||
|
@ -924,8 +937,8 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
public async Task BetTest()
|
public async Task BetTest()
|
||||||
{
|
{
|
||||||
var values = Enum.GetValues<GambleTestTarget>()
|
var values = Enum.GetValues<GambleTestTarget>()
|
||||||
.Select(x => $"`{x}`")
|
.Select(x => $"`{x}`")
|
||||||
.Join(", ");
|
.Join(", ");
|
||||||
|
|
||||||
await Response().Confirm(GetText(strs.available_tests), values).SendAsync();
|
await Response().Confirm(GetText(strs.available_tests), values).SendAsync();
|
||||||
}
|
}
|
||||||
|
@ -998,10 +1011,10 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
sb.AppendLine($"Longest lose streak: `{maxL}`");
|
sb.AppendLine($"Longest lose streak: `{maxL}`");
|
||||||
|
|
||||||
await Response()
|
await Response()
|
||||||
.Confirm(GetText(strs.test_results_for(target)),
|
.Confirm(GetText(strs.test_results_for(target)),
|
||||||
sb.ToString(),
|
sb.ToString(),
|
||||||
footer: $"Total Bet: {tests} | Payout: {payout:F0} | {payout * 1.0M / tests * 100}%")
|
footer: $"Total Bet: {tests} | Payout: {payout:F0} | {payout * 1.0M / tests * 100}%")
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private EllieInteractionBase CreateRakebackInteraction()
|
private EllieInteractionBase CreateRakebackInteraction()
|
||||||
|
@ -1032,16 +1045,16 @@ public partial class Gambling : GamblingModule<GamblingService>
|
||||||
if (rb < 1)
|
if (rb < 1)
|
||||||
{
|
{
|
||||||
await Response()
|
await Response()
|
||||||
.Error(strs.rakeback_none)
|
.Error(strs.rakeback_none)
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var inter = CreateRakebackInteraction();
|
var inter = CreateRakebackInteraction();
|
||||||
await Response()
|
await Response()
|
||||||
.Pending(strs.rakeback_available(N(rb)))
|
.Pending(strs.rakeback_available(N(rb)))
|
||||||
.Interaction(inter)
|
.Interaction(inter)
|
||||||
.SendAsync();
|
.SendAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue