parent
ed6d8a142e
commit
c5505f8eef
|
@ -5,6 +5,7 @@ try:
|
|||
import requests
|
||||
except:
|
||||
print("HTTP Upload support disabled.")
|
||||
|
||||
import sleekxmpp
|
||||
import telegram
|
||||
import configparser
|
||||
|
@ -26,8 +27,9 @@ class Request(ElementBase):
|
|||
interfaces = set(('filename', 'size'))
|
||||
sub_interfaces = interfaces
|
||||
|
||||
|
||||
class Jabbergram(sleekxmpp.ClientXMPP):
|
||||
def __init__(self, jid, password, rooms, nick, token, groups):
|
||||
def __init__(self, jid, password, rooms, nick, token, groups, verify_ssl):
|
||||
# XMPP
|
||||
super(Jabbergram, self).__init__(jid, password)
|
||||
self.add_event_handler('session_start', self.start)
|
||||
|
@ -38,6 +40,7 @@ class Jabbergram(sleekxmpp.ClientXMPP):
|
|||
self.token = token
|
||||
self.xmpp_users = {}
|
||||
self.jid = jid
|
||||
self.verify_ssl = verify_ssl
|
||||
|
||||
for muc in self.muc_rooms:
|
||||
self.add_event_handler("muc::%s::got_online" % muc,
|
||||
|
@ -85,6 +88,7 @@ class Jabbergram(sleekxmpp.ClientXMPP):
|
|||
|
||||
def read_tg(self):
|
||||
update_id = 0
|
||||
|
||||
# wait until http_upload has been tested
|
||||
sleep(5)
|
||||
while True:
|
||||
|
@ -110,6 +114,7 @@ class Jabbergram(sleekxmpp.ClientXMPP):
|
|||
update.message.photo or update.message.video \
|
||||
or update.message.voice or update.message.sticker:
|
||||
# proceed only if http upload is available
|
||||
|
||||
if self.max_size is not None:
|
||||
if update.message.audio:
|
||||
d_file = update.message.audio
|
||||
|
@ -131,13 +136,18 @@ class Jabbergram(sleekxmpp.ClientXMPP):
|
|||
d_file = update.message.voice
|
||||
ext = '.ogg'
|
||||
size = d_file.file_size
|
||||
elif update.message.sticker:
|
||||
d_file = update.message.sticker
|
||||
ext = '.png'
|
||||
size = d_file.file_size
|
||||
if self.max_size >= int(size):
|
||||
t_file = self.bot.getFile(d_file.file_id)
|
||||
f_name = '/tmp/' + d_file.file_id + ext
|
||||
t_file.download(f_name)
|
||||
url = self.http_upload.upload(
|
||||
self.component,
|
||||
'', f_name, size)
|
||||
self.verify_ssl,
|
||||
f_name, size)
|
||||
|
||||
if update.message.caption:
|
||||
message = update.message.caption + ' '
|
||||
|
@ -158,7 +168,7 @@ class Jabbergram(sleekxmpp.ClientXMPP):
|
|||
elif update.message.left_chat_member:
|
||||
message = 'This user has left the group.'
|
||||
elif update.message.new_chat_title:
|
||||
message = 'The group\'s title has changed: '+ \
|
||||
message = 'The group\'s title has changed: ' + \
|
||||
update.message.new_chat_title
|
||||
elif update.message.new_chat_photo:
|
||||
message = 'The group\'s photo has changed.'
|
||||
|
@ -175,7 +185,8 @@ class Jabbergram(sleekxmpp.ClientXMPP):
|
|||
message = update.message.text
|
||||
|
||||
if name:
|
||||
msg = message + ' <- ' + user + ": " + update.message.text
|
||||
msg = message + ' <- ' + user + ": " + \
|
||||
update.message.text
|
||||
else:
|
||||
msg = user + ": " + message
|
||||
|
||||
|
@ -353,10 +364,10 @@ class Jabbergram(sleekxmpp.ClientXMPP):
|
|||
xml = minidom.parseString(str(send))
|
||||
put_url = xml.getElementsByTagName('put')[0].firstChild.data
|
||||
|
||||
if verify_ssl == '' or verif_ssl == 'False':
|
||||
if verify_ssl == 'False':
|
||||
req = requests.put(put_url, data=open(u_file, 'rb'),
|
||||
verify=False)
|
||||
else:
|
||||
elif verify_ssl == '':
|
||||
req = requests.put(put_url, data=open(u_file, 'rb'))
|
||||
|
||||
return put_url
|
||||
|
@ -383,8 +394,10 @@ if __name__ == '__main__':
|
|||
nick = config[3]
|
||||
token = config[4]
|
||||
groups = config[5]
|
||||
verify_ssl = config[6]
|
||||
|
||||
xmpp = Jabbergram(jid, password, muc_rooms, nick, token, groups)
|
||||
xmpp = Jabbergram(jid, password, muc_rooms, nick, token, groups,
|
||||
verify_ssl)
|
||||
xmpp.register_plugin('xep_0045')
|
||||
|
||||
if xmpp.connect():
|
||||
|
|
Loading…
Reference in New Issue