From 758119d172f5bbffa628188dfdd19dc54a65b526 Mon Sep 17 00:00:00 2001 From: tropii <97747461+TropiiDev@users.noreply.github.com> Date: Fri, 24 Nov 2023 21:36:00 -0500 Subject: [PATCH] Store --- commands/economy.py | 4 ++- commands/store.py | 77 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 commands/store.py diff --git a/commands/economy.py b/commands/economy.py index 0523ca5..50d35ab 100644 --- a/commands/economy.py +++ b/commands/economy.py @@ -131,6 +131,8 @@ class economy(commands.Cog): @commands.hybrid_command(name="eleaderboard", description="View the leaderboard", aliases=["elb"]) @commands.cooldown(1, 60, commands.BucketType.user) async def eleaderboard(self, ctx): + await ctx.send("Command disabled") +""" client = pymongo.MongoClient(os.getenv("mongo_url")) db = client.servers coll = db.economy @@ -140,7 +142,7 @@ class economy(commands.Cog): for i in range(10): embed.add_field(name=f"{i+1}. {ctx.guild.get_member(users[i]['_id']['author_id']).display_name}", value=f"{users[i]['coins']} bloboons", inline=False) await ctx.send(embed=embed) - +""" async def setup(bot): await bot.add_cog(economy(bot)) \ No newline at end of file diff --git a/commands/store.py b/commands/store.py new file mode 100644 index 0000000..42cde0a --- /dev/null +++ b/commands/store.py @@ -0,0 +1,77 @@ +# LINKED WITH ECONOMY.PY +import discord, asyncio, pymongo, os +from discord.ext import commands +from dotenv import load_dotenv +from discord.ui import Button, button, View + +from dotenv import load_dotenv +load_dotenv() + +def is_enabled(self): + client = pymongo.MongoClient(os.getenv("mongo_url")) + db = client.servers + coll = db.settings + + if coll.find_one({"_id": {"guild_id": self.guild.id, "commands":"ticket"}}): + command = coll.find_one({"_id": {"guild_id": self.guild.id, "commands":"ticket"}}) + command_enabled = command["enabled"] # True or False + if command_enabled: + return True + else: + return False + else: + return True + +class BronzeButton(View): + def __init__(self): + super().__init__(timeout=None) + + @button(label="Buy Bronze", style=discord.ButtonStyle.blurple, custom_id="bronze") + 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 = 100 + guild = interaction.guild + user = interaction.user + + user = coll.find_one({"_id": {'author_id': user.id, 'guild_id': guild.id}}) + + if not user: + await interaction.followup.send("You don't have any coins!", ephemeral=True) + return + + if user["coins"] < cost: + await interaction.followup.send("You don't have enough coins!", ephemeral=True) + return + + if user["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": "bronze"}}) + await interaction.followup.send("You bought the bronze ticket! Redeem it in the Blob support server for rewards!", ephemeral=True) + return + +class store(commands.Cog): + def __init__(self, bot): + self.bot = bot + + @commands.Cog.listener() + async def on_ready(self): + print('Tickets Online') + + @commands.hybrid_command(name="ticket", description="Create a ticket") + @commands.has_permissions(administrator=True) + @commands.check(is_enabled) + async def ticket(self, ctx): + await ctx.send( + embed=discord.Embed( + description="Shop!", + color=ctx.author.color + ), + view=BronzeButton() + ) + +async def setup(bot): + await bot.add_cog(store(bot))