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", + )