This commit is contained in:
2022-07-24 09:53:19 +03:00
parent 5298783ce4
commit 1011e287c9
6 changed files with 36 additions and 16 deletions

32
lib.py
View File

@@ -21,7 +21,12 @@ class DB:
logging.error("failed to connect db", _error)
@staticmethod
def work_with_db(db_func, data_turple):
def work_with_db(db_func: str, data_turple: tuple):
"""
Writing to db per server userinfo
:param db_func:
:param data_turple:
"""
try:
connect = sqlite3.connect('user.db')
cursor = connect.cursor()
@@ -37,7 +42,7 @@ class DB:
sqlite_insert_with_param = (f"""INSERT OR IGNORE INTO "{guild}"
(username, userid, nick, isbot)
VALUES (?, ?, ?, ?)""")
data_tuple = (name, userid, nick, isbot)
data_tuple: tuple[str, int, str, bool] = (name, userid, nick, isbot)
DB.work_with_db(sqlite_insert_with_param, data_tuple)
@staticmethod
@@ -61,6 +66,10 @@ class DB:
class CogsPrepare:
"""
Loads, unloads Cogs files
"""
@staticmethod
def cog_list():
cogs_list = []
@@ -94,7 +103,6 @@ class Commands:
if not path.isfile('prefix.json'):
with open('prefix.json', 'w+', encoding='utf-8') as f:
f.write("")
f.close()
@staticmethod
async def set_prefix(inter, prefix: str):
@@ -118,7 +126,7 @@ class Commands:
parameter = None
try:
_json = json.load(fp) # Load the custom prefixes
except:
except TypeError:
_json = {}
if guild: # If the guild exists
try:
@@ -129,7 +137,7 @@ class Commands:
pass
except:
pass
fp.close()
return parameter
@staticmethod
@@ -139,7 +147,6 @@ class Commands:
_json = json.load(_f)
except json.decoder.JSONDecodeError:
_json = {}
_f.close()
try:
_guild = _json[f'{guild}']
except KeyError:
@@ -149,10 +156,15 @@ class Commands:
with open('prefix.json', 'w', encoding='utf-8') as _f:
json.dump(_json, _f, indent=4)
_f.close()
@staticmethod
def determine_prefix(bot, msg):
"""
Determite perserver bot prefix
:param bot:
:param msg:
:return: prefix
"""
with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON
parameter: str
try:
@@ -160,10 +172,12 @@ class Commands:
_json = load(fp) # Load the custom prefixes
except:
_json = {}
if msg.guild: # If the guild exists
try:
parameter = _json[f"{msg.guild.id}"]["prefix"] # Read prefix from json if is setted up
except:
parameter = DEFAULT_PREFIX
print(parameter)
return parameter
print(parameter)
return parameter