From 2771800bbdee8c48b2efa4c7d5cbc43856320733 Mon Sep 17 00:00:00 2001 From: tropii <97747461+TropiiDev@users.noreply.github.com> Date: Fri, 24 Nov 2023 21:58:35 -0500 Subject: [PATCH] Finished Store --- commands/economy.py | 1 - commands/store.py | 142 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 137 insertions(+), 6 deletions(-) diff --git a/commands/economy.py b/commands/economy.py index 50d35ab..70b0da4 100644 --- a/commands/economy.py +++ b/commands/economy.py @@ -28,7 +28,6 @@ class economy(commands.Cog): await ctx.send(f"{ctx.author.mention} begged for money and got {num} bloboons!") @commands.hybrid_command(name="balance", description="Check your balance", aliases=["bal"]) - @commands.cooldown(1, 60, commands.BucketType.user) async def balance(self, ctx, member:discord.Member = None): client = pymongo.MongoClient(os.getenv("mongo_url")) db = client.servers diff --git a/commands/store.py b/commands/store.py index 574b92d..0a3360e 100644 --- a/commands/store.py +++ b/commands/store.py @@ -52,6 +52,130 @@ class BronzeButton(View): coll.update_one({"_id": {"author_id": user.id, "guild_id": guild.id}}, {"$set": {"bought": "bronze"}}) await interaction.followup.send("You bought the bronze ticket! Redeem it in the Blob support server for rewards!", ephemeral=True) return + +class SilverButton(View): + def __init__(self): + super().__init__(timeout=None) + + @button(label="Buy Silver", style=discord.ButtonStyle.blurple, custom_id="silver") + async def bronze(self, interaction: discord.Interaction, button: Button): + await interaction.response.defer(ephemeral=True) + client = pymongo.MongoClient(os.getenv("mongo_url")) + db = client.servers + coll = db.economy + + cost = 200 + guild = interaction.guild + user = interaction.user + + userColl = coll.find_one({"_id": {'author_id': user.id, 'guild_id': guild.id}}) + + if not userColl: + await interaction.followup.send("You don't have any coins!", ephemeral=True) + return + + if userColl["coins"] < cost: + await interaction.followup.send("You don't have enough coins!", ephemeral=True) + return + + if userColl["coins"] >= cost: + coll.update_one({"_id": {'author_id': user.id, 'guild_id': guild.id}}, {"$inc":{"coins":-cost}}) + coll.update_one({"_id": {"author_id": user.id, "guild_id": guild.id}}, {"$set": {"bought": "silver"}}) + await interaction.followup.send("You bought the silver ticket! Redeem it in the Blob support server for rewards!", ephemeral=True) + return + +class GoldButton(View): + def __init__(self): + super().__init__(timeout=None) + + @button(label="Buy Gold", style=discord.ButtonStyle.blurple, custom_id="gold") + async def bronze(self, interaction: discord.Interaction, button: Button): + await interaction.response.defer(ephemeral=True) + client = pymongo.MongoClient(os.getenv("mongo_url")) + db = client.servers + coll = db.economy + + cost = 400 + guild = interaction.guild + user = interaction.user + + userColl = coll.find_one({"_id": {'author_id': user.id, 'guild_id': guild.id}}) + + if not userColl: + await interaction.followup.send("You don't have any coins!", ephemeral=True) + return + + if userColl["coins"] < cost: + await interaction.followup.send("You don't have enough coins!", ephemeral=True) + return + + if userColl["coins"] >= cost: + coll.update_one({"_id": {'author_id': user.id, 'guild_id': guild.id}}, {"$inc":{"coins":-cost}}) + coll.update_one({"_id": {"author_id": user.id, "guild_id": guild.id}}, {"$set": {"bought": "gold"}}) + await interaction.followup.send("You bought the gold ticket! Redeem it in the Blob support server for rewards!", ephemeral=True) + return + +class DiamondButton(View): + def __init__(self): + super().__init__(timeout=None) + + @button(label="Buy Diamond", style=discord.ButtonStyle.blurple, custom_id="diamond") + async def bronze(self, interaction: discord.Interaction, button: Button): + await interaction.response.defer(ephemeral=True) + client = pymongo.MongoClient(os.getenv("mongo_url")) + db = client.servers + coll = db.economy + + cost = 800 + guild = interaction.guild + user = interaction.user + + userColl = coll.find_one({"_id": {'author_id': user.id, 'guild_id': guild.id}}) + + if not userColl: + await interaction.followup.send("You don't have any coins!", ephemeral=True) + return + + if userColl["coins"] < cost: + await interaction.followup.send("You don't have enough coins!", ephemeral=True) + return + + if userColl["coins"] >= cost: + coll.update_one({"_id": {'author_id': user.id, 'guild_id': guild.id}}, {"$inc":{"coins":-cost}}) + coll.update_one({"_id": {"author_id": user.id, "guild_id": guild.id}}, {"$set": {"bought": "diamond"}}) + await interaction.followup.send("You bought the diamond ticket! Redeem it in the Blob support server for rewards!", ephemeral=True) + return + +class EmeraldButton(View): + def __init__(self): + super().__init__(timeout=None) + + @button(label="Buy Emerald", style=discord.ButtonStyle.blurple, custom_id="emerald") + async def bronze(self, interaction: discord.Interaction, button: Button): + await interaction.response.defer(ephemeral=True) + client = pymongo.MongoClient(os.getenv("mongo_url")) + db = client.servers + coll = db.economy + + cost = 1600 + guild = interaction.guild + user = interaction.user + + userColl = coll.find_one({"_id": {'author_id': user.id, 'guild_id': guild.id}}) + + if not userColl: + await interaction.followup.send("You don't have any coins!", ephemeral=True) + return + + if userColl["coins"] < cost: + await interaction.followup.send("You don't have enough coins!", ephemeral=True) + return + + if userColl["coins"] >= cost: + coll.update_one({"_id": {'author_id': user.id, 'guild_id': guild.id}}, {"$inc":{"coins":-cost}}) + coll.update_one({"_id": {"author_id": user.id, "guild_id": guild.id}}, {"$set": {"bought": "emerald"}}) + await interaction.followup.send("You bought the emerald ticket! Redeem it in the Blob support server for rewards!", ephemeral=True) + return class store(commands.Cog): def __init__(self, bot): @@ -65,12 +189,20 @@ class store(commands.Cog): @commands.has_permissions(administrator=True) @commands.check(is_enabled) async def ticket(self, ctx): + em = discord.Embed(title="Shop!", description="Spend some Bloboons to get cool rewards! Redeem in supported servers!", color=ctx.author.color) + em.add_field(name="Bronze Ticket", value="100 Bloboons", inline=False) + em.add_field(name="Silver Ticket", value="200 Bloboons", inline=False) + em.add_field(name="Gold Ticket", value="400 Bloboons", inline=False) + em.add_field(name="Diamond Ticket", value="800 Bloboons", inline=False) + em.add_field(name="Emerald Ticket", value="1600 Bloboons", inline=False) + await ctx.send( - embed=discord.Embed( - description="Shop!", - color=ctx.author.color - ), - view=BronzeButton() + embed=em, + view=BronzeButton(), + view=SilverButton(), + view=GoldButton(), + view=DiamondButton(), + view=EmeraldButton() ) async def setup(bot):