Skip to content

Commit

Permalink
Merge pull request #4 from bralbral/develop
Browse files Browse the repository at this point in the history
Additional information about the user when sending a message
  • Loading branch information
bralbral committed Oct 5, 2023
2 parents 31bdb7b + 4b3eb86 commit 7395f8a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
aiogram==3.1.1
# sulguk==0.6.0
# wait for fix https://github.com/Tishka17/sulguk/issues/19
git+https://github.com/bralbral/sulguk.git
sulguk==0.6.0
pydantic-settings==2.0.3
pyaml==23.9.7
structlog~=23.1.0
Expand Down
4 changes: 2 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pre-commit==3.4.0
black==23.9.1
autoflake==2.2.1
reorder-python-imports==3.11.0
pyupgrade==3.11.1
reorder-python-imports==3.12.0
pyupgrade==3.14.0
git+https://github.com/aio-libs/sort-all.git
7 changes: 4 additions & 3 deletions src/bot/handlers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from aiogram.types import Message
from sulguk import SULGUK_PARSE_MODE

from .utils import extract_userinfo_from_message
from src.config import Errors
from src.config import Messages

Expand Down Expand Up @@ -49,11 +50,11 @@ async def handle_user_message(
message_id = message.message_id

if message.text:
if len(message.text) > 4000:
if len(message.text) > 3500:
await message.reply(text=errors.too_long_message_text)
return

message_text = f"<br/>#id{message.from_user.id}<br/>" + message.html_text
message_text = extract_userinfo_from_message(message) + message.html_text

await bot.send_message(
chat_id=chat_id, text=message_text, parse_mode=SULGUK_PARSE_MODE
Expand All @@ -65,7 +66,7 @@ async def handle_user_message(
return

caption = message.caption if message.caption else ""
caption += f"<br/>#id{message.from_user.id}<br/>"
caption += extract_userinfo_from_message

await bot.copy_message(
chat_id=chat_id,
Expand Down
27 changes: 27 additions & 0 deletions src/bot/handlers/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from aiogram.types import Message


def extract_userinfo_from_message(message: Message) -> str:
"""
Extract information from message.from_user
:param message:
:return:
"""
return f"""
#id{message.from_user.id}
<br/>
<kbd>
username: {message.from_user.username}
<br/>
first_name: {message.from_user.first_name}
<br/>
last_name: {message.from_user.last_name}
<br/>
language_cod: {message.from_user.language_code}
<br/>
</kbd>
<br/>
"""


__all__ = ["extract_userinfo_from_message"]

0 comments on commit 7395f8a

Please sign in to comment.