Compare commits

...

5 commits
5.1.12 ... v5

9 changed files with 85 additions and 68 deletions

View file

@ -2,6 +2,23 @@
Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except date format. a-c-f-r-o Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except date format. a-c-f-r-o
## [5.1.14] - 03.10.2024
## Changed
- Improved `.xplb -c`, it will now correctly only show users who are still in the server with no count limit
## Fixed
- Fixed marmalade load error on startup
## [5.1.13] - 03.10.2024
### Fixed
- Grpc api server will no longer start unless enabled in creds
- Seq comment in creds fixed
## [5.1.12] - 03.10.2024 ## [5.1.12] - 03.10.2024
### Added ### Added
@ -10,6 +27,7 @@ Mostly based on [keepachangelog](https://keepachangelog.com/en/1.1.0/) except da
### Fixed ### Fixed
- Fixed the Check for updates service not using the right URL and spitting an error in the console.
- Fixed another bug in `.greet` / `.bye` system, which caused it to show wrong message on a wrong server occasionally - Fixed another bug in `.greet` / `.bye` system, which caused it to show wrong message on a wrong server occasionally
## [5.1.11] - 03.10.2024 ## [5.1.11] - 03.10.2024

View file

@ -26,17 +26,6 @@ public static class UserXpExtensions
return usr; 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) public static async Task<List<UserXpStats>> GetTopUserXps(this DbSet<UserXpStats> xps, ulong guildId, int count)
=> await xps.ToLinqToDBTable() => await xps.ToLinqToDBTable()
.Where(x => x.GuildId == guildId) .Where(x => x.GuildId == guildId)

View file

@ -4,7 +4,7 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<ImplicitUsings>true</ImplicitUsings> <ImplicitUsings>true</ImplicitUsings>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages> <SatelliteResourceLanguages>en</SatelliteResourceLanguages>
<Version>5.1.12</Version> <Version>5.1.14</Version>
<!-- Output/build --> <!-- Output/build -->
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory> <RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>

View file

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

View file

@ -12,6 +12,7 @@ using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using System.Threading.Channels; using System.Threading.Channels;
using LinqToDB.EntityFrameworkCore; using LinqToDB.EntityFrameworkCore;
using LinqToDB.Tools;
using EllieBot.Modules.Patronage; using EllieBot.Modules.Patronage;
using Color = SixLabors.ImageSharp.Color; using Color = SixLabors.ImageSharp.Color;
using Exception = System.Exception; using Exception = System.Exception;
@ -566,13 +567,24 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
public async Task<IReadOnlyCollection<UserXpStats>> GetUserXps(ulong guildId, int page) public async Task<IReadOnlyCollection<UserXpStats>> GetUserXps(ulong guildId, int page)
{ {
await using var uow = _db.GetDbContext(); 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(); 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) 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) if (template.Club.Icon.Show)
await DrawClubImage(img, stats); await DrawClubImage(img, stats);
// #if GLOBAL_ELLIE // #if GLOBAL_ELLIE
await DrawFrame(img, stats.User.UserId); await DrawFrame(img, stats.User.UserId);
// #endif // #endif
var outputSize = template.OutputSize; var outputSize = template.OutputSize;
if (outputSize.X != img.Width || outputSize.Y != img.Height) if (outputSize.X != img.Width || outputSize.Y != img.Height)
@ -1309,7 +1321,7 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
if (frame is not null) if (frame is not null)
img.Mutate(x => x.DrawImage(frame, new Point(0, 0), new GraphicsOptions())); img.Mutate(x => x.DrawImage(frame, new Point(0, 0), new GraphicsOptions()));
} }
// #endif // #endif
private void DrawXpBar(float percent, XpBar info, Image<Rgba32> img) private void DrawXpBar(float percent, XpBar info, Image<Rgba32> img)
{ {

View file

@ -31,7 +31,7 @@ public class GrpcApiService : IEService, IReadyExecutor
public Task OnReadyAsync() public Task OnReadyAsync()
{ {
var creds = _creds.GetCreds(); var creds = _creds.GetCreds();
if (creds.GrpcApi is null || creds.GrpcApi.Enabled) if (creds.GrpcApi is null || !creds.GrpcApi.Enabled)
return Task.CompletedTask; return Task.CompletedTask;
try try

View file

@ -6,7 +6,7 @@ namespace EllieBot.Common;
public sealed class Creds : IBotCreds public sealed class Creds : IBotCreds
{ {
[Comment("""DO NOT CHANGE""")] [Comment("""DO NOT CHANGE""")]
public int Version { get; set; } = 11; public int Version { get; set; } = 12;
[Comment("""Bot token. Do not share with anyone ever -> https://discordapp.com/developers/applications/""")] [Comment("""Bot token. Do not share with anyone ever -> https://discordapp.com/developers/applications/""")]
public string Token { get; set; } public string Token { get; set; }
@ -165,7 +165,7 @@ public sealed class Creds : IBotCreds
public GrpcApiConfig GrpcApi { get; set; } public GrpcApiConfig GrpcApi { get; set; }
[Comment(""" [Comment("""
Url to Url and api key to a seq server. If url is set, bot will try to send logs to it.
""")] """)]
public SeqConfig Seq { get; set; } public SeqConfig Seq { get; set; }

View file

@ -137,12 +137,12 @@ public sealed class BotCredsProvider : IBotCredsProvider
var creds = Yaml.Deserializer.Deserialize<Creds>(File.ReadAllText(CREDS_FILE_NAME)); var creds = Yaml.Deserializer.Deserialize<Creds>(File.ReadAllText(CREDS_FILE_NAME));
if (creds.Version <= 5) if (creds.Version <= 5)
{ {
creds.BotCache = BotCacheImplemenation.Redis; creds.BotCache = BotCacheImplemenation.Memory;
} }
if (creds.Version <= 9) if (creds.Version < 12)
{ {
creds.Version = 10; creds.Version = 12;
File.WriteAllText(CREDS_FILE_NAME, Yaml.Serializer.Serialize(creds)); File.WriteAllText(CREDS_FILE_NAME, Yaml.Serializer.Serialize(creds));
} }
} }

View file

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