-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
69 lines (55 loc) · 1.79 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
import json
import logging
import os
from logging.handlers import RotatingFileHandler
from pathlib import Path
os.environ["TZ"] = "UTC+00:00" # fix timezone
def init_logger(bot_slug: str):
logger = logging.getLogger()
# File logging
logDir = Path(__file__).parent.parent.joinpath("logs")
if not logDir.exists():
os.makedirs(str(logDir.absolute()))
# file_time = datetime.datetime.now().isoformat().replace(":", "-")[:19]
logFilename = logDir.joinpath(bot_slug + ".log")
print("Logging to file:", str(logFilename))
# fileHandler = logging.FileHandler(filename=str(logFilename), encoding="utf-8")
fileHandler = RotatingFileHandler(
logFilename,
mode="a",
maxBytes=5 * 1024 * 1024,
backupCount=2,
encoding="utf-8",
)
fileHandler.setFormatter(
logging.Formatter("%(asctime)s %(levelname)s - %(message)s")
)
logger.addHandler(fileHandler)
# Screen stream logging
streamHandler = logging.StreamHandler()
streamHandler.setFormatter(
logging.Formatter("%(asctime)s %(levelname)s - %(message)s")
)
logger.addHandler(streamHandler)
# Loggin Level
# logger.setLevel(logging.WARNING)
# logger.setLevel(logging.DEBUG)
logger.setLevel(logging.INFO)
return logger
from thebot import error_handler, message_handler
from thebot.my_bot import MyBot
# Initialize
slug = "mmbot"
bot = MyBot(
slug=slug,
mixin_config_file="../config/mixin.json",
operation_config_file="../config/operation.json",
message_handle=message_handler.handle,
error_handle=error_handler.handle,
logger=init_logger(slug),
)
bot.refresh_my_profile()
print("current bot:", bot.profile.user_id)
print(bot.profile.mixin_number, bot.profile.name)
# run blaze forever
bot.blaze.run_forever(3)