K
K
kuzubina2018-05-30 15:22:13
Python
kuzubina, 2018-05-30 15:22:13

Change phyton script condition execution logic?

Hello! I ask for help because I'm not very familiar with python.
There is a working telegram bot that automatically forwards messages (from one group to another) if the message starts with a
hashtag

elif "#" == txt[0]:
                txt_split =txt.strip().split(" ")
                i = 0
                tags = []
                while i < len(txt_split) and txt_split[i][0] == "#":
                    tags.append(txt_split[i].lower())
                    i+=1
                if i != len(txt_split) or 'reply_to_message' in msg:
                    approved = []
                    rejected = []
                    for tag in tags:
                        if tag in chats:
                            if chats[tag]['id'] != chat_id:
                                approved.append(chats[tag]['name'])
                                bot.forwardMessage(chats[tag]['id'], chat_id, msg['message_id'])
                                if 'reply_to_message' in msg:
                                    bot.forwardMessage(chats[tag]['id'], chat_id, msg['reply_to_message']['message_id'])
                        else:
                            rejected.append(tag)
                    if len(rejected) > 0:
                        bot.sendMessage(chat_id, "Failed to send messages to tags <i>" + ", ".join(rejected) + "</i>", parse_mode="HTML")
                else:
                    bot.sendMessage(chat_id, "Failed to send a message only with tags which is not a reply to another message")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aderes, 2018-05-30
@de-iure

without reading it ... probably like this:

elif "#" in txt:
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question