danbooru-bot/main.py
mctaylors 0ee018e2ce
refactor: define parameter types *again*
Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
2025-05-18 12:30:22 +03:00

43 lines
1.2 KiB
Python

import logging
import os
from telegram.ext import Application, CommandHandler, InlineQueryHandler
from config import *
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:
application = Application.builder().token(get_token()).build()
import commands
application.add_handler(CommandHandler("start", commands.start_command))
application.add_handler(CommandHandler("help", commands.help_command))
application.add_handler(CommandHandler("about", commands.about_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() -> None:
if os.getenv("BOT_TOKEN") is not None:
return os.getenv("BOT_TOKEN")
if general.token != "":
return general.token
print("Set BOT_TOKEN environment variable or use General.Token in config.ini to set bot token.")
exit(1)
if __name__ == "__main__":
main()