From 4ddcd2b374d12c0df7c7a932d2e701c3a2181df6 Mon Sep 17 00:00:00 2001 From: crate Date: Sun, 4 Jan 2026 05:36:35 -0600 Subject: [PATCH] env vars testing --- .gitignore | 1 + docker-compose.yml | 8 ++++++++ garfmain.py | 11 +++++------ garfpy/garfai.py | 10 +++++----- garfpy/kroger.py | 6 +++--- garfpy/weather.py | 4 ++-- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index fb3ec2b..ebf3545 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ config.py __pycache__/ garfpy/__pycache__/ *.venv* +.idea *.json *.old *.log* diff --git a/docker-compose.yml b/docker-compose.yml index 4066fb3..a26d4f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,6 +2,14 @@ services: garfbot: image: git.crate.zip/crate/garfbot:latest container_name: garfbot + environment: + - TXT_MODEL=${TXT_MODEL} + - IMG_MODEL=${IMG_MODEL} + - GARFBOT_TOKEN=${GARFBOT_TOKEN} + - OPENAI_TOKEN=${OPENAI_TOKEN} + - WEATHER_TOKEN=${WEATHER_TOKEN} + - KROGER_ID=${KROGER_ID} + - KROGER_SECRET=${KROGER_SECRET} restart: always volumes: - /home/crate/garfbot:/usr/src/app diff --git a/garfmain.py b/garfmain.py index f588acc..5eea509 100644 --- a/garfmain.py +++ b/garfmain.py @@ -1,4 +1,4 @@ -import config +import os import asyncio import discord from discord.ext import commands @@ -16,10 +16,9 @@ from garfpy import ( ) -gapikey = config.GIF_TOKEN -garfkey = config.GARFBOT_TOKEN -txtmodel = config.TXT_MODEL -imgmodel = config.IMG_MODEL +garfkey = os.getenv("GARFBOT_TOKEN") +txtmodel = os.getenv("TXT_MODEL") +imgmodel = os.getenv("IMG_MODEL") intents = discord.Intents.default() intents.members = True @@ -181,7 +180,7 @@ async def on_message(message): async def garfbot_connect(): while True: try: - await garfbot.start(garfkey) + await garfbot.start(garfkey) # type: ignore except Exception as e: e = str(e) logger.error(f"Garfbot couldn't connect! {e}") diff --git a/garfpy/garfai.py b/garfpy/garfai.py index f46e2d5..a090718 100644 --- a/garfpy/garfai.py +++ b/garfpy/garfai.py @@ -1,6 +1,6 @@ import io +import os import openai -import config import aiohttp import asyncio import discord @@ -11,9 +11,9 @@ from garfpy import logger class GarfAI: def __init__(self): - self.openaikey = config.OPENAI_TOKEN - self.txtmodel = config.TXT_MODEL - self.imgmodel = config.IMG_MODEL + self.openaikey = os.getenv('OPENAI_TOKEN') + self.txtmodel = os.getenv('TXT_MODEL') + self.imgmodel = os.getenv('IMG_MODEL') self.image_request_queue = asyncio.Queue() async def garfpic(self, ctx, prompt): @@ -82,7 +82,7 @@ class GarfAI: try: client = AsyncOpenAI(api_key=self.openaikey) response = await client.chat.completions.create( - model=self.txtmodel, + model=self.txtmodel, # type: ignore messages=[ { "role": "system", diff --git a/garfpy/kroger.py b/garfpy/kroger.py index 66b7d8f..b7cf5f7 100644 --- a/garfpy/kroger.py +++ b/garfpy/kroger.py @@ -1,4 +1,4 @@ -import config +import os import requests from base64 import b64encode from garfpy import logger @@ -6,8 +6,8 @@ from garfpy import logger class Kroger: def __init__(self): - self.client_id = config.CLIENT_ID - self.client_secret = config.CLIENT_SECRET + self.client_id = os.getenv('CLIENT_ID') + self.client_secret = os.getenv('CLIENT_SECRET') self.auth = b64encode( f"{self.client_id}:{self.client_secret}".encode() ).decode() diff --git a/garfpy/weather.py b/garfpy/weather.py index 3bbe16f..e689625 100644 --- a/garfpy/weather.py +++ b/garfpy/weather.py @@ -1,5 +1,5 @@ +import os import re -import config import discord import aiohttp from garfpy import logger @@ -7,7 +7,7 @@ from garfpy import logger class WeatherAPI: def __init__(self, api_key=None): - self.api_key = api_key or config.WEATHER_TOKEN + self.api_key = api_key or os.getenv("WEATHER_TOKEN") self.base_url = "https://api.openweathermap.org/data/2.5/weather" def parse_location(self, location):