feat: add send video on reply

This commit is contained in:
Guillermo Marcel 2025-03-28 22:50:14 -03:00
parent d398585129
commit 13d9bef207

View File

@ -1,5 +1,6 @@
using AutoScan; using AutoScan;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Telegram.Bots.Types;
namespace CasaBotApp.Extensions; namespace CasaBotApp.Extensions;
@ -26,19 +27,51 @@ public static class CommandRegister
await autoScanApp.StartNewScan(); await autoScanApp.StartNewScan();
} }
}); });
botHandler.RegisterCommand(new BotCommand
{
Command = "/lastScan",
Description = "Send the images from the last scan",
Action = async (message, ctx) =>
{
var images = autoScanApp.GetLastScanPictures();
if (images.Length == 0)
{
await ctx.Responder(message, "No images found");
return;
}
await botHandler.SendPhotos(message.Chat.Id, images);
}
});
botHandler.OnReply = async msg =>
{
var originalMsg = msg.ReplyToMessage;
// Check if the original message is a photo and has a caption
if (originalMsg is not PhotoMessage photoMessage || photoMessage.Caption is null)
return;
var videoPath = autoScanApp.GetVideoPath(photoMessage.Caption);
if (string.IsNullOrEmpty(videoPath))
return;
await botHandler.SendVideo(msg.Chat.Id, videoPath);
};
} }
public static void UpdateOnScanCompleted(BotHandler botHandler, AutoScanApp autoScanApp, ILogger logger) public static void UpdateOnScanCompleted(BotHandler botHandler, AutoScanApp autoScanApp, ILogger logger)
{ {
autoScanApp.OnScanCompleted = async options => autoScanApp.OnScanCompleted = async () =>
{ {
logger.LogInformation("Scan completed at {At}", DateTime.Now); logger.LogInformation("Scan completed at {At}", DateTime.Now);
try try
{ {
//list all the images in the detection folder var images = autoScanApp.GetLastScanPictures();
if (options.Scanner?.DetectionFolder is null) if (images.Length == 0)
{
await botHandler.Update("No images found");
return; return;
var images = Directory.GetFiles(options.Scanner.DetectionFolder , "*.jpg"); }
await botHandler.Update($"Scan completed, found {images.Length} images"); await botHandler.Update($"Scan completed, found {images.Length} images");
await botHandler.UpdatePhotos(images); await botHandler.UpdatePhotos(images);
}catch(Exception ex) }catch(Exception ex)