diff options
author | VitaliyS <hetleven@yandex.ua> | 2017-03-18 16:59:17 +0300 |
---|---|---|
committer | VitaliyS <hetleven@yandex.ua> | 2017-03-18 16:59:17 +0300 |
commit | 54fa663954efb0774e6faad2b2c79da5bae8f69e (patch) | |
tree | e1664de70e3482dd9e27d1d686a17f1201258e80 | |
parent | a89086fa8d4bb722d5212121d30bccc8d3a7cb5d (diff) |
upd: oboobs plugin
-rw-r--r-- | kernel.py | 18 | ||||
-rw-r--r-- | plugins/oboobs.py | 10 |
2 files changed, 20 insertions, 8 deletions
@@ -479,15 +479,25 @@ def send_msg(raw_in, msg, parse_mode = 'HTML', custom={}): # Send photo
def send_photo(raw_in, photo, custom={}):
- MSG = { 'chat_id': raw_in['message']['chat'].get('id', '') }
- FLS = {'photo': (photo, open(photo, "rb"))}
+ if re.match('https?://.*\.(jpe?g|png|gif)$', photo.lower()):
+ MSG = { 'chat_id': raw_in['message']['chat'].get('id', ''),
+ 'photo': photo }
+ FLS = {}
+ else:
+ MSG = { 'chat_id': raw_in['message']['chat'].get('id', '') }
+ FLS = {'photo': (photo, open(photo, "rb"))}
MSG.update(custom)
return send_raw(raw_in, 'sendPhoto', MSG, FLS)
# Send document
def send_document(raw_in, document, custom={}):
- MSG = { 'chat_id': raw_in['message']['chat'].get('id', '') }
- FLS = {'document': (document, open(document, "rb"))}
+ if re.match('https?://.*\.(pdf|zip|gif)$', document.lower()):
+ MSG = { 'chat_id': raw_in['message']['chat'].get('id', ''),
+ 'document': document }
+ FLS = {}
+ else:
+ MSG = { 'chat_id': raw_in['message']['chat'].get('id', '') }
+ FLS = {'document': (document, open(document, "rb"))}
MSG.update(custom)
return send_raw(raw_in, 'sendDocument', MSG, FLS)
diff --git a/plugins/oboobs.py b/plugins/oboobs.py index 80a9fd5..7cc5ea3 100644 --- a/plugins/oboobs.py +++ b/plugins/oboobs.py @@ -24,18 +24,20 @@ def cmd_oboobs(raw_in):
try:
data = json.loads(load_page('http://api.oboobs.ru/noise/1/'))[0]
- msg = '<a href="http://media.oboobs.ru/%s">#%s</a> Another one - /oboobs' % (data['preview'], data['id'])
+ photo_url = "http://media.oboobs.ru/%s" % data['preview']
+ send_photo(raw_in, photo_url, {'caption': 'Another one - /oboobs'})
except:
msg = 'Error!'
- send_msg(raw_in, msg)
+ send_msg(raw_in, msg)
def cmd_obutts(raw_in):
try:
data = json.loads(load_page('http://api.obutts.ru/noise/1/'))[0]
- msg = '<a href="http://media.obutts.ru/%s">#%s</a> Another one - /obutts' % (data['preview'], data['id'])
+ photo_url = "http://media.obutts.ru/%s" % data['preview']
+ send_photo(raw_in, photo_url, {'caption': 'Another one - /obutts'})
except:
msg = 'Error!'
- send_msg(raw_in, msg)
+ send_msg(raw_in, msg)
commands = [['oboobs', cmd_oboobs, False, 'raw', 'Show random picture from oboobs.ru'],
['obutts', cmd_obutts, False, 'raw', 'Show random picture from obutts.ru']]
|