70 lines
1.6 KiB
Python
Executable File
70 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import sys
|
|
import logging
|
|
import asyncio
|
|
|
|
from aiogram import executor
|
|
|
|
import filters
|
|
import handlers
|
|
from utils.announcements import scheduler
|
|
from load import dp, bot, config
|
|
from utils import set_commands
|
|
|
|
|
|
if (len(sys.argv) >= 2) and (sys.argv[1] == '-u'):
|
|
from parser import docs_parse; docs_parse()
|
|
sys.exit(0)
|
|
|
|
logging.basicConfig(
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
|
level=logging.INFO
|
|
)
|
|
logger = logging.getLogger("Bot")
|
|
|
|
WEBAPP_HOST = config.ip
|
|
WEBAPP_PORT = config.port
|
|
|
|
WEBHOOK_HOST = f'http://{WEBAPP_HOST}:{WEBAPP_PORT}'
|
|
WEBHOOK_PATH = f'/bot{config.token}/'
|
|
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}"
|
|
|
|
|
|
async def on_startup(dp):
|
|
await set_commands(dp)
|
|
await bot.set_webhook(url=WEBHOOK_URL)
|
|
|
|
|
|
async def on_shutdown(dp):
|
|
await bot.delete_webhook()
|
|
|
|
|
|
def main() -> None:
|
|
if config.enable_logging:
|
|
logger.info("Logging enabled!")
|
|
else:
|
|
logger.info("Logging disabled!")
|
|
|
|
#loop = asyncio.get_event_loop()
|
|
loop = asyncio.new_event_loop()
|
|
asyncio.set_event_loop(loop)
|
|
loop.create_task(scheduler())
|
|
|
|
if config.use_webhook.lower() in ['t', 'true', '1', 'yes', 'y']:
|
|
executor.start_webhook(
|
|
dispatcher=dp,
|
|
loop=loop,
|
|
webhook_path=WEBHOOK_PATH,
|
|
on_startup=on_startup,
|
|
skip_updates=False,
|
|
on_shutdown=on_shutdown,
|
|
host=WEBAPP_HOST,
|
|
port=WEBAPP_PORT,
|
|
)
|
|
else:
|
|
executor.start_polling(dp, skip_updates=True)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|