Ignore obsolete messages
This commit is contained in:
parent
1ebcfa9788
commit
c317e0b973
@ -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
|
||||
|
@ -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<UpdateTy
|
||||
|
||||
botClient.StartReceiving(updateHandle,handlePollingError,receiverOptions)
|
||||
|
||||
printf "Я родился"
|
||||
Console.ReadKey() |> ignore
|
Loading…
Reference in New Issue
Block a user