/
main.py
54 lines (44 loc) · 1.33 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
import logging
from logging.handlers import RotatingFileHandler
import core.bot as bot
import core.commands as commands
import core.events as events
LOAD_EVENTS = [
"on_ready",
]
LOAD_COMMANDS = [
"help",
"create_ctf",
"create_challenge",
"add_player",
"remove_ctf",
"remove_player",
"solved",
"unsolve",
"archive_ctf",
"release_ctf"
]
def init_logging():
log_formatter = logging.Formatter("[%(asctime)s][%(levelname)-8s] %(message)-80s\t[%(pathname)s:%(funcName)s:%(lineno)d]")
log_file = bot.config.get("LOG_FILE")
megabyte = 1024*1024
log_handler = RotatingFileHandler(log_file, mode='a', maxBytes=5*megabyte, backupCount=10, encoding='utf-8', delay=False)
log_handler.setFormatter(log_formatter)
log_handler.setLevel(logging.DEBUG)
bot_log = logging.getLogger("bot")
bot_log.setLevel(logging.DEBUG)
bot_log.addHandler(log_handler)
if __name__ == "__main__":
init_logging()
logger = logging.getLogger("bot")
logger.info("BOT STARTING")
try:
bot.init()
events.load(LOAD_EVENTS)
events.register(LOAD_EVENTS)
commands.load(LOAD_COMMANDS)
logger.info("Bot configured, starting to run now")
bot.run()
except Exception as raised_exception:
logger.exception(f"UNCAUGHT CRITICAL EXCEPTION")
raise