Listing and deleting secret roles
This commit is contained in:
parent
cc214cb1ab
commit
43c3ae1757
1 changed files with 33 additions and 3 deletions
|
@ -9,9 +9,13 @@ class Roles(commands.Cog):
|
||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
@discord.slash_command()
|
secret_roles = discord.SlashCommandGroup(
|
||||||
@discord.default_permissions(manage_roles=True)
|
"secretroles",
|
||||||
async def addsecretrole(self, ctx, role: discord.role.Role, password: str):
|
checks=[commands.has_permissions(manage_roles=True)]
|
||||||
|
)
|
||||||
|
|
||||||
|
@secret_roles.command()
|
||||||
|
async def add(self, ctx, role: discord.role.Role, password: str):
|
||||||
roles = data.load_data(ROLES_JSON)
|
roles = data.load_data(ROLES_JSON)
|
||||||
if password in roles["secret_roles"]:
|
if password in roles["secret_roles"]:
|
||||||
return await ctx.respond(f"Password ``{password}`` is already used.", ephemeral=True)
|
return await ctx.respond(f"Password ``{password}`` is already used.", ephemeral=True)
|
||||||
|
@ -19,6 +23,32 @@ class Roles(commands.Cog):
|
||||||
roles["secret_roles"][password] = role.id
|
roles["secret_roles"][password] = role.id
|
||||||
data.dump_data(ROLES_JSON, roles)
|
data.dump_data(ROLES_JSON, roles)
|
||||||
return await ctx.respond(f"Secret role {role.mention} added with password {password}.", ephemeral=True)
|
return await ctx.respond(f"Secret role {role.mention} added with password {password}.", ephemeral=True)
|
||||||
|
|
||||||
|
@secret_roles.command()
|
||||||
|
async def list(self, ctx):
|
||||||
|
roles = data.load_data(ROLES_JSON)
|
||||||
|
if len(roles["secret_roles"]) == 0:
|
||||||
|
return await ctx.respond(f"No current secret roles.", ephemeral=True)
|
||||||
|
msg = ""
|
||||||
|
for passwd, role in roles["secret_roles"].items():
|
||||||
|
role = get(ctx.author.guild.roles, id=role)
|
||||||
|
msg += f"``{passwd}``: {role.mention}\n"
|
||||||
|
return await ctx.respond(msg, ephemeral=True)
|
||||||
|
|
||||||
|
@secret_roles.command()
|
||||||
|
async def delete(self, ctx, password: str):
|
||||||
|
roles = data.load_data(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)
|
||||||
|
return await ctx.respond(
|
||||||
|
f"Secret role {role.mention} no longer obtainable with password {password}.",
|
||||||
|
ephemeral=True
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@discord.slash_command()
|
@discord.slash_command()
|
||||||
async def secretrole(self, ctx, password: str):
|
async def secretrole(self, ctx, password: str):
|
||||||
|
|
Loading…
Reference in a new issue