This repository has been archived by the owner on Nov 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
52 lines (45 loc) · 1.61 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import argparse
import asyncio
from concurrent import futures
from lib.utils import get_current_sha1
from websockets import WebSocketException
from bot import QuantumBot
__version__ = get_current_sha1()
def process_arg():
parser = argparse.ArgumentParser(
description=__doc__,
epilog=f"Quantum {__version__}"
)
parser.add_argument(
"--version", "-v",
action="version", version=f"Quantum {__version__}"
)
parser.add_argument(
"--config", "-c",
help="path to configuation file",
default="default.toml"
)
parser.add_argument(
"--logging", "-l",
choices=["i", "c", "ws", "d", "w", "e"],
help="set logging to Info, Chat, WebSocket, Debug, Warn, Error; respectively",
default="i"
)
return parser.parse_args()
async def start(executor, bot):
asyncio.get_event_loop().run_in_executor(executor, bot.process_message_queue)
asyncio.get_event_loop().run_in_executor(executor, bot.process_input)
settings = bot.settings
while settings["bot"]["auto_restart"]:
try:
await bot.run()
except WebSocketException:
bot.is_running = False
bot.log.error(f"websocket crashed, Restarting in {settings['bot']['restart_time']}")
if settings["bot"]["restart_attempts"] != 0:
settings["bot"]["restart_attempts"] -= 1
await asyncio.sleep(settings['bot']['restart_time'])
executor = futures.ThreadPoolExecutor(max_workers=3, )
args = process_arg()
bot = QuantumBot(args)
asyncio.get_event_loop().run_until_complete(start(executor, bot))