2022-08-07 04:45:35 -04:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
import logging
|
|
|
|
|
2023-01-22 05:27:20 -05:00
|
|
|
from aiogram import executor
|
2023-01-04 15:14:32 -05:00
|
|
|
from load import dp, bot, scheduler
|
|
|
|
|
2023-01-22 05:27:20 -05:00
|
|
|
|
2022-08-16 06:28:08 -04:00
|
|
|
import filters
|
2023-01-22 05:27:20 -05:00
|
|
|
import config
|
|
|
|
|
2022-08-16 06:28:08 -04:00
|
|
|
|
|
|
|
dp.filters_factory.bind(filters.AvaibleRolesFilter)
|
|
|
|
dp.filters_factory.bind(filters.ReplayMessageFilter)
|
|
|
|
|
2022-08-07 04:45:35 -04:00
|
|
|
import handlers
|
|
|
|
|
|
|
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
|
|
|
|
|
|
|
|
WEBAPP_HOST = '127.0.0.1'
|
|
|
|
WEBAPP_PORT = 3001
|
|
|
|
|
|
|
|
# Don`t touch anything!
|
|
|
|
WEBHOOK_HOST = f'http://{WEBAPP_HOST}:{WEBAPP_PORT}'
|
|
|
|
WEBHOOK_PATH = f'/bot{config.token}/'
|
2023-01-22 05:27:20 -05:00
|
|
|
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}"
|
|
|
|
|
2022-08-07 04:45:35 -04:00
|
|
|
|
|
|
|
async def on_startup(dp):
|
2023-01-13 03:22:32 -05:00
|
|
|
from utils.notify_start import notify_started_bot, database_is_empty
|
|
|
|
|
2023-01-22 05:27:20 -05:00
|
|
|
DATABASE_EMPTY = database_is_empty()
|
2023-01-13 03:22:32 -05:00
|
|
|
if DATABASE_EMPTY:
|
2023-01-22 05:27:20 -05:00
|
|
|
await bot.send_message(config.second_group_id,
|
|
|
|
"Member table is empty, run: `!reload`", parse_mode="Markdown")
|
2022-11-25 16:31:49 -05:00
|
|
|
|
2022-08-07 04:45:35 -04:00
|
|
|
await notify_started_bot(bot)
|
2023-01-13 03:22:32 -05:00
|
|
|
|
2022-08-07 04:45:35 -04:00
|
|
|
from utils.default_commands import set_default_commands
|
|
|
|
await set_default_commands(dp)
|
2022-08-13 08:25:52 -04:00
|
|
|
|
2023-01-04 15:14:32 -05:00
|
|
|
# Reloading users data
|
|
|
|
from utils import reload_users_data
|
2023-01-22 05:27:20 -05:00
|
|
|
scheduler.add_job(reload_users_data, "interval", seconds=config.update_interval)
|
2023-01-04 15:14:32 -05:00
|
|
|
scheduler.start()
|
|
|
|
|
2022-08-13 08:25:52 -04:00
|
|
|
from load import tgc
|
|
|
|
await tgc.client.start()
|
2023-01-04 15:14:32 -05:00
|
|
|
|
2022-08-07 04:45:35 -04:00
|
|
|
await bot.set_webhook(WEBHOOK_URL)
|
|
|
|
|
2023-01-22 05:27:20 -05:00
|
|
|
|
2022-08-07 04:45:35 -04:00
|
|
|
async def on_shutdown(dp):
|
|
|
|
await bot.delete_webhook()
|
|
|
|
|
|
|
|
# Close Redis connection.
|
|
|
|
await dp.storage.close()
|
|
|
|
await dp.storage.wait_closed()
|
|
|
|
|
2023-01-22 05:27:20 -05:00
|
|
|
|
2022-08-07 04:45:35 -04:00
|
|
|
def main() -> None:
|
2023-01-13 03:22:32 -05:00
|
|
|
|
2022-11-06 03:48:10 -05:00
|
|
|
if config.USE_WEBHOOK:
|
2022-08-07 04:45:35 -04:00
|
|
|
executor.start_webhook(
|
|
|
|
dispatcher=dp,
|
|
|
|
webhook_path=WEBHOOK_PATH,
|
|
|
|
on_startup=on_startup,
|
|
|
|
on_shutdown=on_shutdown,
|
|
|
|
skip_updates=True,
|
|
|
|
host=WEBAPP_HOST,
|
2023-01-04 15:14:32 -05:00
|
|
|
port=WEBAPP_PORT
|
2022-08-07 04:45:35 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
2023-01-22 05:27:20 -05:00
|
|
|
executor.start_polling(dp, skip_updates=True)
|
2023-01-04 15:14:32 -05:00
|
|
|
|
2023-01-22 05:27:20 -05:00
|
|
|
|
2022-08-07 04:45:35 -04:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|