/nearby, subscriptions check, geocoding #2

Merged
profitroll merged 30 commits from dev into master 2023-01-02 12:16:38 +02:00
2 changed files with 21 additions and 9 deletions
Showing only changes of commit 8b2abc2cfa - Show all commits

View File

@ -92,8 +92,10 @@
"label_too_long": "Довжина назви ролі не повинна перевищувати 16 символів", "label_too_long": "Довжина назви ролі не повинна перевищувати 16 символів",
"finish_sponsorship": "❌ **Дія неможлива**\nПерш ніж заповнювати анкету, треба завершити заповнення форми спонсора.", "finish_sponsorship": "❌ **Дія неможлива**\nПерш ніж заповнювати анкету, треба завершити заповнення форми спонсора.",
"finish_application": "❌ **Дія неможлива**\nПерш ніж заповнювати форму спонсора, треба завершити заповнення анкети.", "finish_application": "❌ **Дія неможлива**\nПерш ніж заповнювати форму спонсора, треба завершити заповнення анкети.",
"nearby_invalid": "", "nearby_invalid": " **Місце не знайдено**\nЗа наданим запитом не знайдено місце з координатами. Спробуйте ще раз формулючи запит в стилі \"Чернівці\" або \"Київська область\".",
"nearby_error": "", "nearby_error": "⚠️ **Сталась помилка**\n\nПомилка: `{0}`\n\nTraceback:\n```\n{1}\n```",
"nearby_result": "Результати пошуку:\n\n{0}",
"nearby_empty": "Здається, нікого поблизу немає.",
"voice_message": [ "voice_message": [
"why are u gae", "why are u gae",
"руки відірвало? пиши як людина", "руки відірвало? пиши як людина",

View File

@ -1,3 +1,4 @@
from traceback import print_exc
from app import app from app import app
from pyrogram import filters from pyrogram import filters
from pyrogram.types import Message from pyrogram.types import Message
@ -14,30 +15,39 @@ async def cmd_nearby(app: Client, msg: Message):
holo_user = HoloUser(msg.from_user) 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}) application = col_applications.find_one({"user": msg.from_user})
if application is None: if application is None:
await msg.reply_text(locale("nearby_user_empty", "message", locale=holo_user)) await msg.reply_text(locale("nearby_user_empty", "message", locale=holo_user))
return return
location = application["application"]["3"]["loc"][0], application["application"]["3"]["loc"][1] location = application["application"]["3"]["loc"][0], application["application"]["3"]["loc"][1]
else: else: # Find a place from input query
try: try:
location_coordinates = find_location(" ".join(msg.command[2:])) location_coordinates = find_location(" ".join(msg.command[2:]))
location = location_coordinates["lng"], location_coordinates["lat"] 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)) await msg.reply_text(locale("nearby_invalid", "message", locale=holo_user), quote=should_quote(msg))
return return
except Exception as exp: except Exception as exp: # Error occurred while finding the place
await msg.reply_text(locale("nearby_error", "message", locale=holo_user), quote=should_quote(msg)) await msg.reply_text(locale("nearby_error", "message", locale=holo_user).format(exp, print_exc()), quote=should_quote(msg))
return return
# Find all users registered in the area provided
output = [] output = []
users_nearby = col_applications.find( {"application.loc": {"$near": { "$geometry": { "type": "Point", "coordinates": location }, "$maxDistance": 30000 }} } ) users_nearby = col_applications.find( {"application.loc": {"$near": { "$geometry": { "type": "Point", "coordinates": location }, "$maxDistance": 30000 }} } )
for user in users_nearby: 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"): # 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") # jsonSave(jsonLoad(f"{configGet('data', 'locations')}{sep}sponsor_default.json"), f"{configGet('data', 'locations')}{sep}sponsors{sep}{msg.from_user.id}.json")