Leaderboards will show 10 users per page

This commit is contained in:
Toastie (DCS Team) 2024-10-08 13:55:47 +13:00
parent af4be2aa8c
commit db8885739f
Signed by: toastie_t0ast
GPG key ID: 27F3B6855AFD40A4
7 changed files with 31 additions and 47 deletions

View file

@ -87,7 +87,7 @@ namespace EllieBot.Generators
sw.WriteLine("namespace EllieBot.GrpcApi;"); sw.WriteLine("namespace EllieBot.GrpcApi;");
sw.WriteLine(); sw.WriteLine();
sw.WriteLine("public partial class PermsInterceptor"); sw.WriteLine("public partial class GrpcApiPermsInterceptor");
sw.WriteLine("{"); sw.WriteLine("{");
sw.Indent++; sw.Indent++;

View file

@ -5,18 +5,11 @@ option csharp_namespace = "EllieBot.GrpcApi";
package greet; package greet;
service GrpcGreet { service GrpcGreet {
rpc GetGreetSettings (GetGreetRequest) returns (GetGreetReply); rpc GetGreetSettings (GetGreetRequest) returns (GrpcGreetSettings);
rpc UpdateGreet (UpdateGreetRequest) returns (UpdateGreetReply); rpc UpdateGreet (UpdateGreetRequest) returns (UpdateGreetReply);
rpc TestGreet (TestGreetRequest) returns (TestGreetReply); rpc TestGreet (TestGreetRequest) returns (TestGreetReply);
} }
message GetGreetReply {
GrpcGreetSettings greet = 1;
GrpcGreetSettings greetDm = 2;
GrpcGreetSettings bye = 3;
GrpcGreetSettings boost = 4;
}
message GrpcGreetSettings { message GrpcGreetSettings {
optional uint64 channelId = 1; optional uint64 channelId = 1;
string message = 2; string message = 2;
@ -26,6 +19,7 @@ message GrpcGreetSettings {
message GetGreetRequest { message GetGreetRequest {
uint64 guildId = 1; uint64 guildId = 1;
GrpcGreetType type = 2;
} }
message UpdateGreetRequest { message UpdateGreetRequest {
@ -41,7 +35,7 @@ enum GrpcGreetType {
} }
message UpdateGreetReply { message UpdateGreetReply {
bool success = 1; GrpcGreetSettings settings = 1;
} }
message TestGreetRequest { message TestGreetRequest {

View file

@ -107,7 +107,7 @@ public partial class Xp : EllieModule<XpService>
[Cmd] [Cmd]
[UserPerm(GuildPerm.ManageChannels)] [UserPerm(GuildPerm.ManageChannels)]
[RequireContext(ContextType.Guild)] [RequireContext(ContextType.Guild)]
public async Task XpExclude(Channel _, [Leftover] IChannel channel = null) public async Task XpExclude(Channel _, [Leftover] IChannel? channel = null)
{ {
if (channel is null) if (channel is null)
channel = ctx.Channel; channel = ctx.Channel;
@ -203,7 +203,7 @@ public partial class Xp : EllieModule<XpService>
await Response() await Response()
.Paginated() .Paginated()
.PageItems(GetPageItems) .PageItems(GetPageItems)
.PageSize(9) .PageSize(10)
.CurrentPage(page) .CurrentPage(page)
.Page((users, curPage) => .Page((users, curPage) =>
{ {
@ -262,7 +262,7 @@ public partial class Xp : EllieModule<XpService>
await Response() await Response()
.Paginated() .Paginated()
.PageItems(GetPageItems) .PageItems(GetPageItems)
.PageSize(9) .PageSize(10)
.Page((users, curPage) => .Page((users, curPage) =>
{ {
var embed = _sender.CreateEmbed() var embed = _sender.CreateEmbed()

View file

@ -571,8 +571,8 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
.UserXpStats .UserXpStats
.Where(x => x.GuildId == guildId) .Where(x => x.GuildId == guildId)
.OrderByDescending(x => x.Xp + x.AwardedXp) .OrderByDescending(x => x.Xp + x.AwardedXp)
.Skip(page * 9) .Skip(page * 10)
.Take(9) .Take(10)
.ToArrayAsyncLinqToDB(); .ToArrayAsyncLinqToDB();
} }
@ -582,8 +582,8 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
return await uow.Set<UserXpStats>() return await uow.Set<UserXpStats>()
.Where(x => x.GuildId == guildId && x.UserId.In(users)) .Where(x => x.GuildId == guildId && x.UserId.In(users))
.OrderByDescending(x => x.Xp + x.AwardedXp) .OrderByDescending(x => x.Xp + x.AwardedXp)
.Skip(page * 9) .Skip(page * 10)
.Take(9) .Take(10)
.ToArrayAsyncLinqToDB(); .ToArrayAsyncLinqToDB();
} }
@ -593,8 +593,8 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
return await uow.GetTable<DiscordUser>() return await uow.GetTable<DiscordUser>()
.OrderByDescending(x => x.TotalXp) .OrderByDescending(x => x.TotalXp)
.Skip(page * 9) .Skip(page * 10)
.Take(9) .Take(10)
.ToArrayAsyncLinqToDB(); .ToArrayAsyncLinqToDB();
} }
@ -605,8 +605,8 @@ public class XpService : IEService, IReadyExecutor, IExecNoCommand
return await uow.GetTable<DiscordUser>() return await uow.GetTable<DiscordUser>()
.Where(x => x.UserId.In(users)) .Where(x => x.UserId.In(users))
.OrderByDescending(x => x.TotalXp) .OrderByDescending(x => x.TotalXp)
.Skip(page * 9) .Skip(page * 10)
.Take(9) .Take(10)
.ToArrayAsyncLinqToDB(); .ToArrayAsyncLinqToDB();
} }

View file

@ -14,12 +14,6 @@ public sealed class GreetByeSvc : GrpcGreet.GrpcGreetBase, IEService
_client = client; _client = client;
} }
public GreetSettings GetDefaultGreet(GreetType type)
=> new GreetSettings()
{
GreetType = type
};
private static GrpcGreetSettings ToConf(GreetSettings? conf) private static GrpcGreetSettings ToConf(GreetSettings? conf)
{ {
if (conf is null) if (conf is null)
@ -35,23 +29,13 @@ public sealed class GreetByeSvc : GrpcGreet.GrpcGreetBase, IEService
} }
[GrpcApiPerm(GuildPerm.Administrator)] [GrpcApiPerm(GuildPerm.Administrator)]
public override async Task<GetGreetReply> GetGreetSettings(GetGreetRequest request, ServerCallContext context) public override async Task<GrpcGreetSettings> GetGreetSettings(GetGreetRequest request, ServerCallContext context)
{ {
var guildId = request.GuildId; var guildId = request.GuildId;
var greetConf = await _gs.GetGreetSettingsAsync(guildId, GreetType.Greet); var conf = await _gs.GetGreetSettingsAsync(guildId, (GreetType)request.Type);
var byeConf = await _gs.GetGreetSettingsAsync(guildId, GreetType.Bye);
var boostConf = await _gs.GetGreetSettingsAsync(guildId, GreetType.Boost);
var greetDmConf = await _gs.GetGreetSettingsAsync(guildId, GreetType.GreetDm);
// todo timer
return new GetGreetReply() return ToConf(conf);
{
Greet = ToConf(greetConf),
Bye = ToConf(byeConf),
Boost = ToConf(boostConf),
GreetDm = ToConf(greetDmConf)
};
} }
[GrpcApiPerm(GuildPerm.Administrator)] [GrpcApiPerm(GuildPerm.Administrator)]
@ -61,12 +45,18 @@ public sealed class GreetByeSvc : GrpcGreet.GrpcGreetBase, IEService
var s = request.Settings; var s = request.Settings;
var msg = s.Message; var msg = s.Message;
var type = GetGreetType(s.Type);
await _gs.SetMessage(gid, GetGreetType(s.Type), msg); await _gs.SetMessage(gid, GetGreetType(s.Type), msg);
await _gs.SetGreet(gid, s.ChannelId, GetGreetType(s.Type), s.IsEnabled); await _gs.SetGreet(gid, s.ChannelId, type, s.IsEnabled);
var settings = await _gs.GetGreetSettingsAsync(gid, type);
if (settings is null)
return new();
return new() return new()
{ {
Success = true Settings = ToConf(settings)
}; };
} }

View file

@ -3,11 +3,11 @@ using Grpc.Core.Interceptors;
namespace EllieBot.GrpcApi; namespace EllieBot.GrpcApi;
public sealed partial class PermsInterceptor : Interceptor public sealed partial class GrpcApiPermsInterceptor : Interceptor
{ {
private readonly DiscordSocketClient _client; private readonly DiscordSocketClient _client;
public PermsInterceptor(DiscordSocketClient client) public GrpcApiPermsInterceptor(DiscordSocketClient client)
{ {
_client = client; _client = client;
Log.Information("interceptor created"); Log.Information("interceptor created");
@ -29,8 +29,8 @@ public sealed partial class PermsInterceptor : Interceptor
.RequestHeaders .RequestHeaders
.ToDictionary(x => x.Key, x => x.Value); .ToDictionary(x => x.Key, x => x.Value);
if (!metadata.ContainsKey("userid"))
var method = context.Method[(context.Method.LastIndexOf('/') + 1)..]; throw new RpcException(new Status(StatusCode.Unauthenticated, "userid has to be specified"));
if (perms.TryGetValue(method, out var perm)) if (perms.TryGetValue(method, out var perm))
{ {

View file

@ -39,7 +39,7 @@ public class GrpcApiService : IEService, IReadyExecutor
var host = creds.GrpcApi.Host; var host = creds.GrpcApi.Host;
var port = creds.GrpcApi.Port + _client.ShardId; var port = creds.GrpcApi.Port + _client.ShardId;
var interceptor = new PermsInterceptor(_client); var interceptor = new GrpcApiPermsInterceptor(_client);
_app = new Server() _app = new Server()
{ {