[SVN] release 0.3.3

[UPD] [BREAK] config update; please, see example `media_external_formats`
[ADD] possibility to upload media (supported formats — in config) with external links; compliant with XEP-0363 HTTP Upload
This commit is contained in:
annelin
2018-07-02 02:02:02 +00:00
parent f0ef3abb9c
commit 03f3231aed
3 changed files with 15 additions and 6 deletions

View File

@@ -10,7 +10,7 @@ import sleekxmpp
from sleekxmpp.componentxmpp import ComponentXMPP
import xml.etree.ElementTree as ET
from telethon.tl.functions.messages import GetDialogsRequest, SendMessageRequest, ImportChatInviteRequest, GetFullChatRequest, AddChatUserRequest, DeleteChatUserRequest, CreateChatRequest, DeleteHistoryRequest
from telethon.tl.functions.messages import GetDialogsRequest, SendMessageRequest, SendMediaRequest, ImportChatInviteRequest, GetFullChatRequest, AddChatUserRequest, DeleteChatUserRequest, CreateChatRequest, DeleteHistoryRequest
from telethon.tl.functions.account import UpdateStatusRequest, GetAuthorizationsRequest, UpdateProfileRequest, UpdateUsernameRequest
from telethon.tl.functions.contacts import DeleteContactRequest, BlockRequest, UnblockRequest, ImportContactsRequest
from telethon.tl.functions.channels import JoinChannelRequest, LeaveChannelRequest, InviteToChannelRequest, EditBannedRequest, CreateChannelRequest
@@ -21,6 +21,7 @@ from telethon.tl.types import PeerChannel, PeerChat, PeerUser, Chat, ChatForbidd
from telethon.tl.types import UserStatusOnline, UserStatusRecently, UserStatusOffline
from telethon.tl.types import Updates, UpdateShortSentMessage, UpdateMessageID
from telethon.tl.types import ChannelBannedRights
from telethon.tl.types import InputMediaPhotoExternal
from telethon.tl.types.messages import Dialogs, DialogsSlice
from telethon.helpers import generate_random_long
@@ -145,10 +146,16 @@ class XMPPTelegram(ComponentXMPP):
tg_peer = InputPeerChannel(tg_id, self.tg_dialogs[jid]['supergroups'][tg_id].access_hash)
if tg_peer:
# Отправляем сообщение и получаем новый апдейт
result = self.tg_connections[jid].invoke(
SendMessageRequest(tg_peer, msg, generate_random_long(), reply_to_msg_id=reply_mid)
)
# 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:
result = self.tg_connections[jid].invoke(SendMessageRequest(tg_peer, msg, generate_random_long(), reply_to_msg_id=reply_mid))
msg_id = None
# Ищем ID отправленного сообщения