mirror of
https://github.com/TotalFreedomMC/TotalFreedomBot.git
synced 2024-12-22 15:44:57 +00:00
Update functions.py
This commit is contained in:
parent
ebd8d535d0
commit
7342ccc5d5
1 changed files with 24 additions and 19 deletions
31
functions.py
31
functions.py
|
@ -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:
|
||||
|
|
Loading…
Reference in a new issue