Moving
This commit is contained in:
33
lib.py
33
lib.py
@@ -90,16 +90,15 @@ class CogsPrepare:
|
||||
|
||||
class Commands:
|
||||
@staticmethod
|
||||
def chech_json():
|
||||
def check_json():
|
||||
if not path.isfile('prefix.json'):
|
||||
with open('prefix.json', 'w+') as f:
|
||||
with open('prefix.json', 'w+', encoding='utf-8') as f:
|
||||
f.write("")
|
||||
f.close()
|
||||
|
||||
@staticmethod
|
||||
async def set_prefix(ctx, prefix: str):
|
||||
await Commands.write_json(ctx.guild.id, "prefix", prefix)
|
||||
await ctx.send(f"Prefix set to: `{prefix}`", ephemeral=True)
|
||||
async def set_prefix(inter, prefix: str):
|
||||
await Commands.write_json(inter.guild.id, "prefix", prefix)
|
||||
|
||||
@staticmethod
|
||||
def list_files(fold: str):
|
||||
@@ -135,7 +134,7 @@ class Commands:
|
||||
|
||||
@staticmethod
|
||||
async def write_json(guild: int, param_name: str, param: str or int):
|
||||
with open('prefix.json', 'r') as _f:
|
||||
with open('prefix.json', 'r', encoding='utf-8') as _f:
|
||||
try:
|
||||
_json = json.load(_f)
|
||||
except json.decoder.JSONDecodeError:
|
||||
@@ -148,23 +147,23 @@ class Commands:
|
||||
_guild = _json[f'{guild}']
|
||||
_guild.update({f'{param_name}': f'{param}'})
|
||||
|
||||
with open('prefix.json', 'w') as _f:
|
||||
with open('prefix.json', 'w', encoding='utf-8') as _f:
|
||||
json.dump(_json, _f, indent=4)
|
||||
_f.close()
|
||||
|
||||
@staticmethod
|
||||
def determine_prefix(bot, msg):
|
||||
guild = msg.guild
|
||||
with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON
|
||||
parameter = DEFAULT_PREFIX
|
||||
parameter: str
|
||||
try:
|
||||
_json = json.load(fp) # Load the custom prefixes
|
||||
except error:
|
||||
from json import load
|
||||
_json = load(fp) # Load the custom prefixes
|
||||
except:
|
||||
_json = {}
|
||||
if guild: # If the guild exists
|
||||
if msg.guild: # If the guild exists
|
||||
try:
|
||||
parameter = _json[f"{guild.id}"]["prefix"] # Read prefix from json if is setted up
|
||||
except error:
|
||||
pass
|
||||
return parameter
|
||||
|
||||
parameter = _json[f"{msg.guild.id}"]["prefix"] # Read prefix from json if is setted up
|
||||
except:
|
||||
parameter = DEFAULT_PREFIX
|
||||
print(parameter)
|
||||
return parameter
|
||||
|
||||
Reference in New Issue
Block a user