-
Notifications
You must be signed in to change notification settings - Fork 3
/
launcher.py
57 lines (39 loc) · 1.14 KB
/
launcher.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
53
54
55
56
57
from argparse import ArgumentParser
from loguru import logger
from auth import DB_URL_DEV, DB_URL_PROD, TOKEN_DEV, TOKEN_PROD
from ouranos.bot import Ouranos
from ouranos.utils import log
# set up uvloop if we can
try:
import uvloop
uvloop.install()
except:
pass
def start_bot(args):
dev = args.dev
lvl = args.log
if not lvl:
lvl = "debug" if dev else "info"
log.init(lvl.upper())
token = TOKEN_DEV if dev else TOKEN_PROD
db_url = DB_URL_DEV if dev else DB_URL_PROD
bot = Ouranos(token, db_url)
logger.info("Starting up.")
try:
bot.run()
finally:
try:
exit_code = bot._exit_code
except AttributeError:
logger.info("Bot's exit code could not be retrieved.")
exit_code = 0
logger.info(f"Bot closed with exit code {exit_code}.\n" + "-" * 100)
exit(exit_code)
def main():
parser = ArgumentParser(description="Launch Ouranos Discord bot.")
parser.add_argument("--log")
parser.add_argument("--dev", action="store_true")
args = parser.parse_args()
start_bot(args)
if __name__ == "__main__":
main()