-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
80 lines (59 loc) · 1.91 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
70
71
72
73
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-
import logging
import logging.handlers
import os
import time
from telegram.ext import PicklePersistence, Application, Defaults
import bot.utils as utils
import bot.setup as setup
# Enable logging
def main():
(
token,
pickle,
chats,
admins,
defaults,
default_settings,
log_file,
log_size,
log_backups,
sheets_file,
sheets_email,
) = utils.parse_cfg("bot.ini")
logger = logging.getLogger()
logger.setLevel(logging.INFO)
rfh = logging.handlers.RotatingFileHandler(
log_file, maxBytes=log_size, backupCount=log_backups
)
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
rfh.setFormatter(formatter)
need_roll = os.path.isfile(log_file)
logger.addHandler(rfh)
if need_roll:
logger.info("\n---------\nLog closed on %s.\n---------\n" % time.asctime())
logger.handlers[0].doRollover()
persistence = PicklePersistence(pickle, single_file=False)
builder = Application.builder()
builder.token(token)
builder.persistence(persistence)
builder.defaults(Defaults(**defaults))
application = builder.build()
setup.register_application(
application,
admins=admins,
chats=chats,
default_settings=default_settings,
gsheets_file=sheets_file,
gsheets_email=sheets_email,
)
application.start_polling()
logger.info("\n---------\nLog started on %s.\n---------\n" % time.asctime())
# Run the bot until you press Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT. This should be used most of the time, since
# start_polling() is non-blocking and will stop the bot gracefully.
application.idle()
if __name__ == "__main__":
main()