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 00620d9..2afc168 100644 --- a/resources.py +++ b/resources.py @@ -1,5 +1,5 @@ from collections import Counter - +import pickle serverResources = { "quela": {"Food": "-1068", "Wood": "449", "Gold": "-826", "Stone": "12"}, "bshammer": {"Food": "-1250", "Wood": "-622", "Gold": "-850", "Stone": "1942"}, @@ -7,5 +7,8 @@ "olaf_the_shrew": {"Food": "323", "Wood": "0", "Gold": "0", "Stone": "0"}, ".harristotle": {"Food": "-2241", "Wood": "560", "Gold": "-986", "Stone": "-706"}, } - -gizmoResources = Counter() +try: + with open('gizmoResources','rb') as f: + gizmoResources = pickle.load(f) +except FileNotFoundError: + gizmoResources = Counter()