2
0

main.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import asyncio
  2. import os.path
  3. from concurrent.futures import ThreadPoolExecutor
  4. from arty.thread_queue import ThreadQueue
  5. from arty.worker import Worker
  6. from arty.make_image import make_image
  7. from arty.utils import get_token, run_in_thread
  8. from arty.bot import Bot
  9. def _init():
  10. lock = os.path.join(os.path.dirname(__file__), '.first_init')
  11. if os.path.isfile(lock):
  12. return
  13. print('running first time setup. this will take some time.')
  14. make_image('something cute', num_images=1)
  15. with open(lock, 'w') as f:
  16. f.write('done')
  17. print('first time setup done.')
  18. async def _main():
  19. worker_queue = ThreadQueue()
  20. bot_queue = ThreadQueue()
  21. worker = Worker(bot_queue, worker_queue)
  22. bot = Bot(get_token('discord'), bot_queue, worker_queue)
  23. executor = ThreadPoolExecutor(max_workers=2)
  24. loop = asyncio.get_event_loop()
  25. await asyncio.wait(
  26. fs={
  27. loop.run_in_executor(executor, run_in_thread, worker),
  28. loop.run_in_executor(executor, run_in_thread, bot),
  29. },
  30. return_when=asyncio.ALL_COMPLETED
  31. )
  32. if __name__ == '__main__':
  33. _init()
  34. asyncio.run(_main())