38 lines
825 B
Python
Executable File
38 lines
825 B
Python
Executable File
#!/usr/bin/python3 -tt
|
|
|
|
# pypy detection
|
|
from platform import python_implementation as py_imp
|
|
|
|
import sys
|
|
import logging
|
|
import concurrent.futures
|
|
import asyncio
|
|
|
|
import toml
|
|
|
|
from bot import Bot
|
|
|
|
# only use uvloop if not using pypy
|
|
if py_imp() != 'PyPy':
|
|
import uvloop
|
|
asyncio.set_event_loop_policy( uvloop.EventLoopPolicy() )
|
|
|
|
if __name__ == '__main__':
|
|
evloop = asyncio.get_event_loop()
|
|
evloop.set_default_executor( concurrent.futures.ThreadPoolExecutor( 4 ) )
|
|
|
|
# parse bot configuration
|
|
cfg_file = './cfg.toml'
|
|
if len( sys.argv ) > 1: cfg_file = sys.argv[1]
|
|
cfg = toml.loads( open( cfg_file ).read() )
|
|
|
|
# create a bot instance
|
|
bot = Bot( evloop, cfg )
|
|
|
|
try: evloop.run_forever()
|
|
except KeyboardInterrupt:
|
|
logging.log( logging.INFO, 'POOF!' )
|
|
|
|
logging.log( logging.INFO, 'Event loop stopped, goodbye...' )
|
|
|