Less fragile obsolete validation, forward message on relay

This commit is contained in:
Keroosha 2023-02-07 22:32:33 +03:00
parent c0636b82fa
commit 9f62177c4e
2 changed files with 3 additions and 3 deletions

View File

@ -59,7 +59,7 @@ let public RelayHandler: Handler = fun (u, c, tg) ->
let caption = lazy RelayResolveCaption(captionMode, author, c.relayUrl) let caption = lazy RelayResolveCaption(captionMode, author, c.relayUrl)
match reply.Type with match reply.Type with
| MessageType.Text -> tg.SendTextMessageAsync(channelId, reply.Text) | MessageType.Text -> tg.ForwardMessageAsync(channelId, reply.Chat.Id, reply.MessageId)
| MessageType.Photo -> tg.SendPhotoAsync(channelId, photoMedia.Value, caption = caption.Value, | MessageType.Photo -> tg.SendPhotoAsync(channelId, photoMedia.Value, caption = caption.Value,
parseMode = RelayParseMode) parseMode = RelayParseMode)
| MessageType.Video -> tg.SendVideoAsync(channelId, reply.Video.FileId, caption = caption.Value, | MessageType.Video -> tg.SendVideoAsync(channelId, reply.Video.FileId, caption = caption.Value,

View File

@ -15,11 +15,11 @@ let CreateBot (config: BotConfig, http: HttpClient) = TelegramBotClient(config.t
let config = CreateConfig <| "SBPB_CONFIG_PATH"; let config = CreateConfig <| "SBPB_CONFIG_PATH";
let botClient = CreateBot <| (config, new HttpClient()) let botClient = CreateBot <| (config, new HttpClient())
let startDate = DateTime.UtcNow 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 updateHandle (bc: ITelegramBotClient) (u: Update) (ct: CancellationToken): Task =
match u with match u with
// Ignore old messages (to prevent overposting on downtime) | _ when isObsoleteUpdate u -> Task.CompletedTask
| _ when u.Message.Date < startDate -> Task.CompletedTask
| _ when RelayMatch <| (u, config) -> RelayHandler <| (u, config, bc) | _ when RelayMatch <| (u, config) -> RelayHandler <| (u, config, bc)
| _ -> Task.CompletedTask | _ -> Task.CompletedTask