-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathmain.py
91 lines (76 loc) · 3.69 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
91
# - *- coding: utf- 8 - *-
import os
import sys
import asyncio
import colorama
import aiogram
from aiogram import Dispatcher
from aiogram import executor
from colorama import Fore
from tgbot.data.config import get_admins
from tgbot.handlers import dp
from tgbot.loader import scheduler
from tgbot.middlewares import setup_middlewares
from tgbot.services.api_session import RequestsSession
from tgbot.services.api_sqlite import create_dbx
from tgbot.services.regular import send_message_start
from tgbot.utils.misc.bot_commands import set_commands
from tgbot.utils.misc.bot_logging import bot_logger
from tgbot.utils.misc_functions import check_update, check_bot_data, on_startup_notify, update_profit_day, \
update_profit_week, autobackup_admin, post_every_hour, post_every_eighteen, post_every_half_hour, \
post_half_eight, post_evening_events, posts3_every_hour, reinvite_sellers_by_city, sellers_news, catch_transactions, fetch_token
# Запуск шедулеров
async def scheduler_start():
#scheduler.add_job(send_message_start, 'interval', seconds=600)
#scheduler.add_job(post_every_hour, "cron", hour=21, minute=43)
#scheduler.add_job(sellers_news, "cron", hour=15, minute=9)
#scheduler.add_job(te, "cron", hour=15, minute=9)
#scheduler.add_job(reinvite_sellers_by_city, "cron", hour=18, minute=25)
#scheduler.add_job(posts3_every_hour, "interval", minutes=60)
#scheduler.add_job(post_every_hour, "interval", minutes=30)
#scheduler.add_job(post_half_eight, "cron", hour=18, minute=30)
#scheduler.add_job(post_evening_events, "cron", hour=22, minute=45)
#scheduler.add_job(post_evening_events, "cron", hour=19, minute=50)
#scheduler.add_job(post_half_eight, "interval", seconds=30)
#scheduler.add_job(post_every_eighteen, "cron", hour=17)
#scheduler.add_job(post_half_eight, "cron", hour=19, minute=35)
#scheduler.add_job(post_evening_events, "cron", hour=10, minute = 40)
#scheduler.add_job(check_order_messages, 'interval', seconds=600)
#scheduler.add_job(catch_transactions, "cron", hour=00)
#scheduler.add_job(fetch_token(user_login="raclear", password="123456"), 'interval', seconds=30)
scheduler.add_job(update_profit_week, "cron", day_of_week="mon", hour=00, minute=1)
scheduler.add_job(update_profit_day, "cron", hour=00)
scheduler.add_job(autobackup_admin, "cron", hour=00)
# Выполнение функции после запуска бота
async def on_startup(dp: Dispatcher):
await dp.bot.delete_webhook()
await dp.bot.get_updates(offset=-1)
dp.bot['rSession'] = RequestsSession()
await set_commands(dp)
await check_bot_data()
await scheduler_start()
await on_startup_notify(dp)
#asyncio.run(fetch_token(user_login="raclear", password="123456"))
bot_logger.exception("BOT WAS STARTED")
print(f"{Fore.LIGHTYELLOW_EX}~~~~~ Bot was started ~~~~~")
print(f"{Fore.LIGHTBLUE_EX}~~~~~ TG Developer: @raclear ~~~~~")
print(Fore.RESET)
if len(get_admins()) == 0: print("***** ENTER ADMIN ID IN settings.ini *****")
# Выполнение функции после выключения бота
async def on_shutdown(dp: Dispatcher):
rSession: RequestsSession = dp.bot['rSession']
await rSession.close()
#
await dp.storage.close()
await dp.storage.wait_closed()
await (await dp.bot.get_session()).close()
#
if sys.platform.startswith("win"):
os.system("cls")
else:
os.system("clear")
if __name__ == "__main__":
create_dbx()
scheduler.start()
setup_middlewares(dp)
executor.start_polling(dp, on_startup=on_startup, on_shutdown=on_shutdown)