Added options '-c' option for '.xpglb' which will show global xp leaderboard only with this server's users
This commit is contained in:
parent
c6a4eaf04e
commit
21267db587
4 changed files with 53 additions and 24 deletions
|
@ -88,13 +88,6 @@ public static class DiscordUserExtensions
|
|||
.Count()
|
||||
+ 1;
|
||||
|
||||
public static async Task<IReadOnlyCollection<DiscordUser>> GetUsersXpLeaderboardFor(this DbSet<DiscordUser> users, int page, int perPage)
|
||||
=> await users.ToLinqToDBTable()
|
||||
.OrderByDescending(x => x.TotalXp)
|
||||
.Skip(page * perPage)
|
||||
.Take(perPage)
|
||||
.ToArrayAsyncLinqToDB();
|
||||
|
||||
public static Task<List<DiscordUser>> GetTopRichest(
|
||||
this DbSet<DiscordUser> users,
|
||||
ulong botId,
|
||||
|
|
|
@ -182,22 +182,22 @@ public partial class Xp : EllieModule<XpService>
|
|||
var (opts, _) = OptionsParser.ParseFrom(new LbOpts(), args);
|
||||
|
||||
await ctx.Channel.TriggerTypingAsync();
|
||||
|
||||
if (opts.Clean)
|
||||
{
|
||||
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
|
||||
}
|
||||
|
||||
async Task<IReadOnlyCollection<UserXpStats>> GetPageItems(int curPage)
|
||||
{
|
||||
var socketGuild = (SocketGuild)ctx.Guild;
|
||||
if (opts.Clean)
|
||||
{
|
||||
await ctx.Channel.TriggerTypingAsync();
|
||||
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
|
||||
|
||||
return await _service.GetTopUserXps(ctx.Guild.Id,
|
||||
return await _service.GetGuildUserXps(ctx.Guild.Id,
|
||||
socketGuild.Users.Select(x => x.Id).ToList(),
|
||||
curPage);
|
||||
}
|
||||
|
||||
return await _service.GetUserXps(ctx.Guild.Id, curPage);
|
||||
return await _service.GetGuildUserXps(ctx.Guild.Id, curPage);
|
||||
}
|
||||
|
||||
await Response()
|
||||
|
@ -236,14 +236,32 @@ public partial class Xp : EllieModule<XpService>
|
|||
|
||||
[Cmd]
|
||||
[RequireContext(ContextType.Guild)]
|
||||
public async Task XpGlobalLeaderboard(int page = 1)
|
||||
public async Task XpGlobalLeaderboard(int page = 1, params string[] args)
|
||||
{
|
||||
if (--page < 0 || page > 99)
|
||||
return;
|
||||
|
||||
var (opts, _) = OptionsParser.ParseFrom(new LbOpts(), args);
|
||||
|
||||
await ctx.Channel.TriggerTypingAsync();
|
||||
if (opts.Clean)
|
||||
{
|
||||
await _tracker.EnsureUsersDownloadedAsync(ctx.Guild);
|
||||
}
|
||||
|
||||
async Task<IReadOnlyCollection<DiscordUser>> GetPageItems(int curPage)
|
||||
{
|
||||
if (opts.Clean)
|
||||
{
|
||||
return await _service.GetGlobalUserXps(page, ((SocketGuild)ctx.Guild).Users.Select(x => x.Id).ToList());
|
||||
}
|
||||
|
||||
return await _service.GetGlobalUserXps(curPage);
|
||||
}
|
||||
|
||||
await Response()
|
||||
.Paginated()
|
||||
.PageItems(async curPage => await _service.GetUserXps(curPage))
|
||||
.PageItems(GetPageItems)
|
||||
.PageSize(9)
|
||||
.Page((users, curPage) =>
|
||||
{
|
||||
|
@ -281,7 +299,9 @@ public partial class Xp : EllieModule<XpService>
|
|||
if (role.IsManaged)
|
||||
return;
|
||||
|
||||
var count = await _service.AddXpToUsersAsync(ctx.Guild.Id, amount, role.Members.Select(x => x.Id).ToArray());
|
||||
var count = await _service.AddXpToUsersAsync(ctx.Guild.Id,
|
||||
amount,
|
||||
role.Members.Select(x => x.Id).ToArray());
|
||||
await Response()
|
||||
.Confirm(
|
||||
strs.xpadd_users(Format.Bold(amount.ToString()), Format.Bold(count.ToString())))
|
||||
|
|
|
@ -564,7 +564,7 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
uow.SaveChanges();
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<UserXpStats>> GetUserXps(ulong guildId, int page)
|
||||
public async Task<IReadOnlyCollection<UserXpStats>> GetGuildUserXps(ulong guildId, int page)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
return await uow
|
||||
|
@ -576,22 +576,38 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
|
|||
.ToArrayAsyncLinqToDB();
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<UserXpStats>> GetTopUserXps(ulong guildId, List<ulong> users, int curPage)
|
||||
public async Task<IReadOnlyCollection<UserXpStats>> GetGuildUserXps(ulong guildId, List<ulong> users, int page)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
return await uow.Set<UserXpStats>()
|
||||
.Where(x => x.GuildId == guildId && x.UserId.In(users))
|
||||
.OrderByDescending(x => x.Xp + x.AwardedXp)
|
||||
.Skip(curPage * 9)
|
||||
.Skip(page * 9)
|
||||
.Take(9)
|
||||
.ToArrayAsyncLinqToDB();
|
||||
}
|
||||
|
||||
public Task<IReadOnlyCollection<DiscordUser>> GetUserXps(int page, int perPage = 9)
|
||||
public async Task<IReadOnlyCollection<DiscordUser>> GetGuildUserXps(int page)
|
||||
{
|
||||
using var uow = _db.GetDbContext();
|
||||
return uow.Set<DiscordUser>()
|
||||
.GetUsersXpLeaderboardFor(page, perPage);
|
||||
await using var uow = _db.GetDbContext();
|
||||
|
||||
return await uow.GetTable<DiscordUser>()
|
||||
.OrderByDescending(x => x.TotalXp)
|
||||
.Skip(page * 9)
|
||||
.Take(9)
|
||||
.ToArrayAsyncLinqToDB();
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<DiscordUser>> GetGlobalUserXps(int page, List<ulong> users)
|
||||
{
|
||||
await using var uow = _db.GetDbContext();
|
||||
|
||||
return await uow.GetTable<DiscordUser>()
|
||||
.Where(x => x.UserId.In(users))
|
||||
.OrderByDescending(x => x.TotalXp)
|
||||
.Skip(page * 9)
|
||||
.Take(9)
|
||||
.ToArrayAsyncLinqToDB();
|
||||
}
|
||||
|
||||
public async Task ChangeNotificationType(ulong userId, ulong guildId, XpNotificationLocation type)
|
||||
|
|
|
@ -105,7 +105,7 @@ public sealed class OtherSvc : GrpcOther.GrpcOtherBase, IEService
|
|||
|
||||
public override async Task<XpLbReply> GetXpLb(GetLbRequest request, ServerCallContext context)
|
||||
{
|
||||
var users = await _xp.GetUserXps(request.Page, request.PerPage);
|
||||
var users = await _xp.GetGuildUserXps(request.Page, request.PerPage);
|
||||
|
||||
var reply = new XpLbReply();
|
||||
|
||||
|
|
Loading…
Reference in a new issue