mirror of
https://github.com/aljazceru/chatgpt-telegram-bot.git
synced 2025-12-19 13:44:57 +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():
|
||||
# Read .env file
|
||||
load_dotenv()
|
||||
|
||||
# Setup logging
|
||||
logging.basicConfig(
|
||||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
||||
level=logging.INFO
|
||||
)
|
||||
|
||||
if 'TELEGRAM_BOT_TOKEN' not in os.environ:
|
||||
logging.error('Telegram bot token not found in environment variables')
|
||||
# Check if the required environment variables are set
|
||||
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)
|
||||
|
||||
# Setup configuration
|
||||
chatgpt_config = {
|
||||
'email': os.environ['OPENAI_EMAIL'],
|
||||
'password': os.environ['OPENAI_PASSWORD'],
|
||||
@@ -29,6 +35,7 @@ def main():
|
||||
}
|
||||
debug = os.environ.get('DEBUG', 'true').lower() == 'true'
|
||||
|
||||
# Setup and run ChatGPT and Telegram bot
|
||||
gpt3_bot = ChatGPT3Bot(config=chatgpt_config, debug=debug)
|
||||
telegram_bot = ChatGPT3TelegramBot(config=telegram_config, gpt3_bot=gpt3_bot)
|
||||
telegram_bot.run()
|
||||
|
||||
Reference in New Issue
Block a user