attempt at error reporting numero deux
This commit is contained in:
parent
9dd00e7d03
commit
9ce44d1e52
1 changed files with 29 additions and 32 deletions
51
robot.py
51
robot.py
|
@ -1,5 +1,6 @@
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
@ -51,6 +52,7 @@ def download_raw(url):
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyBroadException
|
||||||
def handle_url(bot, update):
|
def handle_url(bot, update):
|
||||||
ytdl_urls = list(filter(ytdl_has,
|
ytdl_urls = list(filter(ytdl_has,
|
||||||
map(lambda e: update.message.text[e.offset:e.offset + e.length],
|
map(lambda e: update.message.text[e.offset:e.offset + e.length],
|
||||||
|
@ -59,36 +61,34 @@ def handle_url(bot, update):
|
||||||
if len(ytdl_urls) > 0:
|
if len(ytdl_urls) > 0:
|
||||||
logger.info("Downloading %s" % ytdl_urls)
|
logger.info("Downloading %s" % ytdl_urls)
|
||||||
update.message.reply_text('Downloading now...')
|
update.message.reply_text('Downloading now...')
|
||||||
|
try:
|
||||||
download_ydl(ytdl_urls)
|
download_ydl(ytdl_urls)
|
||||||
|
except:
|
||||||
|
type, value, _ = sys.exc_info()
|
||||||
|
update.message.reply_text("Something is FUCKED: %s, %s" % (type, value))
|
||||||
|
|
||||||
|
|
||||||
def handle_photo(bot, update):
|
# noinspection PyBroadException
|
||||||
|
def handle_rest(bot, update):
|
||||||
|
file = None
|
||||||
|
if update.message.photo is not None:
|
||||||
photo = max(update.message.photo, key=lambda p: p.width)
|
photo = max(update.message.photo, key=lambda p: p.width)
|
||||||
url = bot.getFile(photo.file_id).file_path
|
file = photo.file_id
|
||||||
update.message.reply_text('Downloading now...')
|
elif update.message.document is not None:
|
||||||
logger.info("Downloading '%s'" % url)
|
file = update.message.document.file_id
|
||||||
download_raw(url)
|
elif update.message.audio is not None:
|
||||||
|
file = update.message.audio.file_id
|
||||||
|
elif update.message.video is not None:
|
||||||
def handle_audio(bot, update):
|
file = update.message.video.file_id
|
||||||
url = bot.getFile(update.message.audio.file_id).file_path
|
if file is not None:
|
||||||
update.message.reply_text('Downloading now...')
|
url = bot.getFile(file).file_path
|
||||||
logger.info("Downloading '%s'" % url)
|
|
||||||
download_raw(url)
|
|
||||||
|
|
||||||
|
|
||||||
def handle_video(bot, update):
|
|
||||||
url = bot.getFile(update.message.video.file_id).file_path
|
|
||||||
update.message.reply_text('Downloading now...')
|
|
||||||
logger.info("Downloading '%s'" % url)
|
|
||||||
download_raw(url)
|
|
||||||
|
|
||||||
|
|
||||||
def handle_document(bot, update):
|
|
||||||
url = bot.getFile(update.message.document.file_id).file_path
|
|
||||||
update.message.reply_text('Downloading now...')
|
update.message.reply_text('Downloading now...')
|
||||||
logger.info("Downloading '%s'" % url)
|
logger.info("Downloading '%s'" % url)
|
||||||
|
try:
|
||||||
download_raw(url)
|
download_raw(url)
|
||||||
|
except:
|
||||||
|
type, value, _ = sys.exc_info()
|
||||||
|
update.message.reply_text("Something is FUCKED: %s, %s" % (type, value))
|
||||||
|
|
||||||
|
|
||||||
def start(bot, update):
|
def start(bot, update):
|
||||||
|
@ -111,10 +111,7 @@ def main():
|
||||||
dp.add_error_handler(error)
|
dp.add_error_handler(error)
|
||||||
|
|
||||||
dp.add_handler(MessageHandler(Filters.entity(MessageEntity.URL), handle_url))
|
dp.add_handler(MessageHandler(Filters.entity(MessageEntity.URL), handle_url))
|
||||||
dp.add_handler(MessageHandler(Filters.photo, handle_photo))
|
dp.add_handler(MessageHandler(Filters.photo | Filters.video | Filters.audio | Filters.document, handle_rest))
|
||||||
dp.add_handler(MessageHandler(Filters.audio, handle_audio))
|
|
||||||
dp.add_handler(MessageHandler(Filters.video, handle_video))
|
|
||||||
dp.add_handler(MessageHandler(Filters.document, handle_document))
|
|
||||||
|
|
||||||
updater.start_polling()
|
updater.start_polling()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue