// For more information see https://aka.ms/fsharp-console-apps open System open System.Net.Http open System.Threading open System.Threading.Tasks open PublishHelperBot.Handlers open PublishHelperBot.Environment open PublishHelperBot.YoutubeDl open Telegram.Bot open Telegram.Bot.Polling open Telegram.Bot.Types open Telegram.Bot.Types.Enums let CreateBot (config: BotConfig, http: HttpClient) = TelegramBotClient(config.token, http) let config = CreateConfig <| "SBPB_CONFIG_PATH"; let botClient = CreateBot <| (config, new HttpClient()) let YtService = YoutubeDlBackgroundService <| (new HttpClient(), config.YoutubeDlUrl, botClient, config.chanelId, CancellationToken.None) let startDate = DateTime.UtcNow let isObsoleteUpdate (u: Update) = u.Type = UpdateType.Message && u.Message.Date < startDate; let updateHandle (bc: ITelegramBotClient) (u: Update) (ct: CancellationToken): Task = let tgCtx = (u, config, bc) match u with | _ when isObsoleteUpdate u -> Task.CompletedTask | _ when RelayMatch <| (u, config) -> RelayHandler <| tgCtx | _ when YoutubeRepostMatch <| (u, config) -> YoutubeRepostHandler <| (YtService, tgCtx) | _ -> Task.CompletedTask let handlePollingError (bc: ITelegramBotClient) (e: Exception) (t: CancellationToken) = printfn $"{e.Message}\n{e.StackTrace}" Task.CompletedTask let receiverOptions = ReceiverOptions(AllowedUpdates = Array.zeroCreate 0) botClient.StartReceiving(updateHandle,handlePollingError,receiverOptions) YtService.StartYoutubeDlService() printf "Я родился" Console.ReadKey() |> ignore