2019-12-29 21:38:59 +01:00
|
|
|
import asyncio
|
2019-12-30 00:48:11 +01:00
|
|
|
import logging
|
2019-12-29 21:38:59 +01:00
|
|
|
import threading
|
2019-12-29 23:18:10 +01:00
|
|
|
|
2019-12-29 21:38:59 +01:00
|
|
|
from aiohttp import web
|
2019-12-29 23:18:10 +01:00
|
|
|
from aiohttp.web_request import Request
|
2019-12-29 21:38:59 +01:00
|
|
|
|
|
|
|
from discord.ext import commands
|
|
|
|
from bot import TuxBot
|
|
|
|
|
2019-12-30 00:48:11 +01:00
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2019-12-29 21:38:59 +01:00
|
|
|
|
|
|
|
class Monitoring(commands.Cog):
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
self.app = web.Application()
|
|
|
|
|
|
|
|
t = threading.Thread(
|
|
|
|
target=self.run_server,
|
|
|
|
args=(self.aiohttp_server(),)
|
|
|
|
)
|
|
|
|
t.start()
|
|
|
|
|
|
|
|
def aiohttp_server(self):
|
2019-12-29 23:18:10 +01:00
|
|
|
async def hi(request: Request):
|
2019-12-29 21:38:59 +01:00
|
|
|
return web.Response(text="I'm alive !")
|
|
|
|
|
|
|
|
self.app.add_routes([web.get('/', hi)])
|
|
|
|
runner = web.AppRunner(self.app)
|
|
|
|
|
|
|
|
return runner
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def run_server(runner):
|
|
|
|
loop = asyncio.new_event_loop()
|
|
|
|
asyncio.set_event_loop(loop)
|
|
|
|
loop.run_until_complete(runner.setup())
|
2019-12-29 23:18:10 +01:00
|
|
|
site = web.TCPSite(runner, '0.0.0.0', 8080)
|
2019-12-29 21:38:59 +01:00
|
|
|
loop.run_until_complete(site.start())
|
|
|
|
loop.run_forever()
|
|
|
|
|
|
|
|
|
|
|
|
def setup(bot: TuxBot):
|
|
|
|
bot.add_cog(Monitoring())
|