|
|
@ -5,6 +5,9 @@ from discord.utils import get |
|
|
|
|
|
|
|
ROLES_JSON = "roles" |
|
|
|
|
|
|
|
def role_mention(role): |
|
|
|
return role.mention if role else "@deleted-role" |
|
|
|
|
|
|
|
class Roles(commands.Cog): |
|
|
|
def __init__(self, bot): |
|
|
|
self.bot = bot |
|
|
@ -36,7 +39,7 @@ class Roles(commands.Cog): |
|
|
|
msg = "" |
|
|
|
for passwd, role in roles["secret_roles"].items(): |
|
|
|
role = get(ctx.author.guild.roles, id=role) |
|
|
|
msg += f"``{passwd}``: {role.mention}\n" |
|
|
|
msg += f"``{passwd}``: {role_mention(role)}\n" |
|
|
|
return await ctx.respond(msg, ephemeral=True) |
|
|
|
|
|
|
|
@secret_roles.command(description="Deletes given password and its secret role.") |
|
|
@ -50,7 +53,7 @@ class Roles(commands.Cog): |
|
|
|
del roles["secret_roles"][password] |
|
|
|
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}.", |
|
|
|
f"Secret role {role_mention(role)} no longer obtainable with password {password}.", |
|
|
|
ephemeral=True |
|
|
|
) |
|
|
|
|
|
|
@ -61,7 +64,9 @@ class Roles(commands.Cog): |
|
|
|
if password in roles["secret_roles"]: |
|
|
|
author = ctx.author |
|
|
|
role = get(author.guild.roles, id=roles["secret_roles"][password]) |
|
|
|
await author.add_roles(role, reason="Roles assigned for password knowledge.") |
|
|
|
if role is None: |
|
|
|
return await ctx.respond(f"Role for this password was deleted.", ephemeral=True) |
|
|
|
await author.add_roles(role, reason="Role assigned for password knowledge.") |
|
|
|
return await ctx.respond(f"You now have role {role.mention}.", ephemeral=True) |
|
|
|
else: |
|
|
|
return await ctx.respond("Incorrect password.", ephemeral=True) |
|
|
|