From 1d61392db25247824d708ffaf1736780d28de956 Mon Sep 17 00:00:00 2001 From: annelin Date: Mon, 2 Jul 2018 15:09:18 +0000 Subject: [PATCH] =?UTF-8?q?[SVN]=20release=200.3.4=20[FIX]=20corrext=20exc?= =?UTF-8?q?eption=20handling=20when=20uploading=20media;=20if=20exception?= =?UTF-8?q?=20caught=E2=80=94=20we=20will=20just=20send=20link=20as=20plai?= =?UTF-8?q?ntext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- xmpp_tg/__init__.py | 2 +- xmpp_tg/xmpp.py | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/xmpp_tg/__init__.py b/xmpp_tg/__init__.py index 573e21c..1874bf8 100644 --- a/xmpp_tg/__init__.py +++ b/xmpp_tg/__init__.py @@ -1,3 +1,3 @@ from xmpp_tg.xmpp import XMPPTelegram -__version__ = '0.3.3' +__version__ = '0.3.4' diff --git a/xmpp_tg/xmpp.py b/xmpp_tg/xmpp.py index 3e740ab..8eed3fe 100644 --- a/xmpp_tg/xmpp.py +++ b/xmpp_tg/xmpp.py @@ -146,14 +146,20 @@ class XMPPTelegram(ComponentXMPP): tg_peer = InputPeerChannel(tg_id, self.tg_dialogs[jid]['supergroups'][tg_id].access_hash) if tg_peer: + result = None + # detect media if msg.startswith('http') and re.match(r'(?:http\:|https\:)?\/\/.*\.(?:' + self.config['media_external_formats'] + ')', msg): urls = re.findall(r'(?:http\:|https\:)?\/\/.*\.(?:' + self.config['media_external_formats'] + ')', msg) message = msg.replace(urls[0], '') media = InputMediaPhotoExternal(urls[0]) - result = self.tg_connections[jid].invoke(SendMediaRequest(tg_peer, media, message, random_id = generate_random_long(), reply_to_msg_id = reply_mid)) - # no media — plain message # - else: + try: + result = self.tg_connections[jid].invoke(SendMediaRequest(tg_peer, media, message, random_id = generate_random_long(), reply_to_msg_id = reply_mid)) + except Exception: + print('Media upload failed.') + + # media send failed. # + if not result: result = self.tg_connections[jid].invoke(SendMessageRequest(tg_peer, msg, generate_random_long(), reply_to_msg_id=reply_mid)) msg_id = None