-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
53 lines (46 loc) · 1.4 KB
/
bot.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
import logging
import betterlogging as bl
from pyrogram import Client
from pyrogram.enums import ParseMode
from src.config import (
get_config,
RuntimeSettings,
get_redis_engine,
)
from src.bot.tools.dispatcher import Dispatcher
from src.services.code_pars.piston import PistonClient
from src.bot.modules import routers
def setup_logging() -> None:
log_level = logging.INFO
bl.basic_colorized_config(level=log_level)
logging.basicConfig(
level=logging.INFO,
format='%(filename)s:%(lineno)d #%(levelname)-8s [%(asctime)s] - %(name)s - %(message)s',
)
logger = logging.getLogger(__name__)
logger.info('Starting bot')
def main() -> None:
setup_logging()
config = get_config()
redis = get_redis_engine(config.redis)
runtime_settings = RuntimeSettings('.config/settings.json')
runtime_settings.load()
client = Client(
name='userbot',
api_id=config.userbot.api_id,
api_hash=config.userbot.api_hash,
parse_mode=ParseMode.MARKDOWN,
)
dp = Dispatcher(
client=client,
runtime_settings=runtime_settings,
routers=routers,
redis=redis,
piston=PistonClient(),
)
dp.run()
if __name__ == '__main__':
try:
main()
except (KeyboardInterrupt, SystemExit):
logging.error('Бот був вимкнений!')