-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
77 lines (62 loc) · 2.38 KB
/
main.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
73
74
75
76
77
import argparse
import asyncio
import logging
from typing import NoReturn
import chess.engine
import httpx
import config
from game_manager import GameManager
from lichess import Lichess
LOGO = """
__ _ _ _
__ _ ___ _ _ _ __ ___ / /(_) ___ | |__ ___ | |_
/ _` / __| | | | '_ \ / __|/ / | |/ _ \ _____| '_ \ / _ \| __|
| (_| \__ \ |_| | | | | (__/ /__| | (_) |_____| |_) | (_) | |_
\__,_|___/\__, |_| |_|\___\____/_|\___/ |_.__/ \___/ \__|
|___/
"""
logger = logging.getLogger(__name__)
async def main(args: argparse.Namespace) -> NoReturn:
logging_handlers = [logging.StreamHandler()]
if args.log:
logging_handlers.append(logging.FileHandler(args.log))
logging.basicConfig(
level=logging.DEBUG if args.verbose else logging.INFO,
format="%(asctime)s %(levelname)-8s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
handlers=logging_handlers,
)
logging.getLogger(httpx.__name__).setLevel(
logging.DEBUG if args.verbose else logging.WARNING
)
config.load_config(args.config)
print(LOGO)
async with Lichess() as li:
if args.upgrade:
if li.title == "BOT":
logger.warning(
f"{li.username} is already a BOT account. Run asyncLio-bot without the upgrade flag in the future."
)
else:
await li.upgrade_account()
logger.info(f"Upgraded {li.username} to a BOT account.")
return
if li.title != "BOT":
logger.critical("asyncLio-bot can only be used by BOT accounts.")
return
logger.info(f"Logged in as {li.me}.")
await GameManager(li).watch_event_stream()
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--upgrade", "-u", action="store_true", help="Upgrade account to BOT account."
)
parser.add_argument("--log", "-l", type=str, help="Log file.")
parser.add_argument(
"--config", "-c", type=str, default="config.yml", help="Log file."
)
parser.add_argument(
"--verbose", "-v", action="store_true", help="Make output more verbose."
)
asyncio.set_event_loop_policy(chess.engine.EventLoopPolicy())
asyncio.run(main(parser.parse_args()))