cosmetics

feature-unify_handlers
Tomáš Mládek 2019-04-18 12:54:10 +02:00 committed by Tomáš Mládek
parent c249de6e64
commit da66cbac82
1 changed files with 14 additions and 15 deletions

View File

@ -131,14 +131,14 @@ class DelojzaBot:
hashtag = "PRAS"
return hashtag
def handle_hashtag(self, bot, update):
def handle_hashtag(self, _, update):
hashtags = list(map(update.message.parse_entity,
list(filter(lambda e: e.type == 'hashtag', update.message.entities))))
if len(hashtags) > 0:
self.last_hashtag = (update.message.from_user, hashtags[0])
# noinspection PyBroadException
def handle(self, urls, message, download, tumblr=False, filename=None):
def handle(self, urls, message, download_fn, filename=None):
try:
hashtag = self.get_first_hashtag(message)
if hashtag is None:
@ -154,13 +154,14 @@ class DelojzaBot:
reply += '...'
extract = False
if hashtag in ('AUDIO', 'RADIO') and download != self.download_raw:
if hashtag in ('AUDIO', 'RADIO') and download_fn != self.download_raw:
extract = True
reply += ' (And also guessing you want to extract the audio)'
message.reply_text(reply)
filenames = download(urls,
hashtag or '.', message.date,
extract=extract, filename=filename)
filenames = download_fn(urls, hashtag or '.', message.date,
extract=extract, filename=filename)
if hashtag == 'TUMBLR':
message.reply_text('(btw, queueing to tumblr)')
for filename in filenames:
@ -171,11 +172,10 @@ class DelojzaBot:
if "Timed out" not in str(exc_value):
message.reply_text("Something is FUCKED: %s" % exc_value)
def handle_url(self, bot, update):
ytdl_urls = list(filter(self.ytdl_can,
map(lambda e: update.message.parse_entity(e),
filter(lambda e: e.type == 'url',
update.message.entities))))
def handle_url(self, _, update):
urls = map(lambda e: update.message.parse_entity(e),
filter(lambda e: e.type == 'url', update.message.entities))
ytdl_urls = list(filter(self.ytdl_can, urls))
if len(ytdl_urls) > 0:
self.handle(ytdl_urls, update.message, self.download_ytdl)
@ -185,7 +185,6 @@ class DelojzaBot:
if len(update.message.photo) > 0:
photo = max(update.message.photo, key=lambda p: p.width)
file = photo.file_id
tumblr = True
elif update.message.document is not None:
filename = update.message.document.file_name
file = update.message.document.file_id
@ -201,12 +200,12 @@ class DelojzaBot:
if file is not None:
url = bot.getFile(file).file_path
self.handle([url], update.message, self.download_raw, tumblr=tumblr, filename=filename)
self.handle([url], update.message, self.download_raw, filename=filename)
def handle_text(self, bot, update):
def handle_text(self, _, update):
self.markov.add_to_corpus(update.message.text)
def tg_start(self, bot, update):
def tg_start(self, _, update):
update.message.reply_text(self.markov.make_sentence())
def tg_error(self, bot, update, error):