rename tg methods

This commit is contained in:
Tomáš Mládek 2019-04-18 16:34:56 +02:00 committed by Tomáš Mládek
parent cb63f80fe2
commit 2d85eae50a

View file

@ -48,13 +48,13 @@ class DelojzaBot:
dp.add_handler(CommandHandler("start", self.tg_start)) dp.add_handler(CommandHandler("start", self.tg_start))
dp.add_error_handler(self.tg_error) dp.add_error_handler(self.tg_error)
dp.add_handler(MessageHandler(Filters.entity(MessageEntity.URL), self.handle_url)) dp.add_handler(MessageHandler(Filters.entity(MessageEntity.URL), self.tg_handle_url))
dp.add_handler( dp.add_handler(
MessageHandler( MessageHandler(
Filters.photo | Filters.video | Filters.video_note | Filters.audio | Filters.voice | Filters.document, Filters.photo | Filters.video | Filters.video_note | Filters.audio | Filters.voice | Filters.document,
self.handle_rest)) self.tg_handle_rest))
dp.add_handler(MessageHandler(Filters.entity(MessageEntity.HASHTAG), self.handle_hashtag)) dp.add_handler(MessageHandler(Filters.entity(MessageEntity.HASHTAG), self.tg_handle_hashtag))
dp.add_handler(MessageHandler(Filters.text, self.handle_text)) dp.add_handler(MessageHandler(Filters.text, self.tg_handle_text))
if tumblr_keys: if tumblr_keys:
self.client = pytumblr.TumblrRestClient(*tumblr_keys) self.client = pytumblr.TumblrRestClient(*tumblr_keys)
@ -131,7 +131,7 @@ class DelojzaBot:
hashtag = "PRAS" hashtag = "PRAS"
return hashtag return hashtag
def handle_hashtag(self, _, update): def tg_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:
@ -171,7 +171,7 @@ 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, _, update): def tg_handle_url(self, _, update):
urls = list(map(lambda e: update.message.parse_entity(e), urls = list(map(lambda e: update.message.parse_entity(e),
filter(lambda e: e.type == 'url', update.message.entities))) filter(lambda e: e.type == 'url', update.message.entities)))
ytdl_urls = [url for url in urls if self.ytdl_can(url)] ytdl_urls = [url for url in urls if self.ytdl_can(url)]
@ -184,7 +184,7 @@ class DelojzaBot:
self.handle(image_urls, update.message, self.download_raw) self.handle(image_urls, update.message, self.download_raw)
# noinspection PyBroadException # noinspection PyBroadException
def handle_rest(self, bot, update): def tg_handle_rest(self, bot, update):
file, filename, tumblr = None, None, False file, filename, tumblr = None, None, False
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)
@ -206,7 +206,7 @@ class DelojzaBot:
url = bot.getFile(file).file_path url = bot.getFile(file).file_path
self.handle([url], update.message, self.download_raw, filename=filename) self.handle([url], update.message, self.download_raw, filename=filename)
def handle_text(self, _, update): def tg_handle_text(self, _, update):
if self.markov: if self.markov:
self.markov.add_to_corpus(update.message.text) self.markov.add_to_corpus(update.message.text)
@ -219,7 +219,7 @@ class DelojzaBot:
if update is not None: if update is not None:
default = "Mmmm, I like it..." default = "Mmmm, I like it..."
update.message.reply_text((self.markov.make_sentence(tries=100) if self.markov else default) or default) update.message.reply_text((self.markov.make_sentence(tries=100) if self.markov else default) or default)
self.handle_rest(bot, update) self.tg_handle_rest(bot, update)
else: else:
if update is not None: if update is not None:
update.message.reply_text("Something is fucked: %s" % error) update.message.reply_text("Something is fucked: %s" % error)