Skip to content

Commit

Permalink
Issue #44: Caption problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekmo committed Jul 13, 2020
1 parent ec1c8e3 commit 2a35a5b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions telegram_upload/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def progress(current, total):
return progress


def truncate(text, max_length):
return (text[:max_length - 3] + '...') if len(text) > max_length else text


class Client(TelegramClient):
def __init__(self, config_file, **kwargs):
config = json.load(open(config_file))
Expand All @@ -65,15 +69,14 @@ def send_files(self, entity, files, delete_on_success=False, print_file_id=False
thumb = get_file_thumb(file)
except ThumbError as e:
click.echo('{}'.format(e), err=True)
caption = caption[:CAPTION_MAX_LENGTH] if caption else caption
caption = caption or ((name[:CAPTION_MAX_LENGTH] + '..') if len(name) > CAPTION_MAX_LENGTH else name)
file_caption = truncate(caption or name, CAPTION_MAX_LENGTH)
try:
if force_file:
attributes = [DocumentAttributeFilename(file)]
else:
attributes = get_file_attributes(file)
message = self.send_file(entity, file, thumb=thumb,
caption=caption, force_document=force_file,
caption=file_caption, force_document=force_file,
progress_callback=progress, attributes=attributes)
except Exception:
raise
Expand Down

0 comments on commit 2a35a5b

Please sign in to comment.