Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. def listener(messages):
  2.     for m in messages:
  3.         cid = m.chat.id
  4.         mensaje = ""
  5.         if m.content_type == 'text':
  6.             if cid > 0:
  7.                 mensaje = '' + str(m.chat.first_name) + "[" + str(cid) + "]: " + m.text
  8.             else:
  9.                 mensaje = '' + str(m.from_user.first_name) + "[" + str(cid) + "]: " + m.text
  10.         with open('/path/to/chats.json', 'r') as f:
  11.             chats = json.load(f)
  12.         if not m.chat.id in chats['chats']:
  13.             chats['chats'].append(m.chat.id)
  14.             with open('/path/to/chats.json', 'w') as f:
  15.                 json.dump(chats, f)
  16.  
  17. bot.set_update_listener(listener)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement