-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlancher.py
72 lines (55 loc) · 1.71 KB
/
lancher.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import argparse
import asyncio
import logging
import textwrap
from discord.utils import setup_logging
from dotenv import load_dotenv
from utils import get_lumberjack
from bot import Soybot
# Multiple calls to getLogger() with the same name will return a reference to the same logger object.
# Hence, we are just calling the preset loggers in discord.py
log = get_lumberjack(__name__)
logging.getLogger('discord.http').setLevel(logging.WARNING)
setup_logging()
class EnvChoices:
dev = ('dev', 'development')
prod = ('prod', 'production')
docker = ('docker',)
@classmethod
def all(cls):
return cls.dev + cls.prod + cls.docker
def load_enviorment(filename: str):
if filename is None:
return
load_dotenv(filename)
async def main():
parser_description = textwrap.dedent('''\
command line arguments for soybot
''')
parser = argparse.ArgumentParser(description=parser_description)
env_help_text = textwrap.dedent(f'''\
This option helps load different environment variables.
Choices are {', '.join(f'"{env}"' for env in EnvChoices.all())}
''')
parser.add_argument(
'-e', '--env',
choices=EnvChoices.all(),
required=True,
help=env_help_text
)
env = parser.parse_args().env
if env == 'docker':
env_file = None
command_prefix = '!'
elif env in ('prod', 'production'):
env_file = '.env'
command_prefix = '!'
else:
env_file = f'.env.{env}'
command_prefix = '?'
load_enviorment(env_file)
async with Soybot(command_prefix=command_prefix) as bot:
await bot.start(os.getenv('TOKEN'))
if __name__ == '__main__':
asyncio.run(main())