Begin implementing aiohttp
This commit is contained in:
45
monolith.py
45
monolith.py
@@ -1,36 +1,13 @@
|
||||
import asyncio
|
||||
import signal
|
||||
import sys
|
||||
from os import getenv
|
||||
|
||||
from twisted.internet import asyncioreactor
|
||||
|
||||
import util
|
||||
from sources.ch4 import Chan4
|
||||
from sources.dis import DiscordClient
|
||||
|
||||
loop = asyncio.new_event_loop()
|
||||
# asyncio.set_event_loop(loop)
|
||||
|
||||
|
||||
# asyncioreactor.install(asyncio.new_event_loop())
|
||||
asyncioreactor.install(loop) # noqa
|
||||
from twisted.internet import reactor, task # noqa
|
||||
|
||||
|
||||
# Doesn't quite work but better than nothing
|
||||
def stop(*args):
|
||||
loop.stop()
|
||||
reactor.stop()
|
||||
sys.exit()
|
||||
|
||||
|
||||
signal.signal(signal.SIGINT, stop)
|
||||
# loop.add_signal_handler(signal.SIGINT, functools.partial(stop, loop))
|
||||
# For development
|
||||
if not getenv("DISCORD_TOKEN", None):
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
log = util.get_logger("monolith")
|
||||
@@ -42,23 +19,25 @@ if not token:
|
||||
raise Exception("No Discord token provided")
|
||||
|
||||
|
||||
async def start():
|
||||
async def main(loop):
|
||||
log.info("Starting Discord handler.")
|
||||
client = DiscordClient(loop=loop)
|
||||
client = DiscordClient()
|
||||
loop.create_task(client.start(token))
|
||||
#client.run(token)
|
||||
|
||||
log.info("Starting 4chan handler.")
|
||||
chan = Chan4()
|
||||
running = chan.run()
|
||||
deferred = task.ensureDeferred(running)
|
||||
reactor.callLater(0.1, deferred.callback, "")
|
||||
# log.info("Starting 4chan handler.")
|
||||
# chan = Chan4()
|
||||
# #running = chan.run()
|
||||
# chan.run()
|
||||
#deferred.addCallback(lambda: None)
|
||||
#reactor.callLater(0.1, deferred.callback, None)
|
||||
|
||||
|
||||
loop.create_task(start())
|
||||
|
||||
|
||||
# reactor.run()
|
||||
reactor.run()
|
||||
loop = asyncio.get_event_loop()
|
||||
loop.create_task(main(loop))
|
||||
#reactor.run()
|
||||
try:
|
||||
loop.run_forever()
|
||||
except KeyboardInterrupt:
|
||||
|
||||
Reference in New Issue
Block a user