Skip to content

Commit

Permalink
fix(forward): handle telegram rate limit (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
MrMissx authored Nov 5, 2023
1 parent de0b425 commit 3a7a806
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion forwarder/modules/forward.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import asyncio
from typing import Union, Optional

from telegram import Update, Message, MessageId
from telegram.error import ChatMigrated
from telegram.error import ChatMigrated, RetryAfter
from telegram.ext import MessageHandler, filters, ContextTypes

from forwarder import bot, REMOVE_TAG, LOGGER
Expand All @@ -26,6 +27,10 @@ async def forwarder(update: Update, _: ContextTypes.DEFAULT_TYPE) -> None:
for chat in get_destenation(message.chat_id, message.message_thread_id):
try:
await send_message(message, chat["chat_id"], thread_id=chat["thread_id"])
except RetryAfter as err:
LOGGER.warning(f"Rate limited, retrying in {err.retry_after} seconds")
await asyncio.sleep(err.retry_after + 0.2)
await send_message(message, chat["chat_id"], thread_id=chat["thread_id"])
except ChatMigrated as err:
await send_message(message, err.new_chat_id)
LOGGER.warning(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "telegram-forwarder"
version = "2.2.0"
version = "2.2.1"
description = ""
authors = ["mrmissx <hi@mrmiss.my.id>"]
license = "GNU General Public License v3.0"
Expand Down

0 comments on commit 3a7a806

Please sign in to comment.