import os
import asyncio
import logging
import sys

import django
import telebot
from telebot import asyncio_filters

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'poizonstore.settings')
django.setup()

from tg_bot.bot import bot, commands
from tg_bot.handlers import register_handlers


logger = telebot.logger
telebot.logger.setLevel(logging.DEBUG)


async def setup():
    await bot.delete_my_commands(scope=None, language_code=None)

    bot.add_custom_filter(asyncio_filters.StateFilter(bot))
    register_handlers()
    await bot.set_my_commands(commands=commands)


async def main():
    logger.info("bot starting...")
    await setup()
    await bot.infinity_polling()


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO, stream=sys.stdout)
    asyncio.run(main())
