vicalloy / telegram-shell-bot

A telegram Bot to run shell commands
194 stars 83 forks source link

[Feature request] Split long messages #15

Closed gregorst3 closed 2 years ago

gregorst3 commented 2 years ago

Hello, I have a script with long output, for the limitations imposed, some part of my script's output get lost. Is it possible to do something like this? https://github.com/python-telegram-bot/python-telegram-bot/issues/768#issuecomment-368349130

vicalloy commented 2 years ago

finished

guerman5 commented 1 year ago

Hi @vicalloy I'm also interested in this feature. After updating the code, its running but it doesn't split the message. I've tested both versions, before and after the changes but the outcome is the same (half of the output is lost)

could you check again?

Thanks for your time

guerman5 commented 1 year ago

Here some test results to prove what I'm saying. image As you can see, telegram-shell-bot only sends one message of lenght MAX_TASK_OUTPUT=500, i can increase that to 4096 but that is still less than the total output. The splitting is not happening.

while the benchmark does the spliting: image image

Thank you

vicalloy commented 1 year ago

@guerman5 fixed. telegram's max length is 4096 bytes. Python's len() is by char.

guerman5 commented 1 year ago

Hi @vicalloy , I appreciate your attention :)

    max_length = constants.MAX_MESSAGE_LENGTH // 2
   while msg:
       message.reply_text(msg[:max_length], *args, **kwargs)
       msg = msg[max_length:]

My tests results are not successful :S

I confirm the new code is running as before, image

The message is not being split by consecutive msg of max_length . Seems it is only sending the first msg of "MAX_TASK_OUTPUT", 500. cat /home/user/10K_lines.txt image I can increase that 500 in settings.py (to 2000 for example below), but it just increases the first msg lenght, yet the split wont happen. image

Reference, using same file 10K_lines.txt: image

vicalloy commented 1 year ago

@guerman5

If you want output all message MAX_TASK_OUTPUT should set to a huge number ex: 999999. By default, bot will only send first 3s message. If you want output all message, you should add oa;.

ex: oa;cat poetry.lock