vysheng / tg

telegram-cli
GNU General Public License v2.0
6.49k stars 1.54k forks source link

Pyhton script with loop #778

Open michelePap opened 9 years ago

michelePap commented 9 years ago

In my python script i have this situation:

def on_msg_receive(msg):
    if msg.out and not binlog_done:
      return;

    if msg.dest.id == our_id: # direct message
      peer = msg.src
    else: # chatroom
      peer = msg.dest

    if msg.text.startswith("ping"):
      peer.send_msg("PONG!")

while True:
    #do something
    #sendMessage

With the loop i can't check the incoming message. How can i fix this?

sgitkene commented 9 years ago

You have to access msg within on_msg_receive, otherwise it is out of scope. Also the loop has to terminate, otherwise you don't get new messages.