BotSharp/src/Infrastructure/BotSharp.Core.Crontab/Functions/ScheduleTaskFn.cs

41 lines
1.2 KiB
C#
Raw Normal View History

2024-12-10 18:30:41 +00:00
using BotSharp.Abstraction.Repositories;
2024-12-05 17:11:16 +00:00
using BotSharp.Abstraction.Routing;
using BotSharp.Abstraction.Users;
2024-12-06 15:49:34 +00:00
using BotSharp.Core.Crontab.Hooks;
2024-12-05 17:11:16 +00:00
namespace BotSharp.Core.Crontab.Functions;
public class ScheduleTaskFn : IFunctionCallback
{
2024-12-06 15:49:34 +00:00
public string Name => $"{CrontabUtilityHook.PREFIX}schedule_task";
2024-12-05 17:11:16 +00:00
private readonly IServiceProvider _services;
public ScheduleTaskFn(IServiceProvider services)
{
_services = services;
}
public async Task<bool> Execute(RoleDialogModel message)
{
var args = JsonSerializer.Deserialize<ScheduleTaskArgs>(message.FunctionArgs);
var routing = _services.GetRequiredService<IRoutingContext>();
var user = _services.GetRequiredService<IUserIdentity>();
var crontabItem = new CrontabItem
{
2024-12-10 18:30:41 +00:00
Title = args.Title,
2024-12-05 17:11:16 +00:00
Description = args.Description,
Cron = args.Cron,
UserId = user.Id,
AgentId = routing.EntryAgentId,
2024-12-10 18:30:41 +00:00
ConversationId = routing.ConversationId,
Tasks = args.Tasks,
2024-12-05 17:11:16 +00:00
};
2024-12-10 18:30:41 +00:00
var db = _services.GetRequiredService<IBotSharpRepository>();
// var ret = db.InsertCrontabItem(crontabItem);
2024-12-05 17:11:16 +00:00
return true;
}
}