-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
214 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
""" | ||
Inline query handler for the bot. | ||
Provides user search functionality through inline mode. | ||
""" | ||
|
||
from aiogram import Router, types | ||
from aiogram.types import InlineQueryResultArticle, InputTextMessageContent | ||
from marzban import UsersResponse | ||
|
||
from utils import panel, text_info, EnvSettings, BotKeyboards | ||
from db.crud import TokenManager | ||
|
||
router = Router() | ||
|
||
|
||
@router.inline_query() | ||
async def get(query: types.InlineQuery): | ||
""" | ||
Handle inline queries to search and display user information. | ||
""" | ||
text = query.query.strip() | ||
results = [] | ||
|
||
emarz = panel.APIClient(EnvSettings.MARZBAN_ADDRESS) | ||
token = await TokenManager.get() | ||
users: UsersResponse = await emarz.get_users( | ||
search=text, limit=5, token=token.token | ||
) | ||
|
||
for user in users.users: | ||
user_info = text_info.user_info(user) | ||
|
||
result = InlineQueryResultArticle( | ||
id=user.username, | ||
title=f"{user.username}", | ||
description=f"Status: {user.status}", | ||
input_message_content=InputTextMessageContent( | ||
message_text=user_info, parse_mode="HTML" | ||
), | ||
reply_markup=BotKeyboards.user(user), | ||
) | ||
|
||
results.append(result) | ||
|
||
await query.answer(results=results, cache_time=10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters