danbooru-bot/main.py
mctaylors e448cbc45f
All checks were successful
Build / Upload to production (push) Successful in 1m38s
feat: generate and validate config.ini
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-06-09 01:02:01 +03:00

53 lines
1.5 KiB
Python

import logging
import os
import config
from telegram.ext import CommandHandler, InlineQueryHandler, ApplicationBuilder
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
)
# set higher logging level for httpx to avoid all GET and POST requests being logged
logging.getLogger("httpx").setLevel(logging.WARNING)
logger = logging.getLogger(__name__)
def main() -> None:
config.init_config()
application = ApplicationBuilder().token(get_token()).build()
import commands
application.add_handler(
CommandHandler("start", commands.info_command, has_args=True)
)
application.add_handler(CommandHandler("start", commands.start_command))
application.add_handler(CommandHandler("help", commands.help_command))
application.add_handler(CommandHandler("about", commands.about_command))
application.add_handler(CommandHandler("info", commands.info_command))
application.add_handler(CommandHandler("user", commands.user_command))
from inline_query import inline_query
application.add_handler(InlineQueryHandler(inline_query))
application.run_polling(allowed_updates=commands.Update.ALL_TYPES)
def get_token() -> str:
if os.getenv("BOT_TOKEN") is not None:
return os.getenv("BOT_TOKEN")
if config.general.token != "":
return config.general.token
print(
f"Set BOT_TOKEN environment variable or use 'Token' option in section [General] in {config.config_file} to set bot token."
)
exit(1)
if __name__ == "__main__":
main()