-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
65 lines (46 loc) · 1.62 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
import logging
from logging.handlers import RotatingFileHandler
from pyrogram import Client, raw, __version__
from tg.handlers import HANDLERS
from db import repository
from data import config
# log config
logging.getLogger("pyrogram").setLevel(logging.WARNING)
root_logger = logging.getLogger()
root_logger.setLevel(level=logging.DEBUG)
log_format = logging.Formatter("%(asctime)s | %(levelname)s | %(name)s | %(message)s")
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(log_format)
root_logger.addHandler(console_handler)
file_handler = RotatingFileHandler(
filename="bot.log", maxBytes=20 * (2**20), backupCount=3, mode="D", encoding="utf-8"
)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(log_format)
root_logger.addHandler(file_handler)
_logger = logging.getLogger(__name__)
settings = config.get_settings()
app = Client(
name="my_bot",
api_id=settings.telegram_api_id,
api_hash=settings.telegram_api_hash,
bot_token=settings.telegram_bot_token,
)
def main():
logging.info(
f"The bot is up and running on Pyrogram v{__version__} (Layer {raw.all.layer})."
)
for handler in HANDLERS:
app.add_handler(handler)
for admin in settings.admins:
if not repository.is_user_exists(tg_id=admin):
repository.create_user(
tg_id=admin, name="admin", admin=True, language_code="he"
)
else:
if not repository.is_admin(tg_id=admin):
repository.update_user(tg_id=admin, admin=True)
app.run()
if __name__ == "__main__":
main()