some code changes
This commit is contained in:
@@ -1,23 +1,26 @@
|
||||
import asyncio
|
||||
"""
|
||||
lib.Commands
|
||||
~~~~~~~~~~~~~~
|
||||
Some prepare for commands
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
from typing import Union
|
||||
|
||||
import disnake
|
||||
|
||||
"""
|
||||
Some prepare for commands
|
||||
|
||||
"""
|
||||
import dotenv
|
||||
|
||||
|
||||
def check_conf():
|
||||
if not os.path.isfile(os.getenv('conf_file')):
|
||||
with open(os.getenv('conf_file'), 'w+', encoding='utf-8') as f:
|
||||
def preload_checks():
|
||||
dotenv.load_dotenv()
|
||||
if not os.path.isfile('.env') or not os.getenv('CONF_FILE'):
|
||||
with open('.env', 'a', encoding='utf-8') as f:
|
||||
f.write("CONF_FILE='config.json'\n")
|
||||
dotenv.load_dotenv()
|
||||
if not os.path.isfile(os.getenv('CONF_FILE')):
|
||||
with open(os.getenv('CONF_FILE'), 'a', encoding='utf-8') as f:
|
||||
f.write("")
|
||||
|
||||
|
||||
async def list_files(fold: str = 'audio'):
|
||||
if fold != 'audio': fold = f'audio/{fold}'
|
||||
fl = []
|
||||
for filenames in os.walk(fold):
|
||||
fl.extend(filenames)
|
||||
@@ -36,7 +39,7 @@ async def read_json(guild: int, _param: str):
|
||||
:return: value of parameter.
|
||||
"""
|
||||
parameter = None
|
||||
with open(os.getenv('conf_file'), 'r', encoding='utf-8') as f: # Open the JSON
|
||||
with open(os.getenv('CONF_FILE'), 'r', encoding='utf-8') as f: # Open the JSON
|
||||
try:
|
||||
_json = json.load(f) # Load the custom prefixes
|
||||
except json.decoder.JSONDecodeError:
|
||||
@@ -54,7 +57,7 @@ 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'), 'r', encoding='utf-8') as f:
|
||||
with open(os.getenv('CONF_FILE'), 'r', encoding='utf-8') as f:
|
||||
try:
|
||||
_json = json.load(f)
|
||||
except json.decoder.JSONDecodeError:
|
||||
@@ -65,7 +68,7 @@ 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:
|
||||
with open(os.getenv('CONF_FILE'), 'w', encoding='utf-8') as f:
|
||||
json.dump(_json, f, indent=4)
|
||||
|
||||
|
||||
@@ -77,7 +80,7 @@ def determine_prefix(bot, msg):
|
||||
:return: prefix for server, default is $
|
||||
"""
|
||||
parameter = '$'
|
||||
with open(os.getenv('conf_file'), 'r', encoding='utf-8') as f: # Open the JSON
|
||||
with open(os.getenv('CONF_FILE'), 'r', encoding='utf-8') as f: # Open the JSON
|
||||
try:
|
||||
_json = json.load(f) # Load the custom prefixes
|
||||
except:
|
||||
@@ -97,7 +100,7 @@ def determine_time(msg):
|
||||
:return: prefix for server, default is $
|
||||
"""
|
||||
parameter = 15
|
||||
with open(os.getenv('conf_file'), 'r', encoding='utf-8') as f: # Open the JSON
|
||||
with open(os.getenv('CONF_FILE'), 'r', encoding='utf-8') as f: # Open the JSON
|
||||
try:
|
||||
_json = json.load(f) # Load the custom prefixes
|
||||
except:
|
||||
@@ -108,9 +111,3 @@ def determine_time(msg):
|
||||
except:
|
||||
pass
|
||||
return parameter
|
||||
|
||||
def maybe_defer(inter: disnake.Interaction, *, delay: Union[float, int] = 2.0, **options) -> asyncio.Task:
|
||||
"""Defer an interaction if it has not been responded to after ``delay`` seconds."""
|
||||
loop = inter.bot.loop
|
||||
if delay <= 0:
|
||||
return loop.create_task(inter.response.defer(**options))
|
||||
|
||||
Reference in New Issue
Block a user