cleanup webhook garbage
@@ -25,23 +25,15 @@ class Events(commands.Cog):
self.logger = logging.getLogger("Events")
self.logger.setLevel(logging.INFO)
- self.web_app = web.Application(loop=self.bot.loop)
- self.web_app.router.add_post("/dbl2", self.on_dbl2_vote)
- self.web_runner = web.AppRunner(self.web_app)
-
- self.bot.loop.create_task(self.setup_dbl2_webhook())
-
- async def setup_dbl2_webhook(self):
- await self.web_runner.setup()
-
- site = web.TCPSite(self.web_runner, "0.0.0.0", 8000)
- await site.start()
+ self.bot.loop.create_task(self.webhook())
def cog_unload(self):
self.bot.loop.create_task(self.dblpy.close())
self.bot.loop.create_task(self.web_runner.cleanup())
- async def on_dbl2_vote(self, r):
+ async def webhook(self):
+
+ async def vote_handler(r):
print(r.body)
print(r)
user_id = int(json.loads(r.text))
@@ -57,6 +49,15 @@ class Events(commands.Cog):
await user.send(choice(messages).format(8))
return web.Response()
+ web_app = web.Application(loop=bot.loop)
+ web_app.router.add_post("/dbl2", vote_handler)
+
+ web_runner = web.AppRunner(web_app)
+ await web_runner.setup()
+
+ site = web.TCPSite(self.web_runner, "0.0.0.0", 8000)
+ await site.start()
+
@commands.Cog.listener()
async def on_ready(self):
await self.bot.change_presence(activity=discord.Game(name=choice(self.g.playingList)))
