optimised imports
This commit is contained in:
@@ -3,8 +3,9 @@ lib.Commands
|
||||
~~~~~~~~~~~~~~
|
||||
Some prepare for commands
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
from json import load, decoder, dump, JSONDecodeError
|
||||
from os import getenv
|
||||
|
||||
from disnake.ext import commands
|
||||
|
||||
|
||||
@@ -16,10 +17,10 @@ async def read_json(guild: int, _param: str):
|
||||
:return: value of parameter.
|
||||
"""
|
||||
parameter = None
|
||||
with open(os.getenv('CONF_FILE'), encoding='utf-8') as f: # Open the JSON
|
||||
with open(getenv('CONF_FILE'), encoding='utf-8') as f: # Open the JSON
|
||||
try:
|
||||
_json = json.load(f) # Load the custom prefixes
|
||||
except json.decoder.JSONDecodeError:
|
||||
_json = load(f) # Load the custom prefixes
|
||||
except decoder.JSONDecodeError:
|
||||
_json = {}
|
||||
if guild: # If the guild exists
|
||||
try:
|
||||
@@ -34,10 +35,10 @@ async def read_json(guild: int, _param: str):
|
||||
|
||||
|
||||
async def write_json(guild: int, param_name: str, param: str or int):
|
||||
with open(os.getenv('CONF_FILE'), encoding='utf-8') as f:
|
||||
with open(getenv('CONF_FILE'), encoding='utf-8') as f:
|
||||
try:
|
||||
_json = json.load(f)
|
||||
except json.decoder.JSONDecodeError:
|
||||
_json = load(f)
|
||||
except decoder.JSONDecodeError:
|
||||
_json = {}
|
||||
try:
|
||||
_guild = _json[f'{guild}']
|
||||
@@ -45,8 +46,8 @@ async def write_json(guild: int, param_name: str, param: str or int):
|
||||
_json.update({f'{guild}': {}})
|
||||
_guild = _json[f'{guild}']
|
||||
_guild.update({f'{param_name}': f'{param}'})
|
||||
with open(os.getenv('CONF_FILE'), 'w', encoding='utf-8') as f:
|
||||
json.dump(_json, f, indent=4)
|
||||
with open(getenv('CONF_FILE'), 'w', encoding='utf-8') as f:
|
||||
dump(_json, f, indent=4)
|
||||
|
||||
|
||||
def determine_prefix(bot: commands.Bot, msg):
|
||||
@@ -57,10 +58,10 @@ def determine_prefix(bot: commands.Bot, msg):
|
||||
:return: prefix for server, default is $
|
||||
"""
|
||||
parameter = '$'
|
||||
with open(os.getenv('CONF_FILE'), encoding='utf-8') as f: # Open the JSON
|
||||
with open(getenv('CONF_FILE'), encoding='utf-8') as f: # Open the JSON
|
||||
try:
|
||||
_json = json.load(f) # Load the custom prefixes
|
||||
except json.JSONDecodeError:
|
||||
_json = load(f) # Load the custom prefixes
|
||||
except JSONDecodeError:
|
||||
_json = {}
|
||||
try:
|
||||
parameter = _json[f"{msg.guild.id}"]["prefix"] # Read prefix from json if is setted up
|
||||
|
||||
Reference in New Issue
Block a user