Don't send too large messages
This commit is contained in:
parent
500eb17449
commit
5c4170951a
@ -20,6 +20,9 @@ logger = logging.getLogger(__name__)
|
|||||||
logger.debug('Included module rpc.telegram ...')
|
logger.debug('Included module rpc.telegram ...')
|
||||||
|
|
||||||
|
|
||||||
|
MAX_TELEGRAM_MESSAGE = 4096
|
||||||
|
|
||||||
|
|
||||||
def authorized_only(command_handler: Callable[..., None]) -> Callable[..., Any]:
|
def authorized_only(command_handler: Callable[..., None]) -> Callable[..., Any]:
|
||||||
"""
|
"""
|
||||||
Decorator to check if the message comes from the correct chat_id
|
Decorator to check if the message comes from the correct chat_id
|
||||||
@ -327,13 +330,20 @@ class Telegram(RPC):
|
|||||||
output = ''
|
output = ''
|
||||||
for currency in result['currencies']:
|
for currency in result['currencies']:
|
||||||
if currency['est_btc'] > 0.0001:
|
if currency['est_btc'] > 0.0001:
|
||||||
output += "*{currency}:*\n" \
|
curr_output = "*{currency}:*\n" \
|
||||||
"\t`Available: {available: .8f}`\n" \
|
"\t`Available: {available: .8f}`\n" \
|
||||||
"\t`Balance: {balance: .8f}`\n" \
|
"\t`Balance: {balance: .8f}`\n" \
|
||||||
"\t`Pending: {pending: .8f}`\n" \
|
"\t`Pending: {pending: .8f}`\n" \
|
||||||
"\t`Est. BTC: {est_btc: .8f}`\n".format(**currency)
|
"\t`Est. BTC: {est_btc: .8f}`\n".format(**currency)
|
||||||
else:
|
else:
|
||||||
output += "*{currency}:* not showing <1$ amount \n".format(**currency)
|
curr_output = "*{currency}:* not showing <1$ amount \n".format(**currency)
|
||||||
|
|
||||||
|
# Handle overflowing messsage length
|
||||||
|
if len(output + curr_output) >= MAX_TELEGRAM_MESSAGE:
|
||||||
|
self._send_msg(output, bot=bot)
|
||||||
|
output = curr_output
|
||||||
|
else:
|
||||||
|
output += curr_output
|
||||||
|
|
||||||
output += "\n*Estimated Value*:\n" \
|
output += "\n*Estimated Value*:\n" \
|
||||||
"\t`BTC: {total: .8f}`\n" \
|
"\t`BTC: {total: .8f}`\n" \
|
||||||
|
Loading…
Reference in New Issue
Block a user