mirror of
https://github.com/TotalFreedomMC/TotalFreedomBot.git
synced 2024-12-22 07:34:57 +00:00
Update functions.py
This commit is contained in:
parent
ad7fabc80e
commit
5e77dee33f
1 changed files with 12 additions and 3 deletions
15
functions.py
15
functions.py
|
@ -81,7 +81,7 @@ def config_entry(entry):
|
|||
return read_json('config')[entry]
|
||||
|
||||
|
||||
def hit_endpoint(command, server=1):
|
||||
def hit_endpoint(command, server=1, timeout=10):
|
||||
config_file = read_json('config')
|
||||
if server == 1:
|
||||
ip = config_file['SERVER_IP']
|
||||
|
@ -95,9 +95,9 @@ def hit_endpoint(command, server=1):
|
|||
headers = {}
|
||||
try:
|
||||
response = json.loads(requests.request(
|
||||
"GET", url, headers=headers, data=payload, timeout=5).text)
|
||||
"GET", url, headers=headers, data=payload, timeout=timeout).text)
|
||||
except Exception as e:
|
||||
response = dict(response=f'Connection Error: {e}')
|
||||
raise Exception(f'Error while hitting endpoint: {e}')
|
||||
return response['response']
|
||||
|
||||
|
||||
|
@ -114,3 +114,12 @@ def get_server_status(server=1):
|
|||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def get_visible_player_count(list_json):
|
||||
total = 0
|
||||
for x in list_json:
|
||||
if type(list_json[x]) == list:
|
||||
total += len(list_json[x])
|
||||
|
||||
return total
|
||||
|
|
Loading…
Reference in a new issue