From ce3dee71973912ee6617f1fd2e1a36103afdbf88 Mon Sep 17 00:00:00 2001 From: ProbablyButter Date: Fri, 15 Sep 2023 18:09:48 -0700 Subject: [PATCH] Pickle gizmoResources --- cog_modules/random/cog.py | 4 ++++ resources.py | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cog_modules/random/cog.py b/cog_modules/random/cog.py index c60f960..3b73fb8 100644 --- a/cog_modules/random/cog.py +++ b/cog_modules/random/cog.py @@ -10,6 +10,8 @@ from gizmopics import * from resources import gizmoResources +import pickle + load_dotenv() CATS = os.getenv("x-api-key") botDMs = int(os.getenv("DMChannel")) @@ -42,6 +44,8 @@ async def gizmo(self, ctx: commands.Context): info = f"Gizmo #{num + 1} of {len(gizmoPics)}." pic = gizmoPics[num] gizmoResources[pic] += 1 + with open('gizmoResources','wb') as f: + pickle.dump(gizmoResources, f) most_common = gizmoResources.most_common(1) if pic == most_common[0][0]: info += f" HammerBot's favorite Gizmo pic! Shown {most_common[0][1]} times." diff --git a/resources.py b/resources.py index faabbe3..ec18aa9 100644 --- a/resources.py +++ b/resources.py @@ -1,4 +1,5 @@ from collections import Counter +import pickle serverResources = { "quela": {"Food": "-1068", "Wood": "449", "Gold": "-826", "Stone": "-148"}, "bshammer": {"Food": "-463", "Wood": "-622", "Gold": "-388", "Stone": "1093"}, @@ -6,4 +7,8 @@ "olaf_the_shrew": {"Food": "323", "Wood": "0", "Gold": "0", "Stone": "0"}, ".harristotle": {"Food": "-1448", "Wood": "560", "Gold": "0", "Stone": "-706"}, } -gizmoResources = Counter() +try: + with open('gizmoResources','rb') as f: + gizmoResources = pickle.load(f) +except FileNotFoundError: + gizmoResources = Counter()