[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:
@@ -22,6 +22,8 @@ CONFIG = {
|
|||||||
|
|
||||||
'db_connect': 'db.sqlite',
|
'db_connect': 'db.sqlite',
|
||||||
|
|
||||||
|
'media_external_formats': 'png|jpg|jpeg|gif|mp3|mp4|ogg',
|
||||||
|
|
||||||
'media_web_link_prefix': 'http://tlgrm.localhost/media/',
|
'media_web_link_prefix': 'http://tlgrm.localhost/media/',
|
||||||
'media_store_path': '/var/tg4xmpp/media/',
|
'media_store_path': '/var/tg4xmpp/media/',
|
||||||
'media_max_download_size': 1024 * 1024 * 100, # in bytes
|
'media_max_download_size': 1024 * 1024 * 100, # in bytes
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
from xmpp_tg.xmpp import XMPPTelegram
|
from xmpp_tg.xmpp import XMPPTelegram
|
||||||
|
|
||||||
__version__ = '0.3.2'
|
__version__ = '0.3.3'
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import sleekxmpp
|
|||||||
from sleekxmpp.componentxmpp import ComponentXMPP
|
from sleekxmpp.componentxmpp import ComponentXMPP
|
||||||
import xml.etree.ElementTree as ET
|
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.account import UpdateStatusRequest, GetAuthorizationsRequest, UpdateProfileRequest, UpdateUsernameRequest
|
||||||
from telethon.tl.functions.contacts import DeleteContactRequest, BlockRequest, UnblockRequest, ImportContactsRequest
|
from telethon.tl.functions.contacts import DeleteContactRequest, BlockRequest, UnblockRequest, ImportContactsRequest
|
||||||
from telethon.tl.functions.channels import JoinChannelRequest, LeaveChannelRequest, InviteToChannelRequest, EditBannedRequest, CreateChannelRequest
|
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 UserStatusOnline, UserStatusRecently, UserStatusOffline
|
||||||
from telethon.tl.types import Updates, UpdateShortSentMessage, UpdateMessageID
|
from telethon.tl.types import Updates, UpdateShortSentMessage, UpdateMessageID
|
||||||
from telethon.tl.types import ChannelBannedRights
|
from telethon.tl.types import ChannelBannedRights
|
||||||
|
from telethon.tl.types import InputMediaPhotoExternal
|
||||||
from telethon.tl.types.messages import Dialogs, DialogsSlice
|
from telethon.tl.types.messages import Dialogs, DialogsSlice
|
||||||
|
|
||||||
from telethon.helpers import generate_random_long
|
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)
|
tg_peer = InputPeerChannel(tg_id, self.tg_dialogs[jid]['supergroups'][tg_id].access_hash)
|
||||||
|
|
||||||
if tg_peer:
|
if tg_peer:
|
||||||
# Отправляем сообщение и получаем новый апдейт
|
# detect media
|
||||||
result = self.tg_connections[jid].invoke(
|
if msg.startswith('http') and re.match(r'(?:http\:|https\:)?\/\/.*\.(?:' + self.config['media_external_formats'] + ')', msg):
|
||||||
SendMessageRequest(tg_peer, msg, generate_random_long(), reply_to_msg_id=reply_mid)
|
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
|
msg_id = None
|
||||||
|
|
||||||
# Ищем ID отправленного сообщения
|
# Ищем ID отправленного сообщения
|
||||||
|
|||||||
Reference in New Issue
Block a user