attempt at error reporting numero deux
This commit is contained in:
parent
9dd00e7d03
commit
9ce44d1e52
1 changed files with 29 additions and 32 deletions
61
robot.py
61
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...')
|
||||||
download_ydl(ytdl_urls)
|
try:
|
||||||
|
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
|
||||||
photo = max(update.message.photo, key=lambda p: p.width)
|
def handle_rest(bot, update):
|
||||||
url = bot.getFile(photo.file_id).file_path
|
file = None
|
||||||
update.message.reply_text('Downloading now...')
|
if update.message.photo is not None:
|
||||||
logger.info("Downloading '%s'" % url)
|
photo = max(update.message.photo, key=lambda p: p.width)
|
||||||
download_raw(url)
|
file = photo.file_id
|
||||||
|
elif update.message.document is not None:
|
||||||
|
file = update.message.document.file_id
|
||||||
def handle_audio(bot, update):
|
elif update.message.audio is not None:
|
||||||
url = bot.getFile(update.message.audio.file_id).file_path
|
file = update.message.audio.file_id
|
||||||
update.message.reply_text('Downloading now...')
|
elif update.message.video is not None:
|
||||||
logger.info("Downloading '%s'" % url)
|
file = update.message.video.file_id
|
||||||
download_raw(url)
|
if file is not None:
|
||||||
|
url = bot.getFile(file).file_path
|
||||||
|
update.message.reply_text('Downloading now...')
|
||||||
def handle_video(bot, update):
|
logger.info("Downloading '%s'" % url)
|
||||||
url = bot.getFile(update.message.video.file_id).file_path
|
try:
|
||||||
update.message.reply_text('Downloading now...')
|
download_raw(url)
|
||||||
logger.info("Downloading '%s'" % url)
|
except:
|
||||||
download_raw(url)
|
type, value, _ = sys.exc_info()
|
||||||
|
update.message.reply_text("Something is FUCKED: %s, %s" % (type, value))
|
||||||
|
|
||||||
def handle_document(bot, update):
|
|
||||||
url = bot.getFile(update.message.document.file_id).file_path
|
|
||||||
update.message.reply_text('Downloading now...')
|
|
||||||
logger.info("Downloading '%s'" % url)
|
|
||||||
download_raw(url)
|
|
||||||
|
|
||||||
|
|
||||||
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