mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-11 17:58:26 -04:00
dev: Added initial version of the grpc api. Added relevant dummy settings to creds (they have no effect rn)
dev: Yt searches now INTERNALLY return multiple results but there is no way right now to paginate plain text results dev: moved some stuff around
This commit is contained in:
73
src/NadekoBot/Services/GrpcApi/ExprsSvc.cs
Normal file
73
src/NadekoBot/Services/GrpcApi/ExprsSvc.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using Grpc.Core;
|
||||
using NadekoBot.Db.Models;
|
||||
using NadekoBot.Modules.NadekoExpressions;
|
||||
|
||||
namespace NadekoBot.GrpcApi;
|
||||
|
||||
public class ExprsSvc : GrpcExprs.GrpcExprsBase, INService
|
||||
{
|
||||
private readonly NadekoExpressionsService _svc;
|
||||
|
||||
public ExprsSvc(NadekoExpressionsService svc)
|
||||
{
|
||||
_svc = svc;
|
||||
}
|
||||
|
||||
public override async Task<AddExprReply> AddExpr(AddExprRequest request, ServerCallContext context)
|
||||
{
|
||||
NadekoExpression expr;
|
||||
if (!string.IsNullOrWhiteSpace(request.Expr.Id))
|
||||
{
|
||||
expr = await _svc.EditAsync(request.GuildId,
|
||||
new kwum(request.Expr.Id),
|
||||
request.Expr.Response,
|
||||
request.Expr.Ca,
|
||||
request.Expr.Ad,
|
||||
request.Expr.Dm);
|
||||
}
|
||||
else
|
||||
{
|
||||
expr = await _svc.AddAsync(request.GuildId,
|
||||
request.Expr.Trigger,
|
||||
request.Expr.Response,
|
||||
request.Expr.Ca,
|
||||
request.Expr.Ad,
|
||||
request.Expr.Dm);
|
||||
}
|
||||
|
||||
|
||||
return new AddExprReply()
|
||||
{
|
||||
Id = new kwum(expr.Id).ToString(),
|
||||
Success = true,
|
||||
};
|
||||
}
|
||||
|
||||
public override async Task<GetExprsReply> GetExprs(GetExprsRequest request, ServerCallContext context)
|
||||
{
|
||||
var (exprs, totalCount) = await _svc.FindExpressionsAsync(request.GuildId, request.Query, request.Page);
|
||||
|
||||
var reply = new GetExprsReply();
|
||||
reply.TotalCount = totalCount;
|
||||
reply.Expressions.AddRange(exprs.Select(x => new ExprDto()
|
||||
{
|
||||
Ad = x.AutoDeleteTrigger,
|
||||
At = x.AllowTarget,
|
||||
Ca = x.ContainsAnywhere,
|
||||
Dm = x.DmResponse,
|
||||
Response = x.Response,
|
||||
Id = new kwum(x.Id).ToString(),
|
||||
Trigger = x.Trigger,
|
||||
}));
|
||||
|
||||
return reply;
|
||||
}
|
||||
|
||||
public override async Task<Empty> DeleteExpr(DeleteExprRequest request, ServerCallContext context)
|
||||
{
|
||||
await _svc.DeleteAsync(request.GuildId, new kwum(request.Id));
|
||||
|
||||
return new Empty();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user