[SVN] release 0.3.4
[FIX] corrext exception handling when uploading media; if exception caught— we will just send link as plaintext
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
from xmpp_tg.xmpp import XMPPTelegram
|
from xmpp_tg.xmpp import XMPPTelegram
|
||||||
|
|
||||||
__version__ = '0.3.3'
|
__version__ = '0.3.4'
|
||||||
|
|||||||
@@ -146,14 +146,20 @@ class XMPPTelegram(ComponentXMPP):
|
|||||||
tg_peer = InputPeerChannel(tg_id, self.tg_dialogs[jid]['supergroups'][tg_id].access_hash)
|
tg_peer = InputPeerChannel(tg_id, self.tg_dialogs[jid]['supergroups'][tg_id].access_hash)
|
||||||
|
|
||||||
if tg_peer:
|
if tg_peer:
|
||||||
|
result = None
|
||||||
|
|
||||||
# detect media
|
# detect media
|
||||||
if msg.startswith('http') and re.match(r'(?:http\:|https\:)?\/\/.*\.(?:' + self.config['media_external_formats'] + ')', msg):
|
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)
|
urls = re.findall(r'(?:http\:|https\:)?\/\/.*\.(?:' + self.config['media_external_formats'] + ')', msg)
|
||||||
message = msg.replace(urls[0], '')
|
message = msg.replace(urls[0], '')
|
||||||
media = InputMediaPhotoExternal(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))
|
try:
|
||||||
# no media — plain message #
|
result = self.tg_connections[jid].invoke(SendMediaRequest(tg_peer, media, message, random_id = generate_random_long(), reply_to_msg_id = reply_mid))
|
||||||
else:
|
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))
|
result = self.tg_connections[jid].invoke(SendMessageRequest(tg_peer, msg, generate_random_long(), reply_to_msg_id=reply_mid))
|
||||||
|
|
||||||
msg_id = None
|
msg_id = None
|
||||||
|
|||||||
Reference in New Issue
Block a user