From b9214a0eb4bb4284645ed065f12f1d247529d534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Wed, 25 Apr 2018 14:30:08 +0200 Subject: [PATCH] hashtags before message too! --- delojza.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/delojza.py b/delojza.py index e575dc9..9ae59d3 100755 --- a/delojza.py +++ b/delojza.py @@ -86,19 +86,37 @@ def download_raw(urls, subdir, date, extract=False, filename=None): shutil.move(local_filename, local_filename + '.' + kind.extension) +last_hashtag = None + + def get_first_hashtag(message): + global last_hashtag hashtags = list(map(message.parse_entity, list(filter(lambda e: e.type == 'hashtag', message.entities)))) hashtags += list(map(message.parse_caption_entity, list(filter(lambda e: e.type == 'hashtag', message.caption_entities)))) if len(hashtags) == 0: - return None - hashtag = hashtags[0][1:].upper() + if last_hashtag is not None and last_hashtag[0] == message.from_user: + prehashtag = last_hashtag[1] + last_hashtag = None + else: + return None + else: + prehashtag = hashtags[0] + hashtag = prehashtag[1:].upper() if "PRAS" in hashtag: hashtag = "PRAS" return hashtag +def handle_hashtag(bot, update): + global last_hashtag + hashtags = list(map(update.message.parse_entity, + list(filter(lambda e: e.type == 'hashtag', update.message.entities)))) + if len(hashtags) > 0: + last_hashtag = (update.message.from_user, hashtags[0]) + + # noinspection PyBroadException def handle(urls, message, download, filename=None): tries = 0 @@ -188,6 +206,7 @@ def main(): dp.add_handler(MessageHandler(Filters.entity(MessageEntity.URL), handle_url)) dp.add_handler( MessageHandler(Filters.photo | Filters.video | Filters.audio | Filters.voice | Filters.document, handle_rest)) + dp.add_handler(MessageHandler(Filters.entity(MessageEntity.HASHTAG), handle_hashtag)) updater.start_polling()