Skip to content
This repository was archived by the owner on Sep 24, 2024. It is now read-only.

Conversation

@alcortazzo
Copy link
Owner

@alcortazzo alcortazzo commented Aug 12, 2023

  • Implemented the ability to run multiple bots with a single script
  • Made bot compatible with aiogram v3+

@Kolx0zHik
Copy link

Добрый день. Возможно ли исправить:
AttributeError: module 'aiogram.types' has no attribute 'MediaGroup'.
Плюс еще поправить бы parse_mode=types.ParseMode.HTML. Не работает так. Работает вот так: parse_mode="HTML"

@alcortazzo
Copy link
Owner Author

@Ololoshka8

Беглым взглядом глянул - types.ParseMode.HTML - это и есть "HTML" (источник).

Какая версия у вас Python и aiogram?

@Kolx0zHik
Copy link

@Ololoshka8

Беглым взглядом глянул - types.ParseMode.HTML - это и есть "HTML" (источник).

Какая версия у вас Python и aiogram?

Я запускаю через докер. Git Clone и docker-compose. Ну и подредактировал конфиг файл (поставил свои ID куда нужно)

  1. Сначала была такая ошибка: ImportError: cannot import name 'executor' from 'aiogram.utils' (/root/.local/lib/python3.10/site-packages/aiogram/utils/init.py). Ее исправил - нашел ветку dev4. Там этой проблемы нет.
  2. Потом такая ошибка - AttributeError: module 'aiogram.types' has no attribute 'ParseMode'. Ее тоже решил. Поменял как написал выше: parse_mode="HTML". Так заработало.
  3. Потом, после постинга с фотками - AttributeError: module 'aiogram.types' has no attribute 'MediaGroup'. Точнее там 1 видео было.
  4. а потом вообще вот такая ошибка - https://pastebin.com/XF0N8rLF

@Kolx0zHik
Copy link

Добрый день. Я рассматриваю сейчас форк - https://github.com/Atronar/alcortazzo-vktgbot. Не знаю куда там написать. Напишу сюда. Ситуация такая: я прописываю в файл last_known_id.txt номер последнего сообщения в группе. Далее в группе еще появляются, например, 5 постов новых. Скрипт кидает их в телегу. Все как нужно. Просто супер. Но! если я перезапускаю контейнер, то он поновой этиже 5 новых сообщений кидает. Опять начинает с того же номера, которого я прописывал в файл. Хотя я смотрю. что вроде как реализовано, чтобы записывал новый номер сообщения в файл и начинал с него. Но у меня почему то не отрабатывает данный функционал (( Помогите!

@alcortazzo
Copy link
Owner Author

@Ololoshka8

Спасибо за багрепорт. Сейчас проверил - действительно, aiogram на новых версиях выдает ошибку.
Залочил версию в requirements.txt, сейчас все ок.

Что касается проблемы с файлом last_known_id.txt - у меня таких проблем не наблюдается и не наблюдалось. Подозреваю, что проблема в изменениях в форке.

Copy link

@ilystsov ilystsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use for instead of while; use else instead of if in loop body for consistency and readability

Comment on lines +44 to +45
if num_tries > 5:
logger.error(f"{config_name} - Post was not sent to Telegram. Too many tries.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if num_tries > 5:
logger.error(f"{config_name} - Post was not sent to Telegram. Too many tries.")
else:
logger.error(f"{config_name} - Post was not sent to Telegram. Too many tries.")

Comment on lines +23 to +25
num_tries = 1
while num_tries <= 5:
num_tries += 1
Copy link

@ilystsov ilystsov Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
num_tries = 1
while num_tries <= 5:
num_tries += 1
MAX_TRIES = 5
for num_tries in range(1, MAX_TRIES + 1):

Copy link

@ilystsov ilystsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use constants instead of magic numbers where possible

photos (list): List of photos.
docs (list): List of documents.
config_name (str): Name of config.
"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""
"""
RETRY_DELAY = 10
BAD_REQUEST_DELAY = 60

Comment on lines +38 to +40
f"{config_name} - Flood limit is exceeded. Sleep {ex.retry_after + 10} seconds. Try: {num_tries - 1}."
)
await asyncio.sleep(ex.retry_after + 10)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f"{config_name} - Flood limit is exceeded. Sleep {ex.retry_after + 10} seconds. Try: {num_tries - 1}."
)
await asyncio.sleep(ex.retry_after + 10)
f"{config_name} - Flood limit is exceeded. Sleep {ex.retry_after + RETRY_DELAY} seconds. Try: {num_tries - 1}."
)
await asyncio.sleep(ex.retry_after + RETRY_DELAY)

Comment on lines +42 to +43
logger.warning(f"{config_name} - Bad request. Wait 60 seconds. Try: {num_tries}. {ex}")
await asyncio.sleep(60)
Copy link

@ilystsov ilystsov Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.warning(f"{config_name} - Bad request. Wait 60 seconds. Try: {num_tries}. {ex}")
await asyncio.sleep(60)
logger.warning(f"{config_name} - Bad request. Wait {BAD_REQUEST_DELAY} seconds. Try: {num_tries}. {ex}")
await asyncio.sleep(BAD_REQUEST_DELAY)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants