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