-
Notifications
You must be signed in to change notification settings - Fork 1
/
create_bot.py
53 lines (44 loc) · 1.05 KB
/
create_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 sys
from aiogram import Bot
from aiogram.dispatcher import Dispatcher
from environs import Env
from loguru import logger
from googlesheet import GoogleSheet
env = Env()
env.read_env()
logger.remove()
logger.add(sys.stderr, level=env.int("LOG_LEVEL"))
class TelegramBot(Bot):
def __init__(
self,
token,
googlesheet: GoogleSheet | None = None,
) -> None:
super().__init__(
token,
)
if googlesheet:
self.googlesheet: GoogleSheet = googlesheet
bot: TelegramBot = TelegramBot(
token=env.str("BOT_TOKEN"),
googlesheet=GoogleSheet(
env.str("CREDENTIAL_FILE"),
env.str("GOOGLESHEET_FILE_KEY"),
),
)
dp = Dispatcher(bot)
logger.add(
env.str("ERROR_LOG_FILE"),
format="{time} {level} {message}",
level="WARNING",
rotation="10 MB",
compression="tar.xz",
)
logger.add(
env.str("INFO_LOG_FILE"),
format="{time} {level} {message}",
level="INFO",
rotation="10 MB",
compression="tar.xz",
)
logger.debug("✅ Бот запущен")