From 8560aef6082caa93906bdc0e1a3d9f339718c44a Mon Sep 17 00:00:00 2001 From: Delitel Date: Wed, 20 Sep 2023 22:33:05 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A3=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B8=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=81=D0=B0?= =?UTF-8?q?=20=D0=B1=D0=BE=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sync/tg/core/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sync/tg/core/__init__.py b/sync/tg/core/__init__.py index 8258faa..9fc4794 100644 --- a/sync/tg/core/__init__.py +++ b/sync/tg/core/__init__.py @@ -5,4 +5,5 @@ storage = MemoryStorage() bot = Bot(tgBotToken) +Bot.set_current(bot) dp = Dispatcher(bot, storage=storage) From ab055618e8608d3df5abeebdd7874bf7c38f5781 Mon Sep 17 00:00:00 2001 From: Delitel Date: Wed, 20 Sep 2023 22:34:13 +0300 Subject: [PATCH 2/2] =?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=D1=81=D1=82=D0=B8=D0=BA=D0=B5=D1=80=D0=BE=D0=B2?= =?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 --- README.md | 2 +- sync/vk/handlers/__init__.py | 1 + sync/vk/handlers/stickers.py | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 sync/vk/handlers/stickers.py diff --git a/README.md b/README.md index a08f3a6..f835ed7 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ python main.py | **Сообщения** | | | | Текстовые сообщения | ❌ | ✅ | | Голосовые сообщения | ❌ | ✅ | -| Стикеры | ❌ | ❌ | +| Стикеры | ❌ | ✅ | | Пересланные сообщения | ❌ | ❌ | | Документы | ❌ | ❌ | | Удаление сообщений | ❌ | ❌ | diff --git a/sync/vk/handlers/__init__.py b/sync/vk/handlers/__init__.py index 2ad3cff..000b6b2 100644 --- a/sync/vk/handlers/__init__.py +++ b/sync/vk/handlers/__init__.py @@ -1,2 +1,3 @@ +from . import stickers from . import voices from . import messages diff --git a/sync/vk/handlers/stickers.py b/sync/vk/handlers/stickers.py new file mode 100644 index 0000000..e3f7204 --- /dev/null +++ b/sync/vk/handlers/stickers.py @@ -0,0 +1,43 @@ +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 +from vkbottle.dispatch.rules import ABCRule + + +class StrickersRule(ABCRule[Message]): + """ + Кастомное правило которое будет срабатывать если + будет отправлен любой стикер + """ + + async def check(self, event: Message): + if event.attachments: + if event.attachments[0].sticker: + return True + else: + return False + else: + return False + + +@bot.on.message(StrickersRule()) +async def on_stickers(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) + sticker = await get_file_from_url( + message.attachments[0].sticker.images_with_background[-1].url + ) + sticker_message = await tg.send_sticker(bundle.tg_id, sticker=sticker) + await sticker_message.reply( + f"{user_info[0].first_name} {user_info[0].last_name}\n", + parse_mode="html", + )