How to make a function that takes data and releases in bot chat

0

Good afternoon I have a bot for a site where I go and wanted to develop a function where it sends a private message in the system. In my head it seems simple but I can not execute (I know the code is wrong but that's how I imagined it).

I'm a beginner in the programming area and wanted help on how to solve this.

It's quite simple, the user would call /sms to the bot and soon he would capture everything he had in front of /sms . Then he would pick it up and play it on the chat.

It would be a function of speaking anonymously, can someone help me?

I know it's a silly question but I have this question.

Thank you in advance.

  

(Edit) I have managed to solve the problem but when I send the message it reproduces the code too!

#private mensagem
def mensagemprivate(self, message, name_sender, to=''):
        if re.findall('/sms .*', message):
            self.post(message=message)

elif '/sms' in message:
        t_mensagemprivate = threading.Thread(target=self.mensagemprivate, args=(message, name_sender, id_sender))
        t_mensagemprivate.start()
    
asked by anonymous 22.04.2018 / 18:58

1 answer

0

You have two ways to remove /sms text from your message.

One of them is using the .replace function, which replaces one text with another. In your case, you can substring by an empty string:

...
elif '/sms' in message:
    message = message.replace('/sms ', '')  # Substituindo o texto por vazio
...

Or you can break your string into the position of the text you want to remove:

...
elif '/sms' in message:
    message = message[5:]  # Isto "corta" a string e retorna a partir do quinto caractere até seu fim
...
    
29.04.2018 / 02:28