136 lines
5.8 KiB
Python
136 lines
5.8 KiB
Python
from datetime import datetime
|
||
from os import path, sep
|
||
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
|
||
|
||
@app.on_inline_query()
|
||
async def inline_answer(client, inline_query):
|
||
|
||
if inline_query.chat_type not in [ChatType.BOT, ChatType.PRIVATE]:
|
||
await inline_query.answer(
|
||
results=[
|
||
InlineQueryResultArticle(
|
||
title=locale("title", "inline", "not_pm"),
|
||
input_message_content=InputTextMessageContent(
|
||
locale("message_content", "inline", "not_pm")
|
||
),
|
||
description=locale("description", "inline", "not_pm")
|
||
)
|
||
]
|
||
)
|
||
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)):
|
||
|
||
list_of_users = []
|
||
async for m in app.get_chat_members(configGet("admin_group"), filter=ChatMembersFilter.SEARCH, query=inline_query.query):
|
||
list_of_users.append(m)
|
||
|
||
#list_of_names = []
|
||
|
||
#list_filtered = [v for v in (list_of_users) if inline_query.query in v]
|
||
|
||
results = []
|
||
|
||
for match in list_of_users:
|
||
# if match.user.photo != None:
|
||
# results.append(
|
||
# InlineQueryResultArticle(
|
||
# title=str(match.user.first_name),
|
||
# input_message_content=InputTextMessageContent(
|
||
# f"More about @{match.user.username}"
|
||
# ),
|
||
# description=f"More info about {match.user.username}",
|
||
# thumb_url=f'https://api.telegram.org/bot{configGet("bot_token", "bot")}/{match.user.photo.big_file_id}',
|
||
# thumb_height=640,
|
||
# thumb_width=640
|
||
# )
|
||
# )
|
||
# else:
|
||
|
||
try:
|
||
user_data = jsonLoad(f"{configGet('data', 'locations')}{sep}users{sep}{match.user.id}.json")
|
||
application_content = []
|
||
i = 1
|
||
for question in configGet("application", file=str(match.user.id)):
|
||
if i == 2:
|
||
age = relativedelta(datetime.now(), datetime.strptime(configGet('application', file=str(match.user.id))['2'], '%d.%m.%Y'))
|
||
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {configGet('application', file=str(match.user.id))['2']} ({age.years} р.)")
|
||
else:
|
||
application_content.append(f"{locale('question'+str(i), 'message', 'question_titles')} {configGet('application', file=str(match.user.id))[question]}")
|
||
i += 1
|
||
results.append(
|
||
InlineQueryResultArticle(
|
||
title=str(match.user.first_name),
|
||
input_message_content=InputTextMessageContent(
|
||
locale("message_content", "inline", "user").format(match.user.first_name, match.user.username, "\n".join(application_content))
|
||
),
|
||
description=locale("description", "inline", "user").format(match.user.first_name, match.user.username)
|
||
)
|
||
)
|
||
except FileNotFoundError:
|
||
pass
|
||
except TypeError:
|
||
pass
|
||
|
||
await inline_query.answer(
|
||
results=results,
|
||
cache_time=10
|
||
)
|
||
|
||
# await inline_query.answer(
|
||
# results=[
|
||
# InlineQueryResultArticle(
|
||
# title="Installation",
|
||
# input_message_content=InputTextMessageContent(
|
||
# "Here's how to install **Pyrogram**"
|
||
# ),
|
||
# url="https://docs.pyrogram.org/intro/install",
|
||
# description="How to install Pyrogram",
|
||
# reply_markup=InlineKeyboardMarkup(
|
||
# [
|
||
# [InlineKeyboardButton(
|
||
# "Open website",
|
||
# url="https://docs.pyrogram.org/intro/install"
|
||
# )]
|
||
# ]
|
||
# )
|
||
# ),
|
||
# InlineQueryResultArticle(
|
||
# title="Usage",
|
||
# input_message_content=InputTextMessageContent(
|
||
# "Here's how to use **Pyrogram**"
|
||
# ),
|
||
# url="https://docs.pyrogram.org/start/invoking",
|
||
# description="How to use Pyrogram",
|
||
# reply_markup=InlineKeyboardMarkup(
|
||
# [
|
||
# [InlineKeyboardButton(
|
||
# "Open website",
|
||
# url="https://docs.pyrogram.org/start/invoking"
|
||
# )]
|
||
# ]
|
||
# )
|
||
# )
|
||
# ],
|
||
# cache_time=1
|
||
# )
|
||
|
||
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 |