this change adds self validation in __init__, allows to make config values with different types (not just string) and stores config values in classes for easier accessibility Signed-off-by: mctaylors <cantsendmails@mctaylors.ru>
43 lines
1.2 KiB
Python
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():
|
|
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()
|