diff --git a/README.md b/README.md index 24e4ef2..9338e56 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ You can see config file with all the comments below: "age_allowed": 0, # minimum age of user that submits application "birthdays_notify": true, # notify admin group about birthdays "birthdays_time": "09:00", # server time when to notify about birthdays - "api": "http://127.0.0.1:9024", # API server address + "api": "http://example.com", # API server's external address "admin_group": 0, # telegram ID of a admin's group "destination_group": 0, # telegram ID of a user's group "admins": [], # list of telegram ID's of users that are admins diff --git a/api_avatars.py b/api_avatars.py index a6f2b7b..46051ad 100644 --- a/api_avatars.py +++ b/api_avatars.py @@ -9,6 +9,6 @@ app = FastAPI(title="HoloUA Avatars API", docs_url=None, redoc_url=None, version @app.get("/", response_class=FileResponse, include_in_schema=False) async def favicon(avatar_id: str): if path.exists(f'{configGet("cache", "locations")}{sep}avatars{sep}{avatar_id}'): - return FileResponse(f'{configGet("cache", "locations")}{sep}avatars{sep}{avatar_id}') + return FileResponse(f'{configGet("cache", "locations")}{sep}avatars{sep}{avatar_id}', media_type="image/jpg") else: raise HTTPException(status_code=HTTP_404_NOT_FOUND, detail="File not found") \ No newline at end of file diff --git a/config_example.json b/config_example.json index d298209..8291b4a 100644 --- a/config_example.json +++ b/config_example.json @@ -5,7 +5,7 @@ "age_allowed": 0, "birthdays_notify": true, "birthdays_time": "09:00", - "api": "http://127.0.0.1:9024", + "api": "http://example.com", "admin_group": 0, "destination_group": 0, "admins": [], diff --git a/modules/inline.py b/modules/inline.py index 0676dd8..bd75e16 100644 --- a/modules/inline.py +++ b/modules/inline.py @@ -38,6 +38,59 @@ async def inline_answer(client, inline_query): results = [] for match in list_of_users: + + 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 + except FileNotFoundError: + continue + except TypeError: + continue + + if match.user.photo != None: + try: + await app.download_media(match.user.photo.big_file_id, file_name=f'{configGet("cache", "locations")}{sep}avatars{sep}{match.user.photo.big_file_id}') + 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), + thumb_url=f'{configGet("api")}/?avatar_id={match.user.photo.big_file_id}', + # thumb_height=640, + # thumb_width=640 + ) + ) + print(f'{configGet("api")}/?avatar_id={match.user.photo.big_file_id}', flush=True) + except ValueError: + 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) + ) + ) + else: + 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) + ) + ) # if match.user.photo != None: # results.append( # InlineQueryResultArticle( @@ -53,31 +106,6 @@ async def inline_answer(client, inline_query): # ) # 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