Skip to content

Commit

Permalink
More stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lightninq720 committed Aug 28, 2023
1 parent 8119a0f commit e4bcfec
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 18 deletions.
6 changes: 3 additions & 3 deletions cogs/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
31 changes: 26 additions & 5 deletions cogs/premium.py
Original file line number Diff line number Diff line change
@@ -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))
2 changes: 2 additions & 0 deletions e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
e = "dhasgdy"
print(e.split(","))
4 changes: 2 additions & 2 deletions utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 15 additions & 8 deletions views/dashboard_views.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
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)
5 changes: 5 additions & 0 deletions views/role_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit e4bcfec

Please sign in to comment.