diff --git a/src/NadekoBot.Generators/GrpcApiPermGenerator.cs b/src/NadekoBot.Generators/GrpcApiPermGenerator.cs index 735afe17f..31c51aa40 100644 --- a/src/NadekoBot.Generators/GrpcApiPermGenerator.cs +++ b/src/NadekoBot.Generators/GrpcApiPermGenerator.cs @@ -87,7 +87,7 @@ namespace NadekoBot.Generators sw.WriteLine("namespace NadekoBot.GrpcApi;"); sw.WriteLine(); - sw.WriteLine("public partial class PermsInterceptor"); + sw.WriteLine("public partial class GrpcApiPermsInterceptor"); sw.WriteLine("{"); sw.Indent++; diff --git a/src/NadekoBot.GrpcApiBase/protos/greet.proto b/src/NadekoBot.GrpcApiBase/protos/greet.proto index 7aab3d5a3..c7b4661ea 100644 --- a/src/NadekoBot.GrpcApiBase/protos/greet.proto +++ b/src/NadekoBot.GrpcApiBase/protos/greet.proto @@ -5,18 +5,11 @@ option csharp_namespace = "NadekoBot.GrpcApi"; package greet; service GrpcGreet { - rpc GetGreetSettings (GetGreetRequest) returns (GetGreetReply); + rpc GetGreetSettings (GetGreetRequest) returns (GrpcGreetSettings); rpc UpdateGreet (UpdateGreetRequest) returns (UpdateGreetReply); rpc TestGreet (TestGreetRequest) returns (TestGreetReply); } -message GetGreetReply { - GrpcGreetSettings greet = 1; - GrpcGreetSettings greetDm = 2; - GrpcGreetSettings bye = 3; - GrpcGreetSettings boost = 4; -} - message GrpcGreetSettings { optional uint64 channelId = 1; string message = 2; @@ -26,6 +19,7 @@ message GrpcGreetSettings { message GetGreetRequest { uint64 guildId = 1; + GrpcGreetType type = 2; } message UpdateGreetRequest { @@ -41,7 +35,7 @@ enum GrpcGreetType { } message UpdateGreetReply { - bool success = 1; + GrpcGreetSettings settings = 1; } message TestGreetRequest { diff --git a/src/NadekoBot/Modules/Xp/Xp.cs b/src/NadekoBot/Modules/Xp/Xp.cs index 2bfec14c6..b925449b5 100644 --- a/src/NadekoBot/Modules/Xp/Xp.cs +++ b/src/NadekoBot/Modules/Xp/Xp.cs @@ -107,7 +107,7 @@ public partial class Xp : NadekoModule [Cmd] [UserPerm(GuildPerm.ManageChannels)] [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) channel = ctx.Channel; @@ -203,7 +203,7 @@ public partial class Xp : NadekoModule await Response() .Paginated() .PageItems(GetPageItems) - .PageSize(9) + .PageSize(10) .CurrentPage(page) .Page((users, curPage) => { @@ -262,7 +262,7 @@ public partial class Xp : NadekoModule await Response() .Paginated() .PageItems(GetPageItems) - .PageSize(9) + .PageSize(10) .Page((users, curPage) => { var embed = _sender.CreateEmbed() diff --git a/src/NadekoBot/Modules/Xp/XpService.cs b/src/NadekoBot/Modules/Xp/XpService.cs index e1c9876a7..b36989026 100644 --- a/src/NadekoBot/Modules/Xp/XpService.cs +++ b/src/NadekoBot/Modules/Xp/XpService.cs @@ -571,8 +571,8 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand .UserXpStats .Where(x => x.GuildId == guildId) .OrderByDescending(x => x.Xp + x.AwardedXp) - .Skip(page * 9) - .Take(9) + .Skip(page * 10) + .Take(10) .ToArrayAsyncLinqToDB(); } @@ -582,8 +582,8 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand return await uow.Set() .Where(x => x.GuildId == guildId && x.UserId.In(users)) .OrderByDescending(x => x.Xp + x.AwardedXp) - .Skip(page * 9) - .Take(9) + .Skip(page * 10) + .Take(10) .ToArrayAsyncLinqToDB(); } @@ -593,8 +593,8 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand return await uow.GetTable() .OrderByDescending(x => x.TotalXp) - .Skip(page * 9) - .Take(9) + .Skip(page * 10) + .Take(10) .ToArrayAsyncLinqToDB(); } @@ -605,8 +605,8 @@ public class XpService : INService, IReadyExecutor, IExecNoCommand return await uow.GetTable() .Where(x => x.UserId.In(users)) .OrderByDescending(x => x.TotalXp) - .Skip(page * 9) - .Take(9) + .Skip(page * 10) + .Take(10) .ToArrayAsyncLinqToDB(); } diff --git a/src/NadekoBot/Services/GrpcApi/GreetByeSvc.cs b/src/NadekoBot/Services/GrpcApi/GreetByeSvc.cs index c9ce3ce8f..ce0e67fce 100644 --- a/src/NadekoBot/Services/GrpcApi/GreetByeSvc.cs +++ b/src/NadekoBot/Services/GrpcApi/GreetByeSvc.cs @@ -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 GetGreetSettings(GetGreetRequest request, ServerCallContext context) + public override async Task 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) }; } diff --git a/src/NadekoBot/Services/PermsInterceptor.cs b/src/NadekoBot/Services/GrpcApiPermsInterceptor.cs similarity index 87% rename from src/NadekoBot/Services/PermsInterceptor.cs rename to src/NadekoBot/Services/GrpcApiPermsInterceptor.cs index 185764722..cc2caeaef 100644 --- a/src/NadekoBot/Services/PermsInterceptor.cs +++ b/src/NadekoBot/Services/GrpcApiPermsInterceptor.cs @@ -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)..]; diff --git a/src/NadekoBot/Services/GrpcApiService.cs b/src/NadekoBot/Services/GrpcApiService.cs index 3b9226af2..8e35424fd 100644 --- a/src/NadekoBot/Services/GrpcApiService.cs +++ b/src/NadekoBot/Services/GrpcApiService.cs @@ -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() {