миграция ID чата (fix #7)

This commit is contained in:
mihalin 2021-12-14 23:55:19 +03:00
parent ba0c2752a1
commit 645357995b
2 changed files with 13 additions and 1 deletions

View File

@ -3,7 +3,7 @@
version: '3'
services:
postgres:
image: kartoza/postgis
image: postgres:13.4
environment:
- POSTGRES_USER=test_user
- POSTGRES_PASSWORD=test_passwd

View File

@ -101,6 +101,17 @@ async def receive_left(message: types.Message):
await bot.save()
async def receive_migrate(message: types.Message):
bot = db_bot_instance.get()
from_id = message.chat.id
to_id = message.migrate_to_chat_id
chats = await bot.group_chats.filter(chat_id=from_id)
for chat in chats:
chat.chat_id = to_id
await chat.save(update_fields=["chat_id"])
class CustomRequestHandler(WebhookRequestHandler):
def __init__(self, *args, **kwargs):
@ -127,6 +138,7 @@ class CustomRequestHandler(WebhookRequestHandler):
types.ContentType.VOICE])
dp.register_message_handler(receive_invite, content_types=[types.ContentType.NEW_CHAT_MEMBERS])
dp.register_message_handler(receive_left, content_types=[types.ContentType.LEFT_CHAT_MEMBER])
dp.register_message_handler(receive_migrate, content_types=[types.ContentType.MIGRATE_TO_CHAT_ID])
return dp