mirror of
https://github.com/TheFunny/TelegramTwitterMediaBot.git
synced 2026-10-01 00:32:05 +00:00
fix: rate limit plain chat operations
This commit is contained in:
@@ -193,9 +193,7 @@ impl MediaSender for Bot {
|
|||||||
reply_markup: Option<InlineKeyboardMarkup>,
|
reply_markup: Option<InlineKeyboardMarkup>,
|
||||||
) -> BoxFuture<'_, Result<i64, RequestError>> {
|
) -> BoxFuture<'_, Result<i64, RequestError>> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
// Plain messages never met a bucket: a dead-letter storm (or one
|
crate::rate_limit::limiter_for(chat_id.0).acquire(1.0).await;
|
||||||
// error reply per failed item) could burst past Telegram's
|
|
||||||
// per-bot ceiling with only 429s left to absorb it.
|
|
||||||
crate::rate_limit::acquire_global(1.0).await;
|
crate::rate_limit::acquire_global(1.0).await;
|
||||||
let mut request = <Bot as Requester>::send_message(self, chat_id, text);
|
let mut request = <Bot as Requester>::send_message(self, chat_id, text);
|
||||||
if let Some(reply_to) = reply_to {
|
if let Some(reply_to) = reply_to {
|
||||||
@@ -216,6 +214,7 @@ impl MediaSender for Bot {
|
|||||||
reply_to: Option<MessageId>,
|
reply_to: Option<MessageId>,
|
||||||
) -> BoxFuture<'_, Result<i64, RequestError>> {
|
) -> BoxFuture<'_, Result<i64, RequestError>> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
crate::rate_limit::limiter_for(chat_id.0).acquire(1.0).await;
|
||||||
crate::rate_limit::acquire_global(1.0).await;
|
crate::rate_limit::acquire_global(1.0).await;
|
||||||
let mut request =
|
let mut request =
|
||||||
<Bot as Requester>::send_message(self, chat_id, text).parse_mode(ParseMode::Html);
|
<Bot as Requester>::send_message(self, chat_id, text).parse_mode(ParseMode::Html);
|
||||||
@@ -262,13 +261,14 @@ impl MediaSender for Bot {
|
|||||||
text: String,
|
text: String,
|
||||||
) -> BoxFuture<'_, Result<(), RequestError>> {
|
) -> BoxFuture<'_, Result<(), RequestError>> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
crate::rate_limit::limiter_for(chat_id.0).acquire(1.0).await;
|
||||||
|
crate::rate_limit::acquire_global(1.0).await;
|
||||||
<Bot as Requester>::edit_message_text(self, chat_id, message_id, text)
|
<Bot as Requester>::edit_message_text(self, chat_id, message_id, text)
|
||||||
.reply_markup(InlineKeyboardMarkup::default())
|
.reply_markup(InlineKeyboardMarkup::default())
|
||||||
.await
|
.await
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn edit_message_caption(
|
fn edit_message_caption(
|
||||||
&self,
|
&self,
|
||||||
chat_id: ChatId,
|
chat_id: ChatId,
|
||||||
@@ -276,6 +276,8 @@ impl MediaSender for Bot {
|
|||||||
caption: String,
|
caption: String,
|
||||||
) -> BoxFuture<'_, Result<(), RequestError>> {
|
) -> BoxFuture<'_, Result<(), RequestError>> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
crate::rate_limit::limiter_for(chat_id.0).acquire(1.0).await;
|
||||||
|
crate::rate_limit::acquire_global(1.0).await;
|
||||||
<Bot as Requester>::edit_message_caption(self, chat_id, message_id)
|
<Bot as Requester>::edit_message_caption(self, chat_id, message_id)
|
||||||
.caption(caption)
|
.caption(caption)
|
||||||
.parse_mode(ParseMode::Html)
|
.parse_mode(ParseMode::Html)
|
||||||
@@ -290,6 +292,8 @@ impl MediaSender for Bot {
|
|||||||
message_id: MessageId,
|
message_id: MessageId,
|
||||||
) -> BoxFuture<'_, Result<(), RequestError>> {
|
) -> BoxFuture<'_, Result<(), RequestError>> {
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
|
crate::rate_limit::limiter_for(chat_id.0).acquire(1.0).await;
|
||||||
|
crate::rate_limit::acquire_global(1.0).await;
|
||||||
<Bot as Requester>::delete_message(self, chat_id, message_id)
|
<Bot as Requester>::delete_message(self, chat_id, message_id)
|
||||||
.await
|
.await
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
|
|||||||
Reference in New Issue
Block a user