Guest User

Untitled

a guest
Apr 26th, 2020
60
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from django.core.management.base import BaseCommand, CommandError
  2.  
  3. from vkbottle import Bot, Message
  4. from aiohttp import web
  5.  
  6. from ScheduleService.settings import VKBOT_TOKEN, VKBOT_GROUP_ID, VKBOT_SECRET_KEY, VKBOT_CONFIRMATION_TOKEN
  7.  
  8.  
  9. bot = Bot(tokens=VKBOT_TOKEN, group_id=VKBOT_GROUP_ID, secret=VKBOT_SECRET_KEY)
  10. app = web.Application()
  11.  
  12.  
  13. @bot.on.message()
  14. async def echo(ans: Message):
  15.     await ans(ans.text)
  16.  
  17.  
  18. async def executor(request: web.Request):
  19.     event = await request.json()
  20.     emulation = await bot.emulate(event=event, confirmation_token=VKBOT_CONFIRMATION_TOKEN)
  21.     return web.Response(text=emulation)
  22.  
  23.  
  24. class Command(BaseCommand):
  25.     help = 'Запуск бота ВКонтакте (vkbottle)'
  26.  
  27.     def handle(self, *args, **options):
  28.         app.router.add_route(path='/webhook', method='POST', handler=executor)
  29.  
  30.         web.run_app(app=app)
  31.  
  32.         self.stdout.write(self.style.SUCCESS('Веб сервер запущен!'))
RAW Paste Data