async def predicate(ctx): ranks = fldb.getUserInfo(f"{ctx.message.author.id}", "PermIDs") if perm_set in ranks and ranks[perm_set] in acceptable_rank: return True elif "GBL" in ranks and ranks["GBL"] in acceptable_rank: return True else: raise commands.MissingPermissions(acceptable_rank)
async def setrank(self, ctx, user:discord.User, new_points:int): embed = discord.Embed( color = discord.Color.blue(), title = "User Points Updater", description = "Please confirm that the following information is correct: ", timestamp = datetime.utcnow() ) embed.set_footer(text=f"This prompt will expire in 15 seconds \n{ctx.message.author} | Failed Labs Central Command", icon_url=f"{ctx.message.author.avatar_url}") user_info = fldb.getUserInfo(user.id) embed.add_field(name="User to Update", value=f"**Discord:** {user.mention}\n**Roblox:** [{user_info['RobloxUName']}](https://roblox.com/users/profile?username={user_info['RobloxUName']})") embed.add_field(name="Old Points", value=f"{user_info['Points']}", inline=False) embed.add_field(name="New Points", value=f"{new_points}", inline=False) message = await ctx.send(embed=embed) await message.add_reaction(emoji="✅") await message.add_reaction(emoji="❌") def checkReactions(reaction, user): return user == ctx.message.author and str(reaction.emoji) in ["✅", "❌"] try: reaction, user = await self.bot.wait_for("reaction_add", timeout=15, check=checkReactions) except asyncio.TimeoutError as e: pass else: await message.clear_reactions() if str(reaction.emoji) == "✅": embed = discord.Embed( color = discord.Color.orange(), title = "User Points Updater", description = "Confirmed. Updating...", timestamp = datetime.utcnow() ) embed.set_footer(text="Failed Labs Central Command") await message.edit(embed=embed) else: embed = discord.Embed( color = discord.Color.dark_red(), title = "User Points Updater", description = "Point change cancelled. No changes have been made.", timestamp = datetime.utcnow() )
async def rank(self, ctx): author = ctx.message.author await write_log( f"[Rank Management]: Loading Rank Info for DiscordUID '{author.id}'" ) user_data = fldb.getUserInfo(f"{author.id}") if user_data != "Error" and user_data != {}: ranks_and_perms = json.load(open("./files/ranksandperms.json", "r")) await write_log( f"[Rank Management]: Getting Roblox Avatar Headshort for DiscordUID '{author.id}'" ) async with aiohttp.ClientSession() as session: async with session.get( f"https://thumbnails.roblox.com/v1/users/avatar-headshot?userIds={user_data['RobloxUID']}&size=720x720&format=Png&isCircular=false" ) as response: if response.status == 200: data = json.loads(await response.text()) global avatar_thumbnail_url avatar_thumbnail_url = data["data"][0]["imageUrl"] ranks = ranks_and_perms["Ranks"] perms = ranks_and_perms["Permissions"] fl_ranks, fl_perms, sd_ranks, sd_perms = ranks["FL"], perms[ "FL"], ranks["SD"], perms["SD"] current_ranks = user_data["RankIDs"] current_perms = user_data["PermIDs"] current_fl_rank = "Not Ranked" current_sd_rank = "Not Ranked" current_fl_perm = "Not Applicable" current_sd_perm = "Not Applicable" if "FL" in current_ranks: current_fl_rank = fl_ranks[current_ranks["FL"]]["Name"] if "SD" in current_ranks: current_sd_rank = sd_ranks[current_ranks["SD"]]["Name"] if "GBL" in current_perms: current_fl_perm = fl_perms[current_perms["GBL"]] current_sd_perm = sd_perms[current_perms["GBL"]] else: if "FL" in current_perms: current_fl_perm = fl_perms[current_perms["FL"]] if "SD" in current_perms: current_sd_perm = fl_perms[current_perms["SD"]] desc = f"**Failed Labs Main Group** \n \ **Rank:** {current_fl_rank}\n \ **Permission Level:** {current_fl_perm} \n\n \ **Failed Labs Security Division** \n \ **Rank:** {current_sd_rank} \n \ **Permission Level:** {current_sd_perm}" if current_sd_rank != "Not Ranked": desc = desc + "\n\n**Security Division Rank Progress:**\n\n" + "" embed = discord.Embed(color=discord.Color.blue(), title=f'{user_data["RobloxUName"]} - Rank', description=desc, timestamp=datetime.utcnow()) embed.set_author(name=f"{author}", icon_url=f"{author.avatar_url}") embed.set_footer(text="Failed Labs Central Command") embed.set_thumbnail(url=f"{avatar_thumbnail_url}") #"**Rank Progress:**\n" + ":white_medium_square:"*int(user_data["Points"]) + await ctx.send(embed=embed) else: embed = discord.Embed(color=discord.Color.dark_red(), description="User Not Found", timestamp=datetime.utcnow()) embed.set_author(name=f"{author}", icon_url=f"{author.avatar_url}") embed.set_footer(text="Failed Labs Central Command") await ctx.send(embed=embed)
async def verify(self, ctx): table = dynamodb.Table("Failed_Labs_Users") author = ctx.message.author do_verify = True verified = False r_uid = "" r_uname = "" bot_verifier_used = False await write_log( f"[Verification]: Initiating verification for {ctx.message.author.name}" ) userData = fldb.getUserInfo(f"{author.id}", "RobloxUID") if userData != {}: await write_log( f"[Verification]: Verification for {ctx.message.author.name} failed: User already linked to a Roblox account." ) do_verify = False embed = discord.Embed( color=discord.Color.dark_red(), title="⚠️ Roblox Account Verification Error ⚠️", description= "You already have an account linked to your Discord profile!") embed.set_footer(text="Failed Labs Central Command") await ctx.send(embed=embed) if do_verify and str(ctx.channel.type) == "private": embed = discord.Embed( color=discord.Color.dark_red(), title="⚠️ Roblox Account Verification Error ⚠️", description= "Please start this command from a channel within a Failed Labs Discord Server." ) embed.set_footer(text="Failed Labs Central Command") await ctx.send(embed=embed) # This embed is sent in the 'await ctx.send(embed=embed)' found at the very end of this command do_verify = False verified = False if do_verify: await write_log( f"[Verification]: Attempting verification using Bloxlink") async with aiohttp.ClientSession() as session: async with session.get( f"https://api.blox.link/v1/user/{author.id}" ) as response: if response.status == 200: data = json.loads(await response.text()) if "error" not in data: r_uid = data["primaryAccount"] async with session.get( f"https://api.roblox.com/users/{r_uid}" ) as response: if response.status == 200: data = json.loads(await response.text()) r_uname = data["Username"] do_verify = False verified = True if do_verify: await write_log( f"[Verification]: Attempting verification using RoVer") async with aiohttp.ClientSession() as session: async with session.get( f"https://verify.eryn.io/api/user/{author.id}" ) as response: if response.status == 200: data = json.loads(await response.text()) if "error" not in data: r_uid = data["robloxId"] r_uname = data["robloxUsername"] do_verify = False verified = True if str(ctx.channel.type) != "private" and do_verify: embed = discord.Embed( color=discord.Color.blue(), title= ":globe_with_meridians: Roblox Account Verification :globe_with_meridians:", description=f"{ctx.message.author.mention} Check your DMs!") await ctx.send(embed=embed, delete_after=5) if do_verify: embed = discord.Embed( color=discord.Color.orange(), title= ":globe_with_meridians: Roblox Account Verification :globe_with_meridians:", description= "Please tell me the username of the Roblox account you'd like to verify." ) embed.set_footer( text= "This prompt will expire in 15 seconds. \nFailed Labs Central Command" ) await author.send(embed=embed) def checkAuthor(m): return m.author == ctx.message.author try: msg = await self.bot.wait_for("message", check=checkAuthor, timeout=15) except asyncio.TimeoutError as e: await write_log( f"[Verification]: Verification for {ctx.message.author.name} failed: Username prompt timed out." ) embed = discord.Embed( color=discord.Color.dark_red(), title="⚠️ Roblox Account Verification Error ⚠️", description= f"Prompt timed out. \nPlease try again or contact a staff member for more assistance." ) embed.set_footer(text="Failed Labs Central Command") await author.send(embed=embed) do_verify = False else: r_uname = msg.content async with aiohttp.ClientSession() as session: async with session.get( f"https://api.roblox.com/users/get-by-username?username={r_uname}" ) as response: if response.status == 200: data = json.loads(await response.text()) if "success" in data: embed = discord.Embed( color=discord.Color.dark_red(), title= "⚠️ Roblox Account Verification Error ⚠️", description= f"Roblox User `{r_uname}` Not Found. Please Try Again." ) embed.set_footer( text="Failed Labs Central Command") await ctx.send(embed=embed) await write_log( f"[Verification]: Verification for {ctx.message.author.name} failed: Unknown Roblox username." ) do_verify = False else: r_uid = data["Id"] if do_verify: bot_verifier_used = True auth_code = gen_verify_phrase() await write_log( f"[Verification]: Verification code for {ctx.message.author.name} to {r_uname}: {auth_code}." ) verify_by_status = discord.File(fp="./files/verifybystatus.png", filename="verifybystatus.png", spoiler=False) verify_by_profile = discord.File(fp="./files/verifybyprofile.png", filename="verifybyprofile.png", spoiler=False) embed = discord.Embed( color=discord.Color.orange(), title= ":globe_with_meridians: Roblox Account Verification :globe_with_meridians:", description= f"Hello {author.mention}!\n\nYou will be verifying the following Roblox account: ```{r_uname}```\nGo to https://www.roblox.com/feeds/ and paste this code into your **status**, or you can go to https://www.roblox.com/my/account and paste this code into your **profile**:" ) await author.send(embed=embed, files=[verify_by_status, verify_by_profile]) embed = discord.Embed(color=discord.Color.orange(), description=f"```{auth_code}```") await author.send(embed=embed) embed = discord.Embed( color=discord.Color.orange(), description= "Don't worry about telling me when you've finished. I'll check your status automatically and rank you if I find the code above.\n\nI will indicate to you that I am still checking your status by 'typing'. If I stop, the prompt has timed out and you will need to run the verify command again." ) embed.set_footer( text= "This prompt will expire in 60 seconds.\nFailed Labs Central Command" ) await author.send(embed=embed) do_verify = False check_status = True x = 0 async with author.typing(): while check_status and x <= 60: async with aiohttp.ClientSession() as session: async with session.get( f"https://users.roblox.com/v1/users/{r_uid}/status" ) as response: if response.status == 200: data = json.loads(await response.text()) if data["status"] == auth_code: check_status = False verified = True break await asyncio.sleep(0.5) async with session.get( f"https://users.roblox.com/v1/users/{r_uid}" ) as response: if response.status == 200: data = json.loads(await response.text()) description = data["description"] if description.find(auth_code) != -1: check_status = False verified = True break x = x + 1 await asyncio.sleep(0.5) if verified: await write_log( f"[Verification]: Verification for {ctx.message.author.name} to {r_uname} successful." ) embed = discord.Embed( color=discord.Color.green(), title= ":white_check_mark: Roblox Account Verification :white_check_mark:", description= f"Verification of Roblox User `{r_uname}` to {author.mention} Successful!" ) embed.set_footer(text="Failed Labs Central Command") try: await author.edit( nick=f"{r_uname}", reason= f"User successfully verified and linked to Roblox account with id {r_uid} and username {r_uname}" ) except discord.Forbidden as e: await write_log( f"[Verification]: Failed to change guild nickname of Discord User ID {author.id} to {r_uname}" ) else: pass try: response = table.get_item(Key={"DiscordUID": f"{author.id}"}) except ClientError as e: await write_log( f"[DynamoDB Access]: {e.response['Error']['Message']}") else: if "Item" in response: try: response = table.update_item( Key={"DiscordUID": f"{author.id}"}, UpdateExpression= "set RobloxUID=:ruid, RobloxUName=:run", ExpressionAttributeValues={ ":run": r_uname, ":ruid": str(r_uid) }) except ClientError as e: await write_log( f"[DynamoDB Access]: {e.response['Error']['Message']}" ) else: pass else: fldb.createNewUser( DiscordUID=f"{author.id}", DiscordUName=f"{author.name}", DiscordUDiscriminator=f"{author.discriminator}", RobloxUID=f"{r_uid}", RobloxUName=f"{r_uname}") await author.send(embed=embed) elif not verified and bot_verifier_used and not do_verify: await write_log( f"[Verification]: Verification for {ctx.message.author.name} to {r_uname} failed: Verification timed out." ) embed = discord.Embed( color=discord.Color.dark_red(), title=":x: Roblox Account Verification :x:", description= f"Verification of Roblox User `{r_uname}` to {author.mention} Failed.\nI couldn't find the code I gave you in your status.\n\nPlease try again or contact a staff member for more assistance." ) embed.set_footer(text="Failed Labs Central Command") await ctx.send(embed=embed)