cosmetics
This commit is contained in:
parent
c249de6e64
commit
da66cbac82
1 changed files with 14 additions and 15 deletions
27
delojza.py
27
delojza.py
|
@ -131,14 +131,14 @@ class DelojzaBot:
|
||||||
hashtag = "PRAS"
|
hashtag = "PRAS"
|
||||||
return hashtag
|
return hashtag
|
||||||
|
|
||||||
def handle_hashtag(self, bot, update):
|
def handle_hashtag(self, _, update):
|
||||||
hashtags = list(map(update.message.parse_entity,
|
hashtags = list(map(update.message.parse_entity,
|
||||||
list(filter(lambda e: e.type == 'hashtag', update.message.entities))))
|
list(filter(lambda e: e.type == 'hashtag', update.message.entities))))
|
||||||
if len(hashtags) > 0:
|
if len(hashtags) > 0:
|
||||||
self.last_hashtag = (update.message.from_user, hashtags[0])
|
self.last_hashtag = (update.message.from_user, hashtags[0])
|
||||||
|
|
||||||
# noinspection PyBroadException
|
# noinspection PyBroadException
|
||||||
def handle(self, urls, message, download, tumblr=False, filename=None):
|
def handle(self, urls, message, download_fn, filename=None):
|
||||||
try:
|
try:
|
||||||
hashtag = self.get_first_hashtag(message)
|
hashtag = self.get_first_hashtag(message)
|
||||||
if hashtag is None:
|
if hashtag is None:
|
||||||
|
@ -154,12 +154,13 @@ class DelojzaBot:
|
||||||
reply += '...'
|
reply += '...'
|
||||||
|
|
||||||
extract = False
|
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
|
extract = True
|
||||||
reply += ' (And also guessing you want to extract the audio)'
|
reply += ' (And also guessing you want to extract the audio)'
|
||||||
|
|
||||||
message.reply_text(reply)
|
message.reply_text(reply)
|
||||||
filenames = download(urls,
|
|
||||||
hashtag or '.', message.date,
|
filenames = download_fn(urls, hashtag or '.', message.date,
|
||||||
extract=extract, filename=filename)
|
extract=extract, filename=filename)
|
||||||
if hashtag == 'TUMBLR':
|
if hashtag == 'TUMBLR':
|
||||||
message.reply_text('(btw, queueing to tumblr)')
|
message.reply_text('(btw, queueing to tumblr)')
|
||||||
|
@ -171,11 +172,10 @@ class DelojzaBot:
|
||||||
if "Timed out" not in str(exc_value):
|
if "Timed out" not in str(exc_value):
|
||||||
message.reply_text("Something is FUCKED: %s" % exc_value)
|
message.reply_text("Something is FUCKED: %s" % exc_value)
|
||||||
|
|
||||||
def handle_url(self, bot, update):
|
def handle_url(self, _, update):
|
||||||
ytdl_urls = list(filter(self.ytdl_can,
|
urls = map(lambda e: update.message.parse_entity(e),
|
||||||
map(lambda e: update.message.parse_entity(e),
|
filter(lambda e: e.type == 'url', update.message.entities))
|
||||||
filter(lambda e: e.type == 'url',
|
ytdl_urls = list(filter(self.ytdl_can, urls))
|
||||||
update.message.entities))))
|
|
||||||
if len(ytdl_urls) > 0:
|
if len(ytdl_urls) > 0:
|
||||||
self.handle(ytdl_urls, update.message, self.download_ytdl)
|
self.handle(ytdl_urls, update.message, self.download_ytdl)
|
||||||
|
|
||||||
|
@ -185,7 +185,6 @@ class DelojzaBot:
|
||||||
if len(update.message.photo) > 0:
|
if len(update.message.photo) > 0:
|
||||||
photo = max(update.message.photo, key=lambda p: p.width)
|
photo = max(update.message.photo, key=lambda p: p.width)
|
||||||
file = photo.file_id
|
file = photo.file_id
|
||||||
tumblr = True
|
|
||||||
elif update.message.document is not None:
|
elif update.message.document is not None:
|
||||||
filename = update.message.document.file_name
|
filename = update.message.document.file_name
|
||||||
file = update.message.document.file_id
|
file = update.message.document.file_id
|
||||||
|
@ -201,12 +200,12 @@ class DelojzaBot:
|
||||||
|
|
||||||
if file is not None:
|
if file is not None:
|
||||||
url = bot.getFile(file).file_path
|
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)
|
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())
|
update.message.reply_text(self.markov.make_sentence())
|
||||||
|
|
||||||
def tg_error(self, bot, update, error):
|
def tg_error(self, bot, update, error):
|
||||||
|
|
Loading…
Reference in a new issue