diff --git a/cog_modules/random/cog.py b/cog_modules/random/cog.py index ca91737..3427a56 100644 --- a/cog_modules/random/cog.py +++ b/cog_modules/random/cog.py @@ -10,7 +10,7 @@ from dotenv import load_dotenv from gizmopics import * -from resources import gizmoResources, taoResources, zookieResources +from resources import gizmoResources, taoResources, zookieResources, gadgetResources load_dotenv() CATS = os.getenv("x-api-key") @@ -115,6 +115,32 @@ async def zookie_error(self, ctx, error): f"Zookie likes to hide, so you can only view him once every 30 seconds. Try again in {round(error.retry_after, 2)} seconds." ) + @commands.command(name="!gadget") + @commands.cooldown(1, 30, commands.BucketType.user) + async def gadget(self, ctx: commands.Context): + num = random.randint(0, len(gadgetPics) - 1) + info = f"Gadget #{num + 1} of {len(gadgetPics)}." + pic = gadgetPics[num] + gadgetResources[pic] += 1 + with open("gadgetResources", "wb") as f: + pickle.dump(gadgetResources, f) + most_common = gadgetResources.most_common(2) + if len(gadgetResources) >= 2 and most_common[0][1] != most_common[1][1] and pic == most_common[0][0]: + info += f" HammerBot's favorite Gadget pic! Shown {most_common[0][1]} times." + elif gadgetResources[pic] == 1: + info += " First time shown! ^_^" + else: + info += f" Shown {gadgetResources[pic]} times." + await ctx.send(info) + await ctx.send(pic) + + @gadget.error + async def gadget_error(self, ctx, error): + if isinstance(error, commands.CommandOnCooldown): + await ctx.send( + f"Gadget likes to hide, so you can only view him once every 30 seconds. Try again in {round(error.retry_after, 2)} seconds." + ) + @commands.command(name="?gizmo", aliases=["?tao"]) @commands.cooldown(1, 30, commands.BucketType.user) async def gizmo_or_tao(self, ctx: commands.Context): diff --git a/gizmopics.py b/gizmopics.py index fa50ebb..67ad1e8 100644 --- a/gizmopics.py +++ b/gizmopics.py @@ -573,3 +573,6 @@ "https://cdn.discordapp.com/attachments/1310771971419803668/1310772596937064488/IMG_5084.jpg?ex=674869dc&is=6747185c&hm=6af989ff24a9ada8146988bbc9aa6d181c0f196bbdb16b394c7528a5d59c5b63&", "https://cdn.discordapp.com/attachments/1310771971419803668/1310772591518285835/560B1820-E454-411D-8449-7B5BAC079E57.jpg?ex=674869da&is=6747185a&hm=a980f700243a91110e313c59a8e2100d97e212bf2c4f364d49463ea6ba8f07a0&", ] + +gadgetPics = [ +] diff --git a/resources.py b/resources.py index 06b3dda..9563248 100644 --- a/resources.py +++ b/resources.py @@ -30,3 +30,9 @@ zookieResources = pickle.load(f) except FileNotFoundError: zookieResources = Counter() + +try: + with open("gadgetResources", "rb") as f: + gadgetResources = pickle.load(f) +except FileNotFoundError: + gadgetResources = Counter()