diff --git a/sync/vk/handlers/__init__.py b/sync/vk/handlers/__init__.py index e659813..d371ad5 100644 --- a/sync/vk/handlers/__init__.py +++ b/sync/vk/handlers/__init__.py @@ -1,3 +1,4 @@ +from . import geo from . import circles from . import videos from . import photos diff --git a/sync/vk/handlers/geo.py b/sync/vk/handlers/geo.py new file mode 100644 index 0000000..f471948 --- /dev/null +++ b/sync/vk/handlers/geo.py @@ -0,0 +1,37 @@ +from ..core import bot +from vkbottle.user import Message +from ...tg.core import bot as tg +from ..utils import create_vk_link, check_bundle +from vkbottle.dispatch.rules import ABCRule + + +class GeoRule(ABCRule[Message]): + """ + Кастомное правило которое будет срабатывать если + будет отправлена геолокация + """ + + async def check(self, event: Message): + if event.geo: + return True + + return False + + +@bot.on.message(GeoRule()) +@check_bundle +async def on_geo(message: Message, bundle): + user_info = await bot.api.users.get(message.from_id) + + latitude = message.geo.coordinates.latitude + longitude = message.geo.coordinates.longitude + + geo_message = await tg.send_location( + bundle.tg_id, latitude=latitude, longitude=longitude + ) + await geo_message.reply( + f"{user_info[0].first_name} {user_info[0].last_name}\n", + parse_mode="html", + disable_web_page_preview=True, + disable_notification=True, + )