Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import vk, os, json, time
- from threading import Thread
- from requests import post
- TOKEN = ''
- API = '5.80'
- BOT_ID = 186656440
- time = time.time()
- session = vk.Session(access_token = TOKEN)
- vk = vk.API(session, v = API)
- # первый запрос к лонгпулу: получение server, key и ts
- long_poll = vk.groups.getLongPollServer(group_id = BOT_ID)
- server, key, ts = long_poll['server'], long_poll['key'], long_poll['ts']
- def addslashes(s):
- return repr('"' + s)[2:-1].replace('"', '\\"')
- while True:
- try:
- long_poll = post('%s'%server, data = {'act': 'a_check', 'key': key, 'ts': ts, 'wait': 90}).json() # запрос к лонгпулу
- except Exception:
- quit();
- updates = long_poll['updates']
- if updates is None:
- long_poll = vk.groups.getLongPollServer(group_id = BOT_ID)
- server, key, ts = long_poll['server'], long_poll['key'], long_poll['ts']
- if server == null:
- quit()
- continue
- if long_poll['updates'] and len(long_poll['updates']) != 0:
- for up in long_poll['updates']:
- if ((up['type'] == 'message_new' or up['type'] == 'message_reply') and up['object']['from_id'] > 0) or up['type'] == 'group_join':
- print(os.system('php main.php "'+addslashes(json.dumps(up['object']))+'" &'))
- ts = long_poll['ts']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement