@@ -263,8 +263,10 @@ def ok_update(self):
263263 return True
264264
265265
266- def markdown_fix (message , offset ):
266+ def markdown_fix (message , offset , emoji = False ):
267267 offset = int (offset )
268+ if emoji : # https://github.com/ableev/Zabbix-in-Telegram/issues/152
269+ offset -= 2
268270 message = "\n " .join (message )
269271 message = message [:offset ] + message [offset + 1 :]
270272 message = message .split ("\n " )
@@ -822,13 +824,16 @@ def main():
822824 pass
823825
824826 # replace text with emojis
827+ internal_using_emoji = False # I hate that, but... https://github.com/ableev/Zabbix-in-Telegram/issues/152
825828 if hasattr (zbxtg_settings , "emoji_map" ):
826829 zbxtg_body_text_emoji_support = []
827830 for l in zbxtg_body_text :
828831 l_new = l
829832 for k , v in list (zbxtg_settings .emoji_map .items ()):
830833 l_new = l_new .replace ("{{" + k + "}}" , v )
831834 zbxtg_body_text_emoji_support .append (l_new )
835+ if len ("" .join (zbxtg_body_text )) - len ("" .join (zbxtg_body_text_emoji_support )):
836+ internal_using_emoji = True
832837 zbxtg_body_text = zbxtg_body_text_emoji_support
833838
834839 if not is_single_message :
@@ -844,15 +849,19 @@ def main():
844849
845850 # another case if markdown is enabled and we got parse error, try to remove "bad" symbols from message
846851 if tg .markdown and tg .error .find ("Can't find end of the entity starting at byte offset" ) > - 1 :
852+ markdown_warning = "Original message has been fixed due to {0}. " \
853+ "Please, fix the markdown, it's slowing down messages sending." \
854+ .format (url_wiki_base + "/" + settings_description ["markdown" ]["url" ])
847855 markdown_fix_attempts = 0
848- while not tg .ok and markdown_fix_attempts != 10 :
856+ while not tg .ok and markdown_fix_attempts != 3 :
849857 offset = re .search ("Can't find end of the entity starting at byte offset ([0-9]+)" , tg .error ).group (1 )
850- zbxtg_body_text = markdown_fix (zbxtg_body_text , offset )
858+ zbxtg_body_text = markdown_fix (zbxtg_body_text , offset , emoji = internal_using_emoji ) + \
859+ ["\n " ] + [markdown_warning ]
860+ tg .disable_web_page_preview = True
851861 tg .send_message (uid , zbxtg_body_text )
852862 markdown_fix_attempts += 1
853863 if tg .ok :
854- print_message ("Original message has been fixed due to {0}"
855- .format (url_wiki_base + "/" + settings_description ["markdown" ]["url" ]))
864+ print_message (markdown_warning )
856865
857866 if is_debug :
858867 print ((tg .result ))
0 commit comments