mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
Update safe_split_text function, added split_separator param (#515)
Co-authored-by: Stefan Vasilenko <sv@nuts-agency.ru>
This commit is contained in:
parent
76955bf8f1
commit
6c423d2b92
1 changed files with 3 additions and 2 deletions
|
|
@ -15,12 +15,13 @@ def split_text(text: str, length: int = MAX_MESSAGE_LENGTH) -> typing.List[str]:
|
|||
return [text[i:i + length] for i in range(0, len(text), length)]
|
||||
|
||||
|
||||
def safe_split_text(text: str, length: int = MAX_MESSAGE_LENGTH) -> typing.List[str]:
|
||||
def safe_split_text(text: str, length: int = MAX_MESSAGE_LENGTH, split_separator: str = ' ') -> typing.List[str]:
|
||||
"""
|
||||
Split long text
|
||||
|
||||
:param text:
|
||||
:param length:
|
||||
:param split_separator
|
||||
:return:
|
||||
"""
|
||||
# TODO: More informative description
|
||||
|
|
@ -30,7 +31,7 @@ def safe_split_text(text: str, length: int = MAX_MESSAGE_LENGTH) -> typing.List[
|
|||
while temp_text:
|
||||
if len(temp_text) > length:
|
||||
try:
|
||||
split_pos = temp_text[:length].rindex(' ')
|
||||
split_pos = temp_text[:length].rindex(split_separator)
|
||||
except ValueError:
|
||||
split_pos = length
|
||||
if split_pos < length // 4 * 3:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue