diff --git a/garfbot.py b/garfbot.py index ab34370..70953a1 100644 --- a/garfbot.py +++ b/garfbot.py @@ -27,28 +27,26 @@ intents.messages = True intents.message_content = True client = discord.Client(intents=intents) + @client.event async def on_ready(): - asyncio.create_task(process_image_requests()) - print(f"Logged in as {client.user.name} running gpt-3.5-turbo.", flush=True) + asyncio.create_task(process_image_requests()) # Important! + print(f"Logged in as {client.user.name} running {txtmodel} {imgmodel}.", flush=True) +# Json Handling +meows_file = "meow_counts.json" +stats_file = "user_stats.json" -# MeowCounts File -counts_file = "meow_counts.json" -meow_counts = defaultdict(int) -if os.path.isfile(counts_file): - with open(counts_file, "r") as f: - meow_counts.update(json.load(f)) -elif os.path.exists(counts_file): - with open(counts_file, "r") as f: - meow_counts = json.load(f) -try: - with open("user_stats.json", "r") as f: - user_stats = json.load(f) -except FileNotFoundError: - user_stats = {} +def json_load(file_path, default): + if os.path.isfile(file_path): + with open(file_path, "r") as f: + return json.load(f) + else: + return default +meow_counts = defaultdict(int, json_load(meows_file, {})) +user_stats = json_load(stats_file, {}) # GarfChats @@ -75,7 +73,6 @@ async def generate_chat_response(question): return f"`GarfBot Error: Lasagna`" - # GarfPics async def generate_image(prompt): try: @@ -163,7 +160,7 @@ async def on_message(message): meow_counts[str(message.author.id)] += 1 - with open(counts_file, "w") as f: + with open(meows_file, "w") as f: json.dump(dict(meow_counts), f) if message.content.lower() == "meowcount":