From f41798184c9eabb8ed14204b1139185b2766d9c6 Mon Sep 17 00:00:00 2001 From: tropii <97747461+TropiiDev@users.noreply.github.com> Date: Fri, 24 Nov 2023 23:38:02 -0500 Subject: [PATCH] Final Store Commit --- bot.py | 3 +- commands/store.py | 171 +++++++++++++++++++++------------------------- 2 files changed, 78 insertions(+), 96 deletions(-) diff --git a/bot.py b/bot.py index 097408d..208e262 100644 --- a/bot.py +++ b/bot.py @@ -1,4 +1,4 @@ -from commands import help, ticket +from commands import help, ticket, store # pip install imports import discord, aiofiles @@ -55,6 +55,7 @@ class MyBot(commands.Bot): self.add_view(ticket.CreateButton()) self.add_view(ticket.CloseButton()) self.add_view(ticket.TrashButton()) + self.add_view(store.SelectView()) print(f'\33[32mLogged in as {self.user} (ID: {self.user.id})') print('------') diff --git a/commands/store.py b/commands/store.py index 801db41..4aba05f 100644 --- a/commands/store.py +++ b/commands/store.py @@ -84,105 +84,87 @@ class Select(discord.ui.Select): 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 + elif self.values[0] == "Gold Ticket": + 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 + elif self.values[0] == "Diamond Ticket": + 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 + elif self.values[0] == "Emerald Ticket": + 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 SelectView(discord.ui.View): def __init__(self): super().__init__(timeout=None) self.add_item(Select()) -class GoldButton(View): - def __init__(self): - super().__init__(timeout=None) - - @button(label="Buy Gold", style=discord.ButtonStyle.blurple, custom_id="gold") - async def gold(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 diamond(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): self.bot = bot @@ -192,9 +174,8 @@ class store(commands.Cog): print('Tickets Online') @commands.hybrid_command(name="store", description="View the store") - @commands.has_permissions(administrator=True) @commands.check(is_enabled) - async def ticket(self, ctx): + async def store(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)