diff --git a/PublishHelperBot/Handlers.fs b/PublishHelperBot/Handlers.fs index ceb93a4..e400398 100644 --- a/PublishHelperBot/Handlers.fs +++ b/PublishHelperBot/Handlers.fs @@ -11,6 +11,7 @@ type HandlerArgs = Update * BotConfig * ITelegramBotClient type HandlerRequirements = BaseHandlerArgs -> bool type Handler = HandlerArgs -> Task +// Utils let UpdateIsAMessage (x: Update) = x.Type = UpdateType.Message let FromAdminChat (x: Message, c: BotConfig) = x.Chat.Id = c.adminChatId let HasReply (x: Message) = not(isNull x.ReplyToMessage) @@ -19,7 +20,6 @@ let UrlsAsAlbumInputMedia (urls: string[]): IAlbumInputMedia[] = Array.map (fun (x: string) -> InputMediaPhoto(x)) urls // Post (Relay) command - type RelayCaptionMode = WithAuthor | Anonymous | Unknown let RelaySupportedContent (x: Message) = match x.Type with @@ -65,3 +65,13 @@ let public RelayHandler: Handler = fun (u, c, tg) -> | MessageType.Video -> tg.SendVideoAsync(channelId, reply.Video.FileId, caption = caption.Value, parseMode = RelayParseMode) | _ -> Task.CompletedTask + + +// Youtube repost + +let public YoutubeRepostMatch: HandlerRequirements = fun (u, c) -> + UpdateIsAMessage u && + FromAdminChat <| (u.Message, c) && + u.Message.Text.StartsWith("\\yt") && + u.Message.Text.Split(' ').Length = 2 + \ No newline at end of file diff --git a/PublishHelperBot/Program.fs b/PublishHelperBot/Program.fs index b6507d1..16231a6 100644 --- a/PublishHelperBot/Program.fs +++ b/PublishHelperBot/Program.fs @@ -14,9 +14,12 @@ 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 startDate = DateTime.Now let updateHandle (bc: ITelegramBotClient) (u: Update) (ct: CancellationToken): Task = match u with + // Ignore old messages (to prevent overposting on downtime) + | _ when u.Message.Date < startDate -> Task.CompletedTask | _ when RelayMatch <| (u, config) -> RelayHandler <| (u, config, bc) | _ -> Task.CompletedTask @@ -28,4 +31,5 @@ let receiverOptions = ReceiverOptions(AllowedUpdates = Array.zeroCreate ignore \ No newline at end of file