change: Leaderboards will show 10 users per page

This commit is contained in:
Kwoth
2024-10-07 09:07:32 +00:00
parent 1340533c21
commit cd8c14c607
7 changed files with 33 additions and 47 deletions

View File

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

View File

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

View File

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