This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
90 lines (76 loc) · 3.2 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
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
import logging
from datetime import datetime, timedelta
from pytz import timezone
from telegram import ext as telegram_ext
from config.constants import WEEKDAY_TUESDAY, WEEKDAY_WEDNESDAY
from config.env import TELEGRAM_TOKEN
from handlers.callback import handler_callback
from handlers.commandActive import handler_command_active
from handlers.commandDump import handler_command_dump
from handlers.commandForceActive import handler_command_forceactive
from handlers.commandForceMatch import handler_command_forcematch
from handlers.commandForceNotify import handler_command_forcenotify
from handlers.commandForceRematch import handler_command_forcerematch
from handlers.commandInfo import handler_command_info
from handlers.commandSettings import handler_command_settings
from handlers.commandStart import handler_command_start
from handlers.commandStop import handler_command_stop
from handlers.error import handler_error
from utils.migrate import migrate
from utils.performMatch import perform_match
from utils.performRematch import perform_rematch
logging.basicConfig(
format="[%(asctime)s][%(name)s][%(levelname)s] %(message)s", level=logging.INFO
)
def main():
persistence = telegram_ext.PicklePersistence(filepath="database/store.pickle")
job_queue = telegram_ext.JobQueue()
app = (
telegram_ext.ApplicationBuilder()
.token(TELEGRAM_TOKEN)
.persistence(persistence)
.job_queue(job_queue)
.build()
)
# Initialize matcher
moment = datetime.now(timezone("Europe/Moscow")).replace(
hour=10, minute=0, second=0
)
moment += timedelta(days=(WEEKDAY_TUESDAY - moment.weekday()) % 7)
app.job_queue.run_repeating(perform_match, interval=timedelta(days=7), first=moment)
# Initialize re-matcher
moment = datetime.now(timezone("Europe/Moscow")).replace(
hour=10, minute=0, second=0
)
moment += timedelta(days=(WEEKDAY_WEDNESDAY - moment.weekday()) % 7)
app.job_queue.run_repeating(
perform_rematch, interval=timedelta(days=7), first=moment
)
# Migrations
app.job_queue.run_once(migrate, when=0)
# Handlers
app.add_handler(telegram_ext.CommandHandler("active", handler_command_active))
app.add_handler(telegram_ext.CommandHandler("dump", handler_command_dump))
app.add_handler(
telegram_ext.CommandHandler("forceactive", handler_command_forceactive)
)
app.add_handler(
telegram_ext.CommandHandler("forcematch", handler_command_forcematch)
)
app.add_handler(
telegram_ext.CommandHandler("forcenotify", handler_command_forcenotify)
)
app.add_handler(
telegram_ext.CommandHandler("forcerematch", handler_command_forcerematch)
)
app.add_handler(telegram_ext.CommandHandler("info", handler_command_info))
app.add_handler(telegram_ext.CommandHandler("settings", handler_command_settings))
app.add_handler(telegram_ext.CommandHandler("start", handler_command_start))
app.add_handler(telegram_ext.CommandHandler("stop", handler_command_stop))
app.add_handler(telegram_ext.CallbackQueryHandler(handler_callback))
app.add_error_handler(handler_error)
# Go!
app.run_polling()
if __name__ == "__main__":
main()