forked from Pbatch/ClashRoyaleBuildABot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
68 lines (56 loc) · 1.83 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
from datetime import datetime
import signal
import sys
import threading
import time
from loguru import logger
from clashroyalebuildabot.actions.archers_action import ArchersAction
from clashroyalebuildabot.actions.giant_action import GiantAction
from clashroyalebuildabot.actions.goblin_barrel_action import (
GoblinBarrelAction,
)
from clashroyalebuildabot.actions.knight_action import KnightAction
from clashroyalebuildabot.actions.minions_action import MinionsAction
from clashroyalebuildabot.actions.minipekka_action import MinipekkaAction
from clashroyalebuildabot.actions.musketeer_action import MusketeerAction
from clashroyalebuildabot.actions.zap_action import ZapAction
from clashroyalebuildabot.bot import Bot
start_time = datetime.now()
logger.remove()
logger.add(
sys.stderr,
format="{time} {level} {message}",
backtrace=False,
diagnose=False,
)
def update_terminal_title():
while True:
elapsed_time = datetime.now() - start_time
hours, remainder = divmod(elapsed_time.total_seconds(), 3600)
minutes, seconds = divmod(remainder, 60)
formatted_time = f"{int(hours):02}:{int(minutes):02}:{int(seconds):02}"
sys.stdout.write(f"\x1b]2;{formatted_time} | BuildABot\x07")
sys.stdout.flush()
time.sleep(1)
def main():
actions = {
ArchersAction,
ZapAction,
GoblinBarrelAction,
GiantAction,
KnightAction,
MinionsAction,
MinipekkaAction,
MusketeerAction,
}
try:
bot = Bot(actions=actions)
bot.run()
except Exception as e:
logger.error(f"An error occurred: {e}")
sys.exit(1)
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal.SIG_DFL)
title_thread = threading.Thread(target=update_terminal_title, daemon=True)
title_thread.start()
main()