Update functions.py

This commit is contained in:
Elmon11 2021-01-07 20:13:55 +01:00 committed by GitHub
parent ebd8d535d0
commit 7342ccc5d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,32 +1,32 @@
import json
import requests
import os
import itertools
import json
import os
import requests
from discord.ext import commands
from checks import *
class embed_entry:
def __init__(self, name, value, *, playercount):
class EmbedEntry:
def __init__(self, name, value, playercount=None):
self.name = name
self.value = value
if playercount:
self.playercount = playercount
def format_list_entry(embed, l, name):
l_names = [f'{l[i]}' for i in range(len(l))]
l_names = [name.replace('_', '\_') for name in l_names]
em = embed_entry(
em = EmbedEntry(
name=name,
value=", ".join(l_names),
playercount = len(l)
playercount=len(l)
)
return em
def get_prefix(client, message):
#prefixes = ['TF!', 'Tf!', 'tF!', 'tf!']
prefix = os.getenv('prefix')
prefixes = map(''.join, itertools.product(*((letter.upper(), letter.lower()) for letter in prefix)))
return commands.when_mentioned_or(*prefixes)(client, message)
@ -66,17 +66,21 @@ def get_avatar(user, animate=True):
def read_json(file_name):
with open(f'/root/totalfreedom/{file_name}.json', 'r') as file:
with open(f'{file_name}.json', 'r') as file:
data = json.load(file)
return data
def write_json(file_name, data):
with open(f'/root/totalfreedom/{file_name}.json', 'w') as file:
with open(f'{file_name}.json', 'w') as file:
json.dump(data, file, indent=4)
return data
def config_entry(entry):
return read_json('config')[entry]
def hit_endpoint(command, server=1):
config_file = read_json('config')
if server == 1:
@ -92,10 +96,11 @@ def hit_endpoint(command, server=1):
try:
response = json.loads(requests.request(
"GET", url, headers=headers, data=payload, timeout=5).text)
except:
response = {'response': 'Connection Error.'}
except Exception as e:
response = dict(response=f'Connection Error: {e}')
return response['response']
def get_server_status(server=1):
config_file = read_json('config')
if server == 1: