Skip to content

Commit

Permalink
Merge pull request #5 from Delitel-WEB/dev
Browse files Browse the repository at this point in the history
Поддержка стикеров в вк
  • Loading branch information
Delitel-WEB authored Sep 20, 2023
2 parents 9c8ce11 + ab05561 commit 95e306b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ python main.py
| **Сообщения** | | |
| Текстовые сообщения |||
| Голосовые сообщения |||
| Стикеры || |
| Стикеры || |
| Пересланные сообщения |||
| Документы |||
| Удаление сообщений |||
Expand Down
1 change: 1 addition & 0 deletions sync/tg/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@

storage = MemoryStorage()
bot = Bot(tgBotToken)
Bot.set_current(bot)
dp = Dispatcher(bot, storage=storage)
1 change: 1 addition & 0 deletions sync/vk/handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import stickers
from . import voices
from . import messages
43 changes: 43 additions & 0 deletions sync/vk/handlers/stickers.py
Original file line number Diff line number Diff line change
@@ -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"<a href='{create_vk_link(message.from_id)}'>{user_info[0].first_name} {user_info[0].last_name}</a>\n",
parse_mode="html",
)

0 comments on commit 95e306b

Please sign in to comment.