diff --git a/cogs/dashboard.py b/cogs/dashboard.py index 5e11d6a..b82cc6c 100644 --- a/cogs/dashboard.py +++ b/cogs/dashboard.py @@ -11,15 +11,15 @@ def __init__(self, client: commands.Bot): @nextcord.slash_command(name=f"dashboard", description=f"Configure the bot on the in-discord dashboard") async def dashboard(self, interaction: Interaction): - conn = pymysql.connect(host=self.DBENDPOINT, port=3306, user=self.DBUSER, password=self.DBPASS, db=self.DBNAME) + conn = pymysql.connect(host=DBENDPOINT, port=3306, user=DBUSER, password=DBPASS, db=DBNAME) cur = conn.cursor() cur.execute(f"SELECT * FROM guild_configs WHERE id='{interaction.guild.id}'") data = cur.fetchall() if not data: cur.execute(f"INSERT INTO guild_configs (id) VALUES ('{interaction.guild.id}')") conn.commit() - embed = nextcord.Embed(title=f"Verification Dashboard", description=f"""Verified Role: {('<@' + data[0][1] + '>') if data[0][1] else 'Not Set'}""") - view = DashboardButtons(premium=check_premium(guild = True, user = False, type_id=interaction.guild.id)) + embed = nextcord.Embed(title=f"Verification Dashboard", description=f"""Verified Role: {(",".join([('<@&' + i + '> ') for i in data[0][1].split(",")])) if data[0][1] else 'Not Set'}""") + view = DashboardButtons(premium=check_premium(self, guild = True, user = False, type_id=interaction.guild.id)) await interaction.send(embed=embed, view=view) def setup(client: commands.Bot): diff --git a/cogs/premium.py b/cogs/premium.py index 50a57ec..7d3d208 100644 --- a/cogs/premium.py +++ b/cogs/premium.py @@ -1,26 +1,47 @@ import nextcord +import pymysql from nextcord.ext import commands from nextcord import Interaction, SlashOption -from utils import check_premium, create_error_embed, PREMIUMLINK +from utils import check_premium, create_error_embed, create_warning_embed, PREMIUMLINK, DBENDPOINT, DBUSER, DBPASS, DBNAME class Premium(commands.Cog): def __init__(self, client: commands.Bot): self.client = client - @nextcord.slash_commands(name=f"manage-premium", description=f"Manage your premium membership") + @nextcord.slash_command(name=f"manage-premium", description=f"Manage your premium membership", guild_ids=[1111387758028652657, 801744339343507457]) async def manage_premium(self, interaction: Interaction): pass - @manage_premium(name=f"add-server", description=f"Add a server to your premium subscription") + @manage_premium.subcommand(name=f"add-server", description=f"Add a server to your premium subscription") async def manage_premium_add_server(self, interaction: Interaction, guildid: str = SlashOption( name=f"guild", - description=f"The ID of the guild you want to add to your premium subscription. Use /debug in your server to get the server ID", + description=f"The ID of the guild to add to premium. Use /debug in your server to get this.", required = True )): await interaction.response.defer() - if not check_premium(interaction.user.id): + if not check_premium(False, True, interaction.user.id): await interaction.send(embed=create_error_embed(title=f"No premium subscription", description=f"You are not currently subscribed to any of our premium subscriptions. To purchase premium please follow [this link]({PREMIUMLINK})\n\n\nPlease Note: If you recently subscribed to premium it may take up to 30 minutes to register your subscription. If you are still unable to use this command in 30 minutes, please create a ticket in ")) + return + + if check_premium(True, False, guildid): + await interaction.send(embed=create_warning_embed(title=f"Guild already added", description=f"This guild is already added to your premium subscription.")) + return + + conn = pymysql.connect(host=DBENDPOINT, port=3306, user=DBUSER, password=DBPASS, db=DBNAME) + cur = conn.cursor() + cur.execute("SELECT * FROM sv_premium_users WHERE user_id = %s", (interaction.user.id)) + data = cur.fetchall() + + servers_available = int(data[0][1]) + + cur.execute("SELECT * FROM sv_premium_guilds WHERE user_id = %s", (interaction.user.id)) + data = cur.fetchall() + + servers_used = len(data) if data else 0 + + + def setup(client: commands.Bot): client.add_cog(Premium(client)) \ No newline at end of file diff --git a/e.py b/e.py new file mode 100644 index 0000000..3f4f686 --- /dev/null +++ b/e.py @@ -0,0 +1,2 @@ +e = "dhasgdy" +print(e.split(",")) \ No newline at end of file diff --git a/utils/utils.py b/utils/utils.py index 71e4c41..c2c104c 100644 --- a/utils/utils.py +++ b/utils/utils.py @@ -21,11 +21,11 @@ def check_premium(self, guild: bool, user: bool, type_id: str): conn = pymysql.connect(host=DBENDPOINT, port=3306, user=DBUSER, password=DBPASS, db=DBNAME) cur = conn.cursor() if guild: - cur.execute(f"SELECT * FROM sv_premium_guilds WHERE id='{type_id}'") + cur.execute(f"SELECT * FROM sv_premium_guilds WHERE guild_id='{type_id}'") data = cur.fetchall() return True if data else False elif user: - cur.execute(f"SELECT * FROM sv_premium_users WHERE id='{type_id}'") + cur.execute(f"SELECT * FROM sv_premium_users WHERE user_id='{type_id}'") data = cur.fetchall() return True if data else False return None diff --git a/views/dashboard_views.py b/views/dashboard_views.py index d96806c..9285129 100644 --- a/views/dashboard_views.py +++ b/views/dashboard_views.py @@ -1,5 +1,5 @@ import nextcord, pymysql -from utils import DBENDPOINT, DBNAME, DBPASS, DBUSER, COLOUR_MAIN, create_error_embed, DISCORDLINK +from utils import DBENDPOINT, DBNAME, DBPASS, DBUSER, COLOUR_MAIN, create_error_embed, DISCORDLINK, create_success_embed, PREMIUMLINK from nextcord import Interaction from .role_select import RoleSelect @@ -8,26 +8,33 @@ def __init__(self, premium: bool = False): super().__init__(timeout=300) self.premium = premium - @nextcord.ui.Button(label="Set Verification Roles", style=nextcord.ButtonStyle.blurple, disabled=False) - async def set_verification_role(self, interaction: Interaction, button: nextcord.ui.Button): + @nextcord.ui.button(label="Set Verification Roles", style=nextcord.ButtonStyle.blurple, disabled=False) + async def set_verification_role(self, button: nextcord.ui.Button, interaction: Interaction): await interaction.response.defer(with_message=True, ephemeral=True) if self.premium: rselect = RoleSelect(minvalue=1, maxvalue=10, text="Select Verification Roles") - embed = nextcord.Embed(title="Select Verification Roles", description="Select the role you want members to recieve when they verify. \nAs a [premium]({PREMIUMLINK}) user you can select up to `10` roles!", color=COLOUR_MAIN) + embed = nextcord.Embed(title="Select Verification Roles", description=f"Select the role you want members to recieve when they verify. \nAs a [premium]({PREMIUMLINK}) user you can select up to `10` roles!", color=COLOUR_MAIN) else: rselect = RoleSelect(minvalue=1, maxvalue=1, text="Select Verification Roles") - embed = nextcord.Embed(title="Select Verification Roles", description="Select the role you want members to recieve when they verify. \nAs a standard user you can select `1` role. \nUpgrade to [premium]({PREMIUMLINK}) to be able to select up to `10` roles!", color=COLOUR_MAIN) + embed = nextcord.Embed(title="Select Verification Roles", description=f"Select the role you want members to recieve when they verify. \nAs a standard user you can select `1` role. \nUpgrade to [premium]({PREMIUMLINK}) to be able to select up to `10` roles!", color=COLOUR_MAIN) msg = await interaction.send(embed=embed, view=rselect, ephemeral=True) await rselect.wait() - conn = pymysql.connect(host=self.DBENDPOINT, port=3306, user=self.DBUSER, password=self.DBPASS, db=self.DBNAME) + conn = pymysql.connect(host=DBENDPOINT, port=3306, user=DBUSER, password=DBPASS, db=DBNAME) cur = conn.cursor() cur.execute(f"SELECT * FROM guild_configs WHERE id='{interaction.guild.id}'") data = cur.fetchall() if not data: await msg.edit(embed=create_error_embed(title="Error!", description=f"Failed to fetch your guild data, please report this in our [Support Server]({DISCORDLINK})"), view=None) + conn.commit() self.stop() return - for role in rselect.values: - ",".join(role.id) \ No newline at end of file + ids = ",".join([str(role.id) for role in rselect.values]) + + cur.execute(f"UPDATE `guild_configs` SET verifyrole = '{ids}' WHERE id='{interaction.guild.id}'") + conn.commit() + + embed = nextcord.Embed(title=f"Verification Dashboard", description=f"""Verified Role: {",".join([('<@&' + i + '> ') for i in ids.split(",")]) if ids else 'Not Set'}""") + await interaction.message.edit(embed=embed) + await msg.edit(embed=create_success_embed(title="Success", description="Successfully updated verification roles."), view=None) \ No newline at end of file diff --git a/views/role_select.py b/views/role_select.py index d893369..92ac0d5 100644 --- a/views/role_select.py +++ b/views/role_select.py @@ -16,3 +16,8 @@ def __init__(self, minvalue=1, maxvalue=1, text="Select a role"): super().__init__() self.add_item(RoleSelectDropdown(minvalue=minvalue, maxvalue=maxvalue, text=text)) self.values = [] + + @nextcord.ui.button(label="Remove Roles", style=nextcord.ButtonStyle.red, disabled=False) + async def remove(self, button: nextcord.ui.Button, interaction: Interaction): + self.stop() + \ No newline at end of file