Browse Source

Upload stickers with http upload

And fix minor things
drymer 2 years ago
parent
commit
c5505f8eef
1 changed files with 21 additions and 8 deletions
  1. 21
    8
      jabbergram.py

+ 21
- 8
jabbergram.py View File

@@ -5,6 +5,7 @@ try:
5 5
     import requests
6 6
 except:
7 7
     print("HTTP Upload support disabled.")
8
+
8 9
 import sleekxmpp
9 10
 import telegram
10 11
 import configparser
@@ -26,8 +27,9 @@ class Request(ElementBase):
26 27
     interfaces = set(('filename', 'size'))
27 28
     sub_interfaces = interfaces
28 29
 
30
+
29 31
 class Jabbergram(sleekxmpp.ClientXMPP):
30
-    def __init__(self, jid, password, rooms, nick, token, groups):
32
+    def __init__(self, jid, password, rooms, nick, token, groups, verify_ssl):
31 33
         # XMPP
32 34
         super(Jabbergram, self).__init__(jid, password)
33 35
         self.add_event_handler('session_start', self.start)
@@ -38,6 +40,7 @@ class Jabbergram(sleekxmpp.ClientXMPP):
38 40
         self.token = token
39 41
         self.xmpp_users = {}
40 42
         self.jid = jid
43
+        self.verify_ssl = verify_ssl
41 44
 
42 45
         for muc in self.muc_rooms:
43 46
             self.add_event_handler("muc::%s::got_online" % muc,
@@ -85,6 +88,7 @@ class Jabbergram(sleekxmpp.ClientXMPP):
85 88
 
86 89
     def read_tg(self):
87 90
         update_id = 0
91
+
88 92
         # wait until http_upload has been tested
89 93
         sleep(5)
90 94
         while True:
@@ -110,6 +114,7 @@ class Jabbergram(sleekxmpp.ClientXMPP):
110 114
                        update.message.photo or update.message.video \
111 115
                        or update.message.voice or update.message.sticker:
112 116
                         # proceed only if http upload is available
117
+
113 118
                         if self.max_size is not None:
114 119
                             if update.message.audio:
115 120
                                 d_file = update.message.audio
@@ -131,13 +136,18 @@ class Jabbergram(sleekxmpp.ClientXMPP):
131 136
                                 d_file = update.message.voice
132 137
                                 ext = '.ogg'
133 138
                                 size = d_file.file_size
139
+                            elif update.message.sticker:
140
+                                d_file = update.message.sticker
141
+                                ext = '.png'
142
+                                size = d_file.file_size
134 143
                             if self.max_size >= int(size):
135 144
                                 t_file = self.bot.getFile(d_file.file_id)
136 145
                                 f_name = '/tmp/' + d_file.file_id + ext
137 146
                                 t_file.download(f_name)
138 147
                                 url = self.http_upload.upload(
139
-                                                              self.component,
140
-                                                              '', f_name, size)
148
+                                    self.component,
149
+                                    self.verify_ssl,
150
+                                    f_name, size)
141 151
 
142 152
                                 if update.message.caption:
143 153
                                     message = update.message.caption + ' '
@@ -158,7 +168,7 @@ class Jabbergram(sleekxmpp.ClientXMPP):
158 168
                     elif update.message.left_chat_member:
159 169
                         message = 'This user has left the group.'
160 170
                     elif update.message.new_chat_title:
161
-                        message = 'The group\'s title has changed: '+ \
171
+                        message = 'The group\'s title has changed: ' + \
162 172
                           update.message.new_chat_title
163 173
                     elif update.message.new_chat_photo:
164 174
                         message = 'The group\'s photo has changed.'
@@ -175,7 +185,8 @@ class Jabbergram(sleekxmpp.ClientXMPP):
175 185
                             message = update.message.text
176 186
 
177 187
                     if name:
178
-                        msg = message + ' <- ' + user + ": " + update.message.text
188
+                        msg = message + ' <- ' + user + ": " + \
189
+                              update.message.text
179 190
                     else:
180 191
                         msg = user + ": " + message
181 192
 
@@ -353,10 +364,10 @@ class Jabbergram(sleekxmpp.ClientXMPP):
353 364
             xml = minidom.parseString(str(send))
354 365
             put_url = xml.getElementsByTagName('put')[0].firstChild.data
355 366
 
356
-            if verify_ssl == '' or verif_ssl == 'False':
367
+            if verify_ssl == 'False':
357 368
                 req = requests.put(put_url, data=open(u_file, 'rb'),
358 369
                                    verify=False)
359
-            else:
370
+            elif verify_ssl == '':
360 371
                 req = requests.put(put_url, data=open(u_file, 'rb'))
361 372
 
362 373
             return put_url
@@ -383,8 +394,10 @@ if __name__ == '__main__':
383 394
     nick = config[3]
384 395
     token = config[4]
385 396
     groups = config[5]
397
+    verify_ssl = config[6]
386 398
 
387
-    xmpp = Jabbergram(jid, password, muc_rooms, nick, token, groups)
399
+    xmpp = Jabbergram(jid, password, muc_rooms, nick, token, groups,
400
+                      verify_ssl)
388 401
     xmpp.register_plugin('xep_0045')
389 402
 
390 403
     if xmpp.connect():

Loading…
Cancel
Save