BotBase/bot.py

26 lines
1.1 KiB
Python
Raw Normal View History

2020-06-05 14:53:21 +02:00
import logging
2020-06-15 14:15:50 +02:00
from pyrogram import CallbackQueryHandler
2020-06-05 14:53:21 +02:00
from pyrogram.session import Session
import importlib
if __name__ == "__main__":
MODULE_NAME = "BotBase" # Change this to match the FOLDER name that contains the config.py file
conf = importlib.import_module(f"{MODULE_NAME}.config")
2020-06-15 14:15:50 +02:00
bot = conf.bot
antiflood = importlib.import_module(f"{MODULE_NAME}.modules.antiflood")
dbmodule = importlib.import_module(f"{MODULE_NAME}.database.query")
2020-06-05 14:53:21 +02:00
logging.basicConfig(format=conf.LOGGING_FORMAT, datefmt=conf.DATE_FORMAT, level=conf.LOGGING_LEVEL)
bot.add_handler(CallbackQueryHandler(antiflood.anti_flood, ~antiflood.BYPASS_USERS), group=-1)
2020-06-05 14:53:21 +02:00
Session.notice_displayed = True
try:
logging.warning("Running create_database()")
dbmodule.create_database(conf.DB_PATH, conf.DB_CREATE)
2020-06-05 14:53:21 +02:00
logging.warning("Database interaction complete")
logging.warning("Starting bot")
bot.start()
logging.warning("Bot started")
except Exception as e:
logging.warning(f"Stopping bot due to a {type(e).__name__}: {e}")
2020-06-05 14:53:21 +02:00
bot.stop()