mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2025-12-19 21:55:06 +01:00
improved initial check for environment variables
This commit is contained in:
11
main.py
11
main.py
@@ -7,17 +7,23 @@ from telegram_bot import ChatGPT3TelegramBot
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# Read .env file
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
# Setup logging
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||||
level=logging.INFO
|
level=logging.INFO
|
||||||
)
|
)
|
||||||
|
|
||||||
if 'TELEGRAM_BOT_TOKEN' not in os.environ:
|
# Check if the required environment variables are set
|
||||||
logging.error('Telegram bot token not found in environment variables')
|
required_values = ['TELEGRAM_BOT_TOKEN', 'OPENAI_EMAIL', 'OPENAI_PASSWORD']
|
||||||
|
missing_values = [value for value in required_values if os.environ.get(value) is None]
|
||||||
|
if len(missing_values) > 0:
|
||||||
|
logging.error(f'The following environment values are missing in your .env: {", ".join(missing_values)}')
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
# Setup configuration
|
||||||
chatgpt_config = {
|
chatgpt_config = {
|
||||||
'email': os.environ['OPENAI_EMAIL'],
|
'email': os.environ['OPENAI_EMAIL'],
|
||||||
'password': os.environ['OPENAI_PASSWORD'],
|
'password': os.environ['OPENAI_PASSWORD'],
|
||||||
@@ -29,6 +35,7 @@ def main():
|
|||||||
}
|
}
|
||||||
debug = os.environ.get('DEBUG', 'true').lower() == 'true'
|
debug = os.environ.get('DEBUG', 'true').lower() == 'true'
|
||||||
|
|
||||||
|
# Setup and run ChatGPT and Telegram bot
|
||||||
gpt3_bot = ChatGPT3Bot(config=chatgpt_config, debug=debug)
|
gpt3_bot = ChatGPT3Bot(config=chatgpt_config, debug=debug)
|
||||||
telegram_bot = ChatGPT3TelegramBot(config=telegram_config, gpt3_bot=gpt3_bot)
|
telegram_bot = ChatGPT3TelegramBot(config=telegram_config, gpt3_bot=gpt3_bot)
|
||||||
telegram_bot.run()
|
telegram_bot.run()
|
||||||
|
|||||||
Reference in New Issue
Block a user