From 28d0fcf4d27a3e90d9e80a91a2ebe11c21b31aef Mon Sep 17 00:00:00 2001 From: Delitel Date: Wed, 20 Sep 2023 21:45:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B3=D0=BE=D0=BB=D0=BE=D1=81=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D1=85=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=B8=D0=B7=20=D0=B2=D0=BA=20=D0=B2=20=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=B3=D1=80=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sync/tg/utils/__init__.py | 2 +- sync/utils/__init__.py | 2 +- sync/vk/handlers/__init__.py | 1 + sync/vk/handlers/messages.py | 4 ++-- sync/vk/handlers/voices.py | 28 ++++++++++++++++++++++++++++ 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 sync/vk/handlers/voices.py diff --git a/sync/tg/utils/__init__.py b/sync/tg/utils/__init__.py index 4acc593..2e5a881 100644 --- a/sync/tg/utils/__init__.py +++ b/sync/tg/utils/__init__.py @@ -1 +1 @@ -from .chats import update_chat_info \ No newline at end of file +from .chats import update_chat_info diff --git a/sync/utils/__init__.py b/sync/utils/__init__.py index baa3fd8..eb5ffcf 100644 --- a/sync/utils/__init__.py +++ b/sync/utils/__init__.py @@ -1 +1 @@ -from .files import get_file_from_url \ No newline at end of file +from .files import get_file_from_url diff --git a/sync/vk/handlers/__init__.py b/sync/vk/handlers/__init__.py index 8330732..2ad3cff 100644 --- a/sync/vk/handlers/__init__.py +++ b/sync/vk/handlers/__init__.py @@ -1 +1,2 @@ +from . import voices from . import messages diff --git a/sync/vk/handlers/messages.py b/sync/vk/handlers/messages.py index cb0cf6a..2f705c7 100644 --- a/sync/vk/handlers/messages.py +++ b/sync/vk/handlers/messages.py @@ -14,10 +14,10 @@ async def on_message(message: Message): select(Conversations).where(Conversations.vk_id == message.peer_id) ) if bundle: - users_info = await bot.api.users.get(message.from_id) + user_info = await bot.api.users.get(message.from_id) await tg.send_message( bundle.tg_id, - f"{users_info[0].first_name} {users_info[0].last_name}\n" + f"{user_info[0].first_name} {user_info[0].last_name}\n" + "_" * 10 + f"\n{message.text}", parse_mode="html", diff --git a/sync/vk/handlers/voices.py b/sync/vk/handlers/voices.py new file mode 100644 index 0000000..6db45ff --- /dev/null +++ b/sync/vk/handlers/voices.py @@ -0,0 +1,28 @@ +from ..core import bot +from vkbottle.user import Message +from ...db import Sessions +from ...db.models import Conversations +from sqlalchemy import select +from ...tg.core import bot as tg +from ..utils import create_vk_link +from ...utils import get_file_from_url + + +@bot.on.message(attachment=["audio_message"]) +async def on_audio_message(message: Message): + async with Sessions() as session: + bundle = await session.scalar( + select(Conversations).where(Conversations.vk_id == message.peer_id) + ) + if bundle: + user_info = await bot.api.users.get(message.from_id) + voice_file = await get_file_from_url( + message.attachments[0].audio_message.link_ogg + ) + + await tg.send_voice( + bundle.tg_id, + voice_file, + f"{user_info[0].first_name} {user_info[0].last_name}\n", + parse_mode="html", + )