hashtags before message too!

This commit is contained in:
Tomáš Mládek 2018-04-25 14:30:08 +02:00 committed by Tomáš Mládek
parent bf1f60eca5
commit b9214a0eb4

View file

@ -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()