improved .xplb -c, it will now correctly work only on users who are still in the server, isntead of only top 1k

Fixed marmalade error on bot startup
This commit is contained in:
Toastie (DCS Team) 2024-10-05 14:14:33 +13:00
parent 5c72c6562f
commit 113dc3748a
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
4 changed files with 60 additions and 61 deletions

View file

@ -26,17 +26,6 @@ public static class UserXpExtensions
return usr;
}
public static async Task<IReadOnlyCollection<UserXpStats>> GetUsersFor(
this DbSet<UserXpStats> xps,
ulong guildId,
int page)
=> await xps.ToLinqToDBTable()
.Where(x => x.GuildId == guildId)
.OrderByDescending(x => x.Xp + x.AwardedXp)
.Skip(page * 9)
.Take(9)
.ToArrayAsyncLinqToDB();
public static async Task<List<UserXpStats>> GetTopUserXps(this DbSet<UserXpStats> xps, ulong guildId, int count)
=> await xps.ToLinqToDBTable()
.Where(x => x.GuildId == guildId)

View file

@ -183,27 +183,26 @@ public partial class Xp : EllieModule<XpService>
await ctx.Channel.TriggerTypingAsync();
async Task<IReadOnlyCollection<UserXpStats>> GetPageItems(int curPage)
{
var socketGuild = (SocketGuild)ctx.Guild;
var allCleanUsers = new List<UserXpStats>();
if (opts.Clean)
{
await ctx.Channel.TriggerTypingAsync();
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
allCleanUsers = (await _service.GetTopUserXps(ctx.Guild.Id, 1000))
.Where(user => socketGuild.GetUser(user.UserId) is not null)
.ToList();
return await _service.GetTopUserXps(ctx.Guild.Id,
socketGuild.Users.Select(x => x.Id).ToList(),
curPage);
}
var res = opts.Clean
? Response()
.Paginated()
.Items(allCleanUsers)
: Response()
.Paginated()
.PageItems((curPage) => _service.GetUserXps(ctx.Guild.Id, curPage));
return await _service.GetUserXps(ctx.Guild.Id, curPage);
}
await res
await Response()
.Paginated()
.PageItems(GetPageItems)
.PageSize(9)
.CurrentPage(page)
.Page((users, curPage) =>

View file

@ -12,6 +12,7 @@ using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using System.Threading.Channels;
using LinqToDB.EntityFrameworkCore;
using LinqToDB.Tools;
using EllieBot.Modules.Patronage;
using Color = SixLabors.ImageSharp.Color;
using Exception = System.Exception;
@ -566,13 +567,24 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
public async Task<IReadOnlyCollection<UserXpStats>> GetUserXps(ulong guildId, int page)
{
await using var uow = _db.GetDbContext();
return await uow.Set<UserXpStats>().GetUsersFor(guildId, page);
return await uow
.UserXpStats
.Where(x => x.GuildId == guildId)
.OrderByDescending(x => x.Xp + x.AwardedXp)
.Skip(page * 9)
.Take(9)
.ToArrayAsyncLinqToDB();
}
public async Task<IReadOnlyCollection<UserXpStats>> GetTopUserXps(ulong guildId, int count)
public async Task<IReadOnlyCollection<UserXpStats>> GetTopUserXps(ulong guildId, List<ulong> users, int curPage)
{
await using var uow = _db.GetDbContext();
return await uow.Set<UserXpStats>().GetTopUserXps(guildId, count);
return await uow.Set<UserXpStats>()
.Where(x => x.GuildId == guildId && x.UserId.In(users))
.OrderByDescending(x => x.Xp + x.AwardedXp)
.Skip(curPage * 9)
.Take(9)
.ToArrayAsyncLinqToDB();
}
public Task<IReadOnlyCollection<DiscordUser>> GetUserXps(int page, int perPage = 9)
@ -1249,9 +1261,9 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
if (template.Club.Icon.Show)
await DrawClubImage(img, stats);
// #if GLOBAL_ELLIE
// #if GLOBAL_ELLIE
await DrawFrame(img, stats.User.UserId);
// #endif
// #endif
var outputSize = template.OutputSize;
if (outputSize.X != img.Width || outputSize.Y != img.Height)
@ -1309,7 +1321,7 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
if (frame is not null)
img.Mutate(x => x.DrawImage(frame, new Point(0, 0), new GraphicsOptions()));
}
// #endif
// #endif
private void DrawXpBar(float percent, XpBar info, Image<Rgba32> img)
{

View file

@ -1,5 +1,4 @@
# DO NOT CHANGE
version: 1
# List of marmalades automatically loaded at startup
loaded:
- ngrpc
loaded: []