Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. import time, json, vkbee, asyncio, requests
  2.  
  3. async def main(loop):
  4. vk = vkbee.VkApi('d43b3b5b8ec72b4c4886326329e3e1c1dc6c68b8da41d54182dcb7731ccacf58718ced94cb481964bedb5',
  5. loop=loop,
  6. )
  7. vk_polluse = vkbee.BotLongpoll(vk, '171679995', 10)
  8. async for event in vk_polluse.events():
  9. if event['type'] == 'message_new':
  10. start = time.time()
  11. peer_id = event['object']['message']['peer_id']
  12. text = event['object']['message']['text'].lower()
  13. user_id = event['object']['message']['from_id']
  14. if text == '1':
  15. await vkbee.VkApi.call(vk, 'messages.send', {'random_id': 0, 'peer_id': peer_id, 'message': 'ВТОПЕ{0}'.format(user_id) })
  16. stop = time.time()
  17. speed = stop - start
  18. keyboard = json.dumps(
  19. {
  20. 'one_time': False,
  21. 'buttons': [
  22. [
  23. {
  24. 'action': {
  25. 'type': 'open_link',
  26. 'link': 'https://asyncvk.github.io',
  27. 'label': 'Открыть документацию VKBee',
  28. }
  29. }
  30. ],
  31. [
  32. {
  33. 'action': {
  34. 'type': 'text',
  35. 'label': 'Скорость обработки события:',
  36. },
  37. 'color': 'positive',
  38. }
  39. ],
  40. [
  41. {
  42. 'action': {'type': 'text', 'label': speed},
  43. 'color': 'negative',
  44. }
  45. ],
  46. ],
  47. 'inline': True
  48. }
  49. )
  50.  
  51.  
  52. loop = asyncio.get_event_loop()
  53. loop.run_until_complete(main(loop))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement