-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcli.py
52 lines (35 loc) · 955 Bytes
/
cli.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 asyncio
import logging
import click
from config import LOG_LEVEL, TOKEN
from crimsobot import db
from crimsobot.bot import CrimsoBOT
logging.basicConfig(
format='[%(asctime)s] %(levelname)8s: %(message)s\t(%(name)s)',
datefmt='%Y-%m-%d %H:%M:%S',
level=LOG_LEVEL
)
@click.group()
def cli():
pass
@cli.command()
def run():
"""This command runs the bot."""
bot = CrimsoBOT()
bot.load_extensions()
bot.run(TOKEN)
@cli.command()
def initdb():
"""This command initializes the database schemas."""
click.secho('Creating tables...', bg='blue', fg='bright_white')
loop = asyncio.get_event_loop()
async def coro() -> None:
await db.connect()
await db.create_schemas(safe=True)
try:
loop.run_until_complete(coro())
finally:
loop.run_until_complete(db.close())
click.secho('Done!', bg='green', fg='bright_white')
if __name__ == '__main__':
cli()