async def lookup(self, ctx, *arg): arg = ' '.join(arg) self.conn = database.connect_to_db() # Token-based search check if token_regex.match(arg): match_type = 'token' db_result = database.get_user_by_thm_token(self.conn, arg) else: # ID-based search checks if mention_regex.match(arg): match_type = 'mention' user_id = mention_regex.search(arg).group(1) elif user_id_regex.match(arg): match_type = 'user id' user_id = arg elif user_discrim_regex.match(arg): match_type = 'user#discrim' user = self.bot.get_guild(id_guild).get_member_named(arg) if user is None: return await ctx.send( f"Failed to find a user with that discriminator") user_id = user.id else: return await ctx.send(s_lookup["match_failed"]) try: db_result = database.get_user_by_discord_uid( self.conn, user_id) except: return await ctx.send(s_lookup["db_fetch_failed"]) # Loops over the results (also handles multiple-row results if they occur) for row in db_result: u_id, u_token = row try: thm_user = get_user_by_token(u_token) except: return await ctx.send(s_lookup["thm_fetch_failed"]) response = officialEmbed("Token match", footer=f"Matched with {match_type}") response.add_field(name="Discord mention", value=f"<@{u_id}>") response.add_field(name="Discord ID", value=u_id) response.add_field(name="THM username", value=thm_user["username"]) response.add_field(name="THM profile", value=thm_user_link.format( thm_user["username"])) response.add_field(name="THM token", value=u_token) await ctx.send(embed=response) if len(db_result) == 0: await ctx.send("No results.")
async def rank_from_id(self, ctx, id): """Retrieve a user's rank from his ID.""" db = database.connect_to_db() request = database.get_user_by_discord_uid(db, id) if len(request) == 0: response = officialEmbed("Rank", s_userrank["user_not_found"], color=0xdc143c) userImg = config.get_config("info")["icon"] response.set_thumbnail(url=userImg) await ctx.send(embed=response) else: user_token = request[0][1] data = await api_fetch(c_api_token, user_token) user = data["username"] await self.send_rank(ctx, user)
def __init__(self, bot): self.bot = bot self.conn = database.connect_to_db()
################### id_guild = config.get_config("server") roles = config.get_config("roles") id_admin = roles["admin"] id_mod = roles["mod"] id_ranks = roles["ranks"] id_sub = roles["sub"] id_contrib = roles["contrib"] id_verified = roles["verified"] id_bughunter = roles["bughunter"] id_lucky = roles["lucky"] # DB db = database.connect_to_db() ############# # Functions # ############# # Role managment. async def remove_rank_roles(member): """Remove the member's rank/level roles.""" for rId in id_ranks: if has_role(member, rId): await member.remove_roles(get(member.guild.roles, id=rId))