diff --git a/commands/force_player_verify.py b/commands/force_player_verify.py index 84315ee..cddfe87 100644 --- a/commands/force_player_verify.py +++ b/commands/force_player_verify.py @@ -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): @@ -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}" @@ -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"]: @@ -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: diff --git a/commands/unverify.py b/commands/unverify.py index 4de0ab8..54615d1 100644 --- a/commands/unverify.py +++ b/commands/unverify.py @@ -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: @@ -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) diff --git a/commands/verify.py b/commands/verify.py index 579d6ce..3405620 100644 --- a/commands/verify.py +++ b/commands/verify.py @@ -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): @@ -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: @@ -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 @@ -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:" @@ -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) @@ -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/",