/nearby, subscriptions check, geocoding #2
@ -92,8 +92,10 @@
|
||||
"label_too_long": "Довжина назви ролі не повинна перевищувати 16 символів",
|
||||
"finish_sponsorship": "❌ **Дія неможлива**\nПерш ніж заповнювати анкету, треба завершити заповнення форми спонсора.",
|
||||
"finish_application": "❌ **Дія неможлива**\nПерш ніж заповнювати форму спонсора, треба завершити заповнення анкети.",
|
||||
"nearby_invalid": "",
|
||||
"nearby_error": "",
|
||||
"nearby_invalid": "ℹ️ **Місце не знайдено**\nЗа наданим запитом не знайдено місце з координатами. Спробуйте ще раз формулючи запит в стилі \"Чернівці\" або \"Київська область\".",
|
||||
"nearby_error": "⚠️ **Сталась помилка**\n\nПомилка: `{0}`\n\nTraceback:\n```\n{1}\n```",
|
||||
"nearby_result": "Результати пошуку:\n\n{0}",
|
||||
"nearby_empty": "Здається, нікого поблизу немає.",
|
||||
"voice_message": [
|
||||
"why are u gae",
|
||||
"руки відірвало? пиши як людина",
|
||||
|
@ -1,3 +1,4 @@
|
||||
from traceback import print_exc
|
||||
from app import app
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import Message
|
||||
@ -14,30 +15,39 @@ async def cmd_nearby(app: Client, msg: Message):
|
||||
|
||||
holo_user = HoloUser(msg.from_user)
|
||||
|
||||
if len(msg.command) < 2:
|
||||
# Check if any place provided
|
||||
if len(msg.command) < 2: # Action if no place provided
|
||||
application = col_applications.find_one({"user": msg.from_user})
|
||||
if application is None:
|
||||
await msg.reply_text(locale("nearby_user_empty", "message", locale=holo_user))
|
||||
return
|
||||
location = application["application"]["3"]["loc"][0], application["application"]["3"]["loc"][1]
|
||||
else:
|
||||
else: # Find a place from input query
|
||||
try:
|
||||
location_coordinates = find_location(" ".join(msg.command[2:]))
|
||||
location = location_coordinates["lng"], location_coordinates["lat"]
|
||||
except PlaceNotFoundError:
|
||||
except PlaceNotFoundError: # Place is not found
|
||||
await msg.reply_text(locale("nearby_invalid", "message", locale=holo_user), quote=should_quote(msg))
|
||||
return
|
||||
except Exception as exp:
|
||||
await msg.reply_text(locale("nearby_error", "message", locale=holo_user), quote=should_quote(msg))
|
||||
except Exception as exp: # Error occurred while finding the place
|
||||
await msg.reply_text(locale("nearby_error", "message", locale=holo_user).format(exp, print_exc()), quote=should_quote(msg))
|
||||
return
|
||||
|
||||
# Find all users registered in the area provided
|
||||
output = []
|
||||
users_nearby = col_applications.find( {"application.loc": {"$near": { "$geometry": { "type": "Point", "coordinates": location }, "$maxDistance": 30000 }} } )
|
||||
|
||||
for user in users_nearby:
|
||||
output.append(user)
|
||||
if user["tg_username"] not in [None, "None", ""]: # Check if user has any name
|
||||
output.append(f'• {user["tg_name"]} (@{user["tg_username"]}):\n {user["application"]["3"]["Name"]}, {user["application"]["3"]["adminName1"]}')
|
||||
else:
|
||||
output.append(f'• {user["tg_name"]}:\n {user["application"]["3"]["Name"]}, {user["application"]["3"]["adminName1"]}')
|
||||
|
||||
await msg.reply_text("Yes, I exist.", quote=should_quote(msg))
|
||||
# Check if any users found
|
||||
if len(output) > 0:
|
||||
await msg.reply_text(locale("nearby_result", "message", locale=holo_user).format("\n".join(output)), quote=should_quote(msg))
|
||||
else:
|
||||
await msg.reply_text(locale("nearby_empty", "message", locale=holo_user), quote=should_quote(msg))
|
||||
|
||||
# if not path.exists(f"{configGet('data', 'locations')}{sep}sponsors{sep}{msg.from_user.id}.json"):
|
||||
# jsonSave(jsonLoad(f"{configGet('data', 'locations')}{sep}sponsor_default.json"), f"{configGet('data', 'locations')}{sep}sponsors{sep}{msg.from_user.id}.json")
|
||||
|
Reference in New Issue
Block a user