Less fragile obsolete validation, forward message on relay
This commit is contained in:
parent
c0636b82fa
commit
9f62177c4e
@ -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,
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user