Skip to content

Commit

Permalink
Отправка геопозиции со стороны вк
Browse files Browse the repository at this point in the history
  • Loading branch information
Delitel-WEB committed Sep 28, 2023
1 parent ae57add commit cdf7f64
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions sync/vk/handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import geo
from . import circles
from . import videos
from . import photos
Expand Down
37 changes: 37 additions & 0 deletions sync/vk/handlers/geo.py
Original file line number Diff line number Diff line change
@@ -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"<a href='{create_vk_link(message.from_id)}'>{user_info[0].first_name} {user_info[0].last_name}</a>\n",
parse_mode="html",
disable_web_page_preview=True,
disable_notification=True,
)

0 comments on commit cdf7f64

Please sign in to comment.