async def verify(self, ctx, user_token=None): # If not DM, clear the message so that the token isn't kept publicly. if not isinstance(ctx.channel, DMChannel): await ctx.message.delete() msg = await ctx.send(s_verify["error_not_dm"]) time.sleep(15) await msg.delete() return # If no token sends message... if user_token == None: await ctx.send(s_verify["usage"]) return # Otherwise, keeps going: else: cmdResult = "" data = await api_fetch(c_api_token, user_token) success = data["success"] # If the token isn't valid. if success == False: cmdResult = s_verify["token_not_found"] await ctx.send(cmdResult) else: ### Retrieves needed variables and updates DB if needed. ### server = self.bot.get_guild(id_guild) # If server ID is wrong. if server == None: await ctx.send(s_verify["error"] + "ERROR: Server not found.") return user = ctx.message.author member = server.get_member(user.id) # If user isn't a member. if member == None: database.remove_user_by_discord_uid(ctx.author.id) await ctx.send(s_verify["not_a_member"]) return dm_channel = await member.create_dm() result = database.get_user_by_thm_token(db, user_token) # If user is not in DB; add him. if len(result) == 0: database.add_user(db, member.id, user_token) ### Updates roles for the user. ### await update(member, dm_channel, data)
async def verify(self, ctx, input_token=None): # If not DM, clear the message so that the token isn't kept publicly. if not isinstance(ctx.channel, DMChannel): await ctx.message.delete() msg = await ctx.send(s_verify["error_not_dm"]) time.sleep(15) await msg.delete() return # If no token sends message... if input_token == None: await ctx.send(s_verify["usage"]) return # Otherwise, keeps going: else: cmdResult = "" data = await api_fetch(c_api_token, input_token) success = data["success"] # If the token isn't valid. if success == False: cmdResult = s_verify["token_not_found"] await ctx.send(cmdResult) else: ### Verifies that the token is being use only once and that the discord account doesn't have multiple tokens. ### # If user already has got a token (the provided token and one found are different) user_tokens = database.get_user_by_discord_uid( db, ctx.author.id) if len(user_tokens ) > 0 and not user_tokens[0][1] == input_token: cmdResult = s_verify["already_verified"] await ctx.send(cmdResult) return # If the token is already used token_accounts = database.get_user_by_thm_token( db, input_token) if len(token_accounts) > 0 and not token_accounts[0][0] == str( ctx.author.id): cmdResult = s_verify["token_in_use"] await ctx.send(cmdResult) return ### Retrieves needed variables and updates DB if needed. ### # If server ID is wrong. server = self.bot.get_guild(id_guild) if server == None: await ctx.send(s_verify["error"] + "ERROR: Server not found.") return # If user isn't a member. user = ctx.message.author member = await server.fetch_member(user.id) if member == None: database.remove_user_by_discord_uid(db, ctx.author.id) await ctx.send(s_verify["not_a_member"]) return dm_channel = await member.create_dm() result = database.get_user_by_thm_token(db, input_token) # If user is not in DB; add him. if len(result) == 0: database.add_user(db, member.id, input_token) ### Updates roles for the user. ### await update(member, dm_channel, data)