|
|
@ -12,6 +12,7 @@ class Roles(commands.Cog): |
|
|
|
secret_roles = discord.SlashCommandGroup( |
|
|
|
"secretroles", |
|
|
|
"Commands for management of secret roles.", |
|
|
|
guild_only=True, |
|
|
|
checks=[commands.has_permissions(manage_roles=True)] |
|
|
|
) |
|
|
|
|
|
|
@ -19,17 +20,17 @@ class Roles(commands.Cog): |
|
|
|
@discord.option("role", discord.role.Role, description="Role locked behind a password.") |
|
|
|
@discord.option("password", str, description="Password for given role.") |
|
|
|
async def add(self, ctx, role, password): |
|
|
|
roles = data.load_data(ROLES_JSON) |
|
|
|
roles = data.load_guild_data(ctx.author.guild.id, ROLES_JSON) |
|
|
|
if password in roles["secret_roles"]: |
|
|
|
return await ctx.respond(f"Password ``{password}`` is already used.", ephemeral=True) |
|
|
|
|
|
|
|
roles["secret_roles"][password] = role.id |
|
|
|
data.dump_data(ROLES_JSON, roles) |
|
|
|
data.dump_guild_data(ctx.author.guild.id, ROLES_JSON, roles) |
|
|
|
return await ctx.respond(f"Secret role {role.mention} added with password {password}.", ephemeral=True) |
|
|
|
|
|
|
|
@secret_roles.command(description="Lists all passwords and their secret roles") |
|
|
|
async def list(self, ctx): |
|
|
|
roles = data.load_data(ROLES_JSON) |
|
|
|
roles = data.load_guild_data(ctx.author.guild.id, ROLES_JSON) |
|
|
|
if len(roles["secret_roles"]) == 0: |
|
|
|
return await ctx.respond(f"No current secret roles.", ephemeral=True) |
|
|
|
msg = "" |
|
|
@ -41,22 +42,22 @@ class Roles(commands.Cog): |
|
|
|
@secret_roles.command(description="Deletes given password and its secret role.") |
|
|
|
@discord.option("password", str, description="Password to be deleted.") |
|
|
|
async def delete(self, ctx, password): |
|
|
|
roles = data.load_data(ROLES_JSON) |
|
|
|
roles = data.load_guild_data(ctx.author.guild.id, ROLES_JSON) |
|
|
|
if password not in roles["secret_roles"]: |
|
|
|
return await ctx.respond(f"Role with passowrd {password} does not exist.", ephemeral=True) |
|
|
|
|
|
|
|
role = get(ctx.author.guild.roles, id=roles["secret_roles"][password]) |
|
|
|
del roles["secret_roles"][password] |
|
|
|
data.dump_data(ROLES_JSON, roles) |
|
|
|
data.dump_guild_data(ctx.author.guild.id, ROLES_JSON, roles) |
|
|
|
return await ctx.respond( |
|
|
|
f"Secret role {role.mention} no longer obtainable with password {password}.", |
|
|
|
ephemeral=True |
|
|
|
) |
|
|
|
|
|
|
|
@discord.slash_command(description="Gives a secret role locked by a password.") |
|
|
|
@discord.slash_command(description="Gives a secret role locked by a password.", guild_only=True) |
|
|
|
@discord.option("password", str, description="Password for secret role.") |
|
|
|
async def secretrole(self, ctx, password): |
|
|
|
roles = data.load_data(ROLES_JSON) |
|
|
|
roles = data.load_guild_data(ctx.author.guild.id, ROLES_JSON) |
|
|
|
if password in roles["secret_roles"]: |
|
|
|
author = ctx.author |
|
|
|
role = get(author.guild.roles, id=roles["secret_roles"][password]) |
|
|
|