open System open System.Net.Http open System.Threading.Tasks open PublishHelperBot.Environment open PublishHelperBot.YoutubeDl open PublishHelperBot.Telegram open Telegram.Bot open Telegram.Bot.Polling open Telegram.Bot.Types open Telegram.Bot.Types.Enums let config = createConfig "SBPB_CONFIG_PATH" let botClient = TelegramBotClient (config.token, new HttpClient()) let youtubeDlClient = YoutubeDlClient.createClient { Client = new HttpClient() BaseUrl = config.youtubeDlUrl } let tgService = TgService.createService { Client = botClient ChannelId = config.chanelId YoutubeDlClient = youtubeDlClient AdminChatId = config.adminChatId } let youtubeDlService = YoutubeDlService.createService youtubeDlClient tgService (config.tmpYtdlSavePath |> Option.defaultValue "/tmp") let isObsoleteUpdate = let startDate = DateTime.UtcNow fun (update: Update) -> update.Type = UpdateType.Message && update.Message.Date < startDate let handlePollingError _ (e: Exception) _ = Logging.logger.Error(e, "Polling error") Task.CompletedTask Logging.logger.Information("Starting bot") let botHandler = TgUpdateHandler.createHandler config tgService youtubeDlService botClient.StartReceiving( (fun client update _ -> if not (isObsoleteUpdate update) then botHandler.PostUpdate(update) Task.CompletedTask ), handlePollingError, ReceiverOptions( AllowedUpdates = Array.zeroCreate 0 ) ) Logging.logger.Information("Я родился") Console.ReadKey() |> ignore