Skip to content

Commit

Permalink
fix pylint problems in function.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Donbur4156 committed Jun 3, 2021
1 parent 2faa167 commit 1292a04
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 44 deletions.
4 changes: 3 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[MASTER]
disable=
C0114, # missing-module-docstring
C0116, # missing-function-docstring
E0401, # import-error
R1723, # no-else-break
R1723, # no-else-break

55 changes: 12 additions & 43 deletions faultybot/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ def check_user(username):
""" Check User """
flag = False
try:
# The system marks such players with a TOS mark. This can be obtained as an array from the API.
# The system marks such players with a TOS mark.
# This can be obtained as an array from the API.
flag = lichesspy.api.user(username)['tosViolation']
except:
except lichesspy.api.ApiError():
# Since it is either there or not, the try catch block is misused as an if statement
flag = False
else:
flag = False
return flag


Expand All @@ -22,9 +25,8 @@ def check_user(username):
def check_user_ausgabe(username):
""" Check User Ausgabe """
if check_user(username):
return "True"
else:
return "False"
return True
return False


# The function checks all players of a team and returns a list of all cheaters.
Expand All @@ -51,26 +53,16 @@ def kick(team, user, token):
header = {'Authorization': 'Bearer ' + token}
# The Lichess API accepts the request as a POST request.
# Therefore all data must be in the header.
r = requests.post(url, headers=header)
return r


# The function kicks all cheaters from the desired team.
def runner(team, token):
# This is actually the complete backend for the kickfaulty
for c in analyse_team(team.lower()):
kick(team.lower(), c, token)
request = requests.post(url, headers=header)
return request


# Unfortunately, the API returns only an array.
# This is checked here.
def check(level):
""" check """
# Since it is a request response, it cannot be interpreted as a string.
if "true" in level.text:
return True
else:
return False
return bool("true" in level.text)


# The function investigates why a request failed.
Expand All @@ -85,26 +77,6 @@ def status(level):
return "No Error"


# This function kicks all people out of the team. No matter if they cheat or not.
# This function is usually only used for YouTube teams.
def clear_team(team, token):
try:
# The bot just goes through them all. With normal teams,
# lichess does not block the IP address either.
for i in lichesspy.api.users_by_team(team):
username = i.get('username').lower()
url = 'https://lichess.org/team/' + team + '/kick/' + username
header = {'Authorization': 'Bearer ' + token}
requests.post(url, headers=header)
# So that lichess doesn't think we're about to launch a DDOS attack,
# we give them some time to catch their breath.
time.sleep(1)
except Exception as error:
print(error)
return False
return True


# If anyone operates the bot incorrectly, it will be checked again for errors here.
def check_team_name(team):
# The program uses the static links from lichess
Expand All @@ -114,10 +86,7 @@ def check_team_name(team):
# Lichess cannot process teams with the "/" character for syntax reasons.
# Therefore there are no such teams.
if "/" in team[-runner::]:
runner = runner - 1
runner -= 1
else:
return team[-runner::]
else:
return team
# The false can never be reached. It stands so that it looks better
return False
return team

0 comments on commit 1292a04

Please sign in to comment.