Merge Beta with Stable releases #1

Merged
profitroll merged 52 commits from dev into master 2022-12-16 16:14:41 +02:00
Showing only changes of commit bc8cd8a8ce - Show all commits

View File

@ -1,12 +1,13 @@
from datetime import datetime
from os import path, sep
from app import app, isAnAdmin
from pyrogram.types import InlineQueryResultArticle, InputTextMessageContent
from pyrogram.enums.chat_type import ChatType
from pyrogram.enums.chat_members_filter import ChatMembersFilter
from dateutil.relativedelta import relativedelta
from app import app, isAnAdmin
from modules.utils import configGet, jsonLoad, locale
from classes.holo_user import HoloUser, UserInvalidError, UserNotFoundError
from modules.utils import configGet, locale
from modules.database import col_applications
@app.on_inline_query()
async def inline_answer(client, inline_query):
@ -25,7 +26,23 @@ async def inline_answer(client, inline_query):
)
return
if (path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{inline_query.from_user.id}.json") and jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{inline_query.from_user.id}.json")["approved"]) or (await isAnAdmin(inline_query.from_user.id) is True):
try:
holo_user = HoloUser(inline_query.from_user)
except (UserNotFoundError, UserInvalidError):
await inline_query.answer(
results=[
InlineQueryResultArticle(
title=locale("title", "inline", "forbidden"),
input_message_content=InputTextMessageContent(
locale("message_content", "inline", "forbidden")
),
description=locale("description", "inline", "forbidden")
)
]
)
return
if holo_user.application_approved() or (await isAnAdmin(holo_user.id) is True):
list_of_users = []
async for m in app.get_chat_members(configGet("destination_group"), limit=configGet("inline_preview_count"), filter=ChatMembersFilter.SEARCH, query=inline_query.query):
@ -33,26 +50,30 @@ async def inline_answer(client, inline_query):
results = []
applications = jsonLoad(f"{configGet('data', 'locations')}{sep}applications.json")
for match in list_of_users:
try:
application_content = []
i = 1
for question in applications[str(match.user.id)]["application"]:
if i == 2:
age = relativedelta(datetime.now(), datetime.strptime(applications[str(match.user.id)]['application']['2'], '%d.%m.%Y'))
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {applications[str(match.user.id)]['application']['2']} ({age.years} р.)")
application = col_applications.find_one({"user": match.user.id})
if application is None:
continue
application_content = []
i = 1
for question in application['application']:
if i == 2:
age = relativedelta(datetime.now(), application['application']['2'])
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['2'].strftime('%d.%m.%Y')} ({age.years} р.)")
elif i == 3:
if application['application']['3']['countryCode'] == "UA":
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['3']['name']}")
else:
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {applications[str(match.user.id)]['application'][question]}")
i += 1
except KeyError:
continue
except FileNotFoundError:
continue
except TypeError:
continue
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {application['application']['3']['name']} ({application['application']['3']['adminName1']}, {application['application']['3']['countryName']})")
else:
application_content.append(f"{locale(f'question{i}', 'message', 'question_titles')} {application['application'][question]}")
i += 1
if match.user.photo != None:
try:
@ -104,17 +125,3 @@ async def inline_answer(client, inline_query):
results=results,
cache_time=10
)
else:
await inline_query.answer(
results=[
InlineQueryResultArticle(
title=locale("title", "inline", "forbidden"),
input_message_content=InputTextMessageContent(
locale("message_content", "inline", "forbidden")
),
description=locale("description", "inline", "forbidden")
)
]
)
return