Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. import vk, os, json, time
  2. from threading import Thread
  3. from requests import post
  4.  
  5. TOKEN = ''
  6. API = '5.80'
  7. BOT_ID = 186656440
  8. time = time.time()
  9. session = vk.Session(access_token = TOKEN)
  10. vk = vk.API(session, v = API)
  11.  
  12. # первый запрос к лонгпулу: получение server, key и ts
  13. long_poll = vk.groups.getLongPollServer(group_id = BOT_ID)
  14. server, key, ts = long_poll['server'], long_poll['key'], long_poll['ts']
  15. def addslashes(s):
  16. return repr('"' + s)[2:-1].replace('"', '\\"')
  17. while True:
  18. try:
  19. long_poll = post('%s'%server, data = {'act': 'a_check', 'key': key, 'ts': ts, 'wait': 90}).json() # запрос к лонгпулу
  20. except Exception:
  21. quit();
  22. updates = long_poll['updates']
  23. if updates is None:
  24. long_poll = vk.groups.getLongPollServer(group_id = BOT_ID)
  25. server, key, ts = long_poll['server'], long_poll['key'], long_poll['ts']
  26. if server == null:
  27. quit()
  28. continue
  29. if long_poll['updates'] and len(long_poll['updates']) != 0:
  30. for up in long_poll['updates']:
  31.  
  32. if ((up['type'] == 'message_new' or up['type'] == 'message_reply') and up['object']['from_id'] > 0) or up['type'] == 'group_join':
  33. print(os.system('php main.php "'+addslashes(json.dumps(up['object']))+'" &'))
  34. ts = long_poll['ts']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement