Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

roles #28

Merged
merged 1 commit into from
Nov 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 37 additions & 9 deletions cogs/server_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ async def _unban(self, ctx: SlashContext, user_id: str,
# @cog_ext.cog_subcommand(base="server", subcommand_group="user", name="add-role", description="adds a role to a user")
# @cog_ext.cog_subcommand(base="server", subcommand_group="user", name="remove-role", description="removes a role from a user")

cre_opt = [
rcre_opt = [
{
"name": "name",
"description": "the name of the role",
Expand All @@ -524,10 +524,23 @@ async def _unban(self, ctx: SlashContext, user_id: str,
"type": 3,
"required": True,
},
{
"name": "hoist",
"description": "whether the role should be shown separately in the member list, default False",
"required": False,
"type": 5,
},
{
"name": "mentionable",
"description": "whether everyone should be able to mention the role, default False",
"required": False,
"type": 5,
},
]

@cog_ext.cog_subcommand(base="server", subcommand_group="role", name="create", description="creates a role")
async def _create_role(self, ctx: SlashContext, name: str, color: str):
@cog_ext.cog_subcommand(base="server", subcommand_group="role", name="create", description="creates a role",
options=rcre_opt)
async def _create_role(self, ctx: SlashContext, name: str, color: str, hoist: bool = False, mentionable: bool = False):
if not ctx.author.guild_permissions.manage_roles:
raise discord.ext.commands.errors.MissingPermissions(missing_perms=["manage_roles"])
match = re.search(r'^#(?:[0-9a-fA-F]{3}){1,2}$', color) # check if color is hex
Expand Down Expand Up @@ -585,7 +598,7 @@ async def _create_role(self, ctx: SlashContext, name: str, color: str):
content=f"creating role '{name}' with the color #{hexval} and no permissions....",
components=[any_ar]
)
await ctx.guild.create_role(name=name, color=color, permissions=roleperm)
await ctx.guild.create_role(name=name, color=color, permissions=roleperm, hoist=hoist, mentionable=mentionable)
await ctx.channel.send("Done")
return

Expand Down Expand Up @@ -615,7 +628,7 @@ async def _create_role(self, ctx: SlashContext, name: str, color: str):
content=f"creating role '{name}' with the color #{hexval} and administrator permissions....",
components=[adm_ar]
)
await ctx.guild.create_role(name=name, color=color, permissions=roleperm)
await ctx.guild.create_role(name=name, color=color, permissions=roleperm, hoist=hoist, mentionable=mentionable)
await ctx.channel.send("Done")
return

Expand Down Expand Up @@ -812,7 +825,7 @@ async def _create_role(self, ctx: SlashContext, name: str, color: str):
content="Please choose the permissions you want to assign to the role (2/2)",
components=[sel2row],
)

try:
secondperms = await wait_for_component(self.bot, components=[sel2row], timeout=600)
await secondperms.defer(edit_origin=True)
Expand Down Expand Up @@ -844,12 +857,27 @@ async def _create_role(self, ctx: SlashContext, name: str, color: str):
content=f"Role '{name}' with color #{hexval} and your custom permissions, which have the value {roleperm.value}, is being created",
components=[sel2row]
),
await ctx.guild.create_role(name=name, color=color, permissions=roleperm)
await ctx.guild.create_role(name=name, color=color, permissions=roleperm, hoist=hoist, mentionable=mentionable)
await ctx.channel.send("Done!")


# @cog_ext.cog_subcommand(base="server", subcommand_group="role", name="edit", description="edits a role")
# @cog_ext.cog_subcommand(base="server", subcommand_group="role", name="delete", description="deletes a role")

rdel_opt = [
{
"name": "role",
"description": "the role to delete",
"required": True,
"type": 8
}
]

@cog_ext.cog_subcommand(base="server", subcommand_group="role", name="delete", description="deletes a role",
options=rdel_opt)
async def _delete_role(self, ctx: SlashContext, role: discord.Role):
if not ctx.author.guild_permissions.manage_roles:
raise discord.ext.commands.MissingPermissions(missing_perms=["manage_roles"])
await role.delete()
await ctx.send("role has been deleted")

# @cog_ext.cog_subcommand(base="server", subcommand_group="channel", name="create", description="creates a channel")
# @cog_ext.cog_subcommand(base="server", subcommand_group="channel", name="edit", description="edits a channel") # not sure about that one
Expand Down