most commands moved into cogs

This commit is contained in:
2022-07-02 14:28:22 +03:00
parent 19e1d4226b
commit bab5d68a88
6 changed files with 104 additions and 110 deletions

28
lib.py
View File

@@ -1,7 +1,9 @@
import json
import logging
import sqlite3
from os import walk, listdir
from os import walk, listdir, path
DEFAULT_PREFIX = "$" # The prefix you want everyone to have if you don't define your own
class DB:
@@ -87,6 +89,13 @@ class CogsPrepare:
class Commands:
@staticmethod
def chech_json():
if not path.isfile('prefix.json'):
with open('prefix.json', 'w+') as f:
f.write("")
f.close()
@staticmethod
async def set_prefix(ctx, prefix: str):
await Commands.write_json(ctx.guild.id, "prefix", prefix)
@@ -142,3 +151,20 @@ class Commands:
with open('prefix.json', 'w') 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
try:
_json = json.load(fp) # Load the custom prefixes
except error:
_json = {}
if 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