forked from btseytlin/dungeon_bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
66 lines (48 loc) · 1.57 KB
/
run.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
#!/usr/bin/env python3
import dungeon_bot
from dungeon_bot.dungeon_bot import DungeonBot
import telegram
from telegram import TelegramError
#from telegram import Bot
import atexit
import logging
from logging.handlers import TimedRotatingFileHandler
api_token_path = 'data/api.token'
dungeon_bot_instance = None
def clean_up():
pass
# else:
# DungeonBot.get_instance().timer.cancel()
#DungeonBot.resart()
def start():
try:
global dungeon_bot_instance
with open(api_token_path) as f:
apitoken = f.read().strip()
tg = telegram.Bot(token=apitoken)
dungeon_bot_instance = DungeonBot()
dungeon_bot_instance.api = tg
dungeon_bot_instance.start_main_loop()
except (KeyboardInterrupt):
logger.exception("Finished program.")
clean_up()
log_path = './logs/botlog.log'
logger = logging.getLogger('dungeon_bot')
logger.setLevel(logging.DEBUG)
fh = TimedRotatingFileHandler(log_path, when="d", interval = 1, backupCount = 5)
fh.setLevel(logging.DEBUG)
console = logging.StreamHandler()
console.setLevel(logging.ERROR)
formatter = logging.Formatter('%(asctime)s|%(name)s|%(levelname)s|%(message)s')
console.setFormatter(formatter)
fh.setFormatter(formatter)
logger.addHandler(console)
logger.addHandler(fh)
combat_log_path = './logs/combat.log'
combat_logger = logging.getLogger('dungeon_bot_combat')
combat_logger.setLevel(logging.INFO)
fh = TimedRotatingFileHandler(combat_log_path, when="d", interval = 1, backupCount = 5)
fh.setLevel(logging.INFO)
combat_logger.addHandler(fh)
atexit.register(clean_up)
start()