some refractoring functions
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -10,4 +10,4 @@ gen
|
|||||||
/audio/*/
|
/audio/*/
|
||||||
/test2.py
|
/test2.py
|
||||||
/user.db
|
/user.db
|
||||||
/prefix.json
|
/*.json
|
||||||
|
|||||||
138
test.py
138
test.py
@@ -83,25 +83,7 @@ if not path.isfile('prefix.json'):
|
|||||||
|
|
||||||
def determine_prefix(bot, msg):
|
def determine_prefix(bot, msg):
|
||||||
guild = msg.guild
|
guild = msg.guild
|
||||||
base = DEFAULT_PREFIX
|
base = Commands._read_json(guild.id, 'prefix') or DEFAULT_PREFIX # Get bot role
|
||||||
try:
|
|
||||||
with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON
|
|
||||||
jsonObject = json.load(fp) # Load the custom prefixes
|
|
||||||
|
|
||||||
except:
|
|
||||||
jsonObject = {}
|
|
||||||
|
|
||||||
if guild: # If the guild exists
|
|
||||||
try:
|
|
||||||
guild_conf = jsonObject[f"{guild.id}"]
|
|
||||||
try:
|
|
||||||
prefix = guild_conf["prefix"] # Get the prefix
|
|
||||||
base = prefix
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return base
|
return base
|
||||||
|
|
||||||
|
|
||||||
@@ -112,7 +94,7 @@ inter_client = InteractionClient(bot)
|
|||||||
|
|
||||||
|
|
||||||
class Commands:
|
class Commands:
|
||||||
async def setprefix(ctx, prefix: str):
|
async def set_prefix(ctx, prefix: str):
|
||||||
with open('prefix.json', 'r', encoding='utf-8') as fp:
|
with open('prefix.json', 'r', encoding='utf-8') as fp:
|
||||||
try:
|
try:
|
||||||
jsonObject = json.load(fp)
|
jsonObject = json.load(fp)
|
||||||
@@ -144,6 +126,45 @@ class Commands:
|
|||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
async def _read_json(guild, param):
|
||||||
|
parameter = None
|
||||||
|
try:
|
||||||
|
with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON
|
||||||
|
jsonObject = json.load(fp) # Load the custom prefixes
|
||||||
|
|
||||||
|
except:
|
||||||
|
jsonObject = {}
|
||||||
|
|
||||||
|
if guild: # If the guild exists
|
||||||
|
try:
|
||||||
|
guild_conf = jsonObject[f"{guild}"]
|
||||||
|
try:
|
||||||
|
parameter = guild_conf[f"{param}"]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
return parameter
|
||||||
|
|
||||||
|
async def _write_json(guild, param_name, param):
|
||||||
|
with open('prefix.json', 'r', encoding='utf-8') as fp:
|
||||||
|
try:
|
||||||
|
jsonObject = json.load(fp)
|
||||||
|
except:
|
||||||
|
jsonObject = {}
|
||||||
|
try:
|
||||||
|
jsonObject[f"{guild}"][f"{param_name}"] = param
|
||||||
|
except KeyError:
|
||||||
|
json_param = jsonObject[f"{guild}"] = {f'{param_name}': ''}
|
||||||
|
new = {f"{param_name}": param}
|
||||||
|
json_param.update(new)
|
||||||
|
jsonObject[str(guild)] = json_param
|
||||||
|
|
||||||
|
with open("prefix.json", "w") as fl:
|
||||||
|
json.dump(jsonObject, fl)
|
||||||
|
fl.close()
|
||||||
|
|
||||||
|
|
||||||
@bot.event
|
@bot.event
|
||||||
async def on_ready():
|
async def on_ready():
|
||||||
@@ -165,23 +186,8 @@ async def on_guild_join(guild):
|
|||||||
async def on_member_join(member):
|
async def on_member_join(member):
|
||||||
DB._fill_bd(member.name, member.id, member.bot, member.nick, member.guild.id)
|
DB._fill_bd(member.name, member.id, member.bot, member.nick, member.guild.id)
|
||||||
|
|
||||||
try:
|
bot_role = Commands._read_json(member.guild.id, 'bot_role') # Get bot role
|
||||||
with open('prefix.json', 'r', encoding='utf-8') as fp: # Open the JSON
|
guest_role = Commands._read_json(member.guild.id, 'guest_role') # Get guest role
|
||||||
jsonObject = json.load(fp) # Load the custom prefixes
|
|
||||||
|
|
||||||
except:
|
|
||||||
jsonObject = {}
|
|
||||||
|
|
||||||
if member.guild.id: # If the guild exists
|
|
||||||
try:
|
|
||||||
guild_conf = jsonObject[f"{member.guild.id}"]
|
|
||||||
try:
|
|
||||||
bot_role = guild_conf["bot_role"] # Get bot role
|
|
||||||
guest_role = guild_conf["guest_role"] # Get guest role
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if bot_role and guest_role:
|
if bot_role and guest_role:
|
||||||
if member.bot == 0:
|
if member.bot == 0:
|
||||||
@@ -247,7 +253,7 @@ async def upload_audio(ctx, user=None):
|
|||||||
@bot.command(name="set_prefix")
|
@bot.command(name="set_prefix")
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def command_setprefix(ctx, prefix: str):
|
async def command_setprefix(ctx, prefix: str):
|
||||||
await Commands.setprefix(ctx, prefix)
|
await Commands.set_prefix(ctx, prefix)
|
||||||
|
|
||||||
|
|
||||||
@inter_client.slash_command(
|
@inter_client.slash_command(
|
||||||
@@ -258,7 +264,7 @@ async def command_setprefix(ctx, prefix: str):
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
async def slash_setprefix(ctx, prefix: str):
|
async def slash_setprefix(ctx, prefix: str):
|
||||||
await Commands.setprefix(ctx, prefix)
|
await Commands.set_prefix(ctx, prefix)
|
||||||
|
|
||||||
|
|
||||||
@inter_client.slash_command(
|
@inter_client.slash_command(
|
||||||
@@ -308,25 +314,9 @@ async def info(ctx, user=None):
|
|||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def set_trigger_role(ctx, role):
|
async def set_trigger_role(ctx, role):
|
||||||
with open('prefix.json', 'r', encoding='utf-8') as fp:
|
await Commands._write_json(ctx.guild.id, "tigger_role", role.id)
|
||||||
try:
|
|
||||||
jsonObject = json.load(fp)
|
|
||||||
except:
|
|
||||||
jsonObject = {}
|
|
||||||
try:
|
|
||||||
jsonObject[f"{ctx.guild.id}"]["tigger_role"] = role.id
|
|
||||||
except KeyError:
|
|
||||||
trigger_role = jsonObject[f"{ctx.guild.id}"] = {'tigger_role': ''}
|
|
||||||
new = {"tigger_role": role.id}
|
|
||||||
trigger_role.update(new)
|
|
||||||
jsonObject[str(ctx.guild.id)] = trigger_role
|
|
||||||
|
|
||||||
await ctx.send(f"Role to trigger set to : `{role.name}`")
|
await ctx.send(f"Role to trigger set to : `{role.name}`")
|
||||||
|
|
||||||
with open("prefix.json", "w") as fl:
|
|
||||||
json.dump(jsonObject, fl)
|
|
||||||
fl.close()
|
|
||||||
|
|
||||||
|
|
||||||
@inter_client.slash_command(
|
@inter_client.slash_command(
|
||||||
name="set_bot_role",
|
name="set_bot_role",
|
||||||
@@ -337,25 +327,9 @@ async def set_trigger_role(ctx, role):
|
|||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def set_bot_role(ctx, role):
|
async def set_bot_role(ctx, role):
|
||||||
with open('prefix.json', 'r', encoding='utf-8') as fp:
|
await Commands._write_json(ctx.guild.id, "bot_role", role.id)
|
||||||
try:
|
|
||||||
jsonObject = json.load(fp)
|
|
||||||
except:
|
|
||||||
jsonObject = {}
|
|
||||||
try:
|
|
||||||
jsonObject[f"{ctx.guild.id}"]["bot_role"] = role.id
|
|
||||||
except KeyError:
|
|
||||||
bot_role = jsonObject[f"{ctx.guild.id}"] = {'bot_role': ''}
|
|
||||||
new = {"bot_role": role.id}
|
|
||||||
bot_role.update(new)
|
|
||||||
jsonObject[str(ctx.guild.id)] = bot_role
|
|
||||||
|
|
||||||
await ctx.send(f"Setted up bot role to: `{role.name}`")
|
await ctx.send(f"Setted up bot role to: `{role.name}`")
|
||||||
|
|
||||||
with open("prefix.json", "w") as fl:
|
|
||||||
json.dump(jsonObject, fl)
|
|
||||||
fl.close()
|
|
||||||
|
|
||||||
|
|
||||||
@inter_client.slash_command(
|
@inter_client.slash_command(
|
||||||
name="set_guest_role",
|
name="set_guest_role",
|
||||||
@@ -366,24 +340,8 @@ async def set_bot_role(ctx, role):
|
|||||||
)
|
)
|
||||||
@commands.has_permissions(administrator=True)
|
@commands.has_permissions(administrator=True)
|
||||||
async def set_guest_role(ctx, role):
|
async def set_guest_role(ctx, role):
|
||||||
with open('prefix.json', 'r', encoding='utf-8') as fp:
|
await Commands._write_json(ctx.guild.id, "guest_role", role.id)
|
||||||
try:
|
|
||||||
jsonObject = json.load(fp)
|
|
||||||
except:
|
|
||||||
jsonObject = {}
|
|
||||||
try:
|
|
||||||
jsonObject[f"{ctx.guild.id}"]["guest_role"] = role.id
|
|
||||||
except KeyError:
|
|
||||||
bot_role = jsonObject[f"{ctx.guild.id}"] = {'guest_role': ''}
|
|
||||||
new = {"guest_role": role.id}
|
|
||||||
bot_role.update(new)
|
|
||||||
jsonObject[str(ctx.guild.id)] = bot_role
|
|
||||||
|
|
||||||
await ctx.send(f"Setted up bot role to: `{role.name}`")
|
await ctx.send(f"Setted up bot role to: `{role.name}`")
|
||||||
|
|
||||||
with open("prefix.json", "w") as fl:
|
|
||||||
json.dump(jsonObject, fl)
|
|
||||||
fl.close()
|
|
||||||
|
|
||||||
|
|
||||||
bot.run('OTQ3OTUzOTAxNzgzNjIxNjYy.GTXbMv.KrztaTO7-ivsPEAVjsyikSQ-GP-ANwULmDraig')
|
bot.run('OTQ3OTUzOTAxNzgzNjIxNjYy.GTXbMv.KrztaTO7-ivsPEAVjsyikSQ-GP-ANwULmDraig')
|
||||||
|
|||||||
Reference in New Issue
Block a user