Skip to content

Commit

Permalink
Updated verification, unverify, and force verify. Fixed bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinTrinh1227 committed Nov 2, 2023
1 parent 73db9ea commit 7c0c4c8
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 14 deletions.
16 changes: 13 additions & 3 deletions commands/force_player_verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
font_title = ImageFont.truetype("./assets/fonts/Minecraft.ttf", 16)
font_footer = ImageFont.truetype("./assets/fonts/Minecraft.ttf", 13)
hypixel_guild_id = data["hypixel_ids"]["guild_id"]

verification_template = data["embed_templates"]["verification_nickname"]

class forceVerify(commands.Cog):
def __init__(self, client):
Expand Down Expand Up @@ -93,7 +95,11 @@ async def forceverify(self, ctx, user: discord.Member, username: str):

#other bedwars stats
bedwars_level = hydata["player"]["achievements"]["bedwars_level"] #bedwars level
new_nickname = f"[v] {ign}"

# default for users not in the server guild
new_nickname = verification_template["verified_non_guild_member"].format(
ign = ign
)

#user guild information
guild_url = f"https://api.hypixel.net/guild?player={uuid}&key={hypixel_api_key}"
Expand All @@ -107,7 +113,7 @@ async def forceverify(self, ctx, user: discord.Member, username: str):
for member in guild_data["guild"]["members"]:
if member.get("uuid") == uuid:
member_data = member
user_rank = member_data.get("rank")
user_rank = member_data.get("rank") # guild rank/role
# print(user_rank)

if "name" in guild_data["guild"]:
Expand All @@ -116,7 +122,11 @@ async def forceverify(self, ctx, user: discord.Member, username: str):

if guild_id == hypixel_guild_id:
# print("This user is in your guild!")
new_nickname = f"{user_rank} | {ign} ✔"

new_nickname = verification_template["verified_guild_member"].format(
ign = ign,
guild_rank = user_rank
)
await user.add_roles(verified_linked_role) # gives user guild role

else:
Expand Down
6 changes: 5 additions & 1 deletion commands/unverify.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self, client):
self.client = client

@commands.hybrid_command(aliases=["unlink", "unconnect"], brief="unverify", description="unsync your minecraft account", with_app_command=True)
@commands.cooldown(1, 600, commands.BucketType.user) # 10 min cool down.
async def unverify(self, ctx):
member = ctx.message.author
with open('verified_accounts.json', 'r') as f:
Expand Down Expand Up @@ -60,7 +61,10 @@ async def unverify(self, ctx):
embed.set_footer(text=f"©️ {ctx.guild.name}", icon_url = ctx.guild.icon.url)

await ctx.author.add_roles(unverified_role) #give the unverified role
await member.edit(nick=None) # This line will reset the user's nickname
try:
await member.edit(nick=None) # This line will reset the user's nickname
except:
await ctx.send("Unlinking was a success, but the bot could not change the user's nickname. This means the user is the server owner, or they have a higher role priority than the bot.")
await ctx.send(embed=embed)


Expand Down
56 changes: 46 additions & 10 deletions commands/verify.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
verified_role_id = int(data["role_ids"]["verified_member"])
font_title = ImageFont.truetype("./assets/fonts/Minecraft.ttf", 16)
font_footer = ImageFont.truetype("./assets/fonts/Minecraft.ttf", 13)

hypixel_guild_id = data["hypixel_ids"]["guild_id"]
verification_template = data["embed_templates"]["verification_nickname"]


class verify_mcaccount(commands.Cog):
Expand All @@ -35,6 +38,7 @@ async def save_data(self):

#bedwars stats command
@commands.hybrid_command(aliases=["sync", "connect", "link"], brief="verify [Minecraft User Name]",description="sync/verify your minecraft account", with_app_command=True)
@commands.cooldown(1, 20, commands.BucketType.user) # 20 sec cool down.
async def verify(self, ctx, *, username):

try:
Expand Down Expand Up @@ -85,25 +89,51 @@ async def verify(self, ctx, *, username):

#other bedwars stats
bedwars_level = hydata["player"]["achievements"]["bedwars_level"] #bedwars level
new_nickname = ign

# default for users not in the server guild
new_nickname = verification_template["verified_non_guild_member"].format(
ign = ign
)

#user guild information
guild_url = f"https://api.hypixel.net/guild?player={uuid}&key={hypixel_api_key}"
guild_response = requests.get(guild_url)
guild_data = guild_response.json()

unverified_role = discord.utils.get(ctx.guild.roles, id=unverified_role_id) #default role id
verified_linked_role = discord.utils.get(ctx.guild.roles, id=verified_role_id) #verified role id

#checks if user is in a guild
try:
for member in guild_data["guild"]["members"]:
if member.get("uuid") == uuid:
member_data = member
user_rank = member_data.get("rank") # guild rank/role
# print(user_rank)

if "name" in guild_data["guild"]:
guild_name = guild_data["guild"]["name"]
guild_id = guild_data["guild"]["_id"]

if guild_id == hypixel_guild_id:
# print("This user is in your guild!")

new_nickname = verification_template["verified_guild_member"].format(
ign = ign,
guild_rank = user_rank
)
await ctx.author.add_roles(verified_linked_role) # gives user guild role

else:
pass
#print("Player is not in your guild!")


else:
guild_name = "Not in Guild"
except: #runs if player is not in a guild
except Exception as error:
guild_name = "No Guild"


unverified_role = discord.utils.get(ctx.guild.roles, id=unverified_role_id) #default role id
verified_linked_role = discord.utils.get(ctx.guild.roles, id=verified_role_id) #verified role id
#print("An error occurred:", error) # An error occurred: name 'x' is not defined


#check if the user even has social media activated
Expand Down Expand Up @@ -150,11 +180,11 @@ async def verify(self, ctx, *, username):


front_skin = front_skin.resize((151, 124))
background_image.paste(front_skin, (16, 68), front_skin)
background_image.paste(overlay_image, (0, 0), overlay_image)
background_image.paste(front_skin, (16, 68), front_skin)

text1 = "Verification Success"
text2 = f"{ctx.guild.name} | Hycord.net"
text2 = f"© {ctx.guild.name} | Hycord.net"
text3 = f"Username:"
text4 = f"Discord Tag:"
text5 = f"Guild:"
Expand Down Expand Up @@ -197,7 +227,10 @@ async def verify(self, ctx, *, username):
json.dump(self.data, f, indent=4)

#modifies user's roles and nickname
await ctx.author.edit(nick=f"{new_nickname} ✔")
try:
await ctx.author.edit(nick=new_nickname)
except:
await ctx.send("Verification was a success, but the bot could not change the user's nickname. This means the user is the server owner, or they have a higher role priority than the bot.")
await ctx.author.add_roles(verified_linked_role)
await ctx.author.remove_roles(unverified_role)
#await ctx.send(f"{ctx.author.mention}'s account is now linked and updated.", embed=embed)
Expand Down Expand Up @@ -243,7 +276,10 @@ async def verify(self, ctx, *, username):
embed.set_footer(text=f"©️ {ctx.guild.name}", icon_url = ctx.guild.icon.url)
await ctx.send(embed=embed)

except:
except Exception as e:
error_message = str(e)
print("ERROR:", error_message)

embed = discord.Embed(
title = f"User Does Not Exist",
url = f"https://mcchecker.net/",
Expand Down

0 comments on commit 7c0c4c8

Please sign in to comment.