Skip to content
This repository was archived by the owner on Oct 2, 2023. It is now read-only.

Commit 6cfa4bd

Browse files
NekoFanaticDefelo
authored andcommitted
Added role-clone command to clone a role
1 parent 544dc55 commit 6cfa4bd

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

administration/roles/cog.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
from typing import Optional, Union, Dict, List
22

3+
import discord.ext.commands
34
from discord import Role, Embed, Member, Status, Guild, NotFound, User, Forbidden
45
from discord.ext import commands
56
from discord.ext.commands import CommandError, Context, guild_only, UserInputError, Group
67

78
from PyDrocsid.cog import Cog
89
from PyDrocsid.command import reply, docs, optional_permissions
9-
from PyDrocsid.config import Contributor, Config
10+
from PyDrocsid.config import Config
11+
from ...contributor import Contributor
1012
from PyDrocsid.converter import UserMemberConverter
1113
from PyDrocsid.database import db, select, filter_by
1214
from PyDrocsid.embeds import send_long_embed
@@ -90,7 +92,7 @@ async def inner(_, ctx: Context, *, role: Role):
9092

9193

9294
class RolesCog(Cog, name="Roles"):
93-
CONTRIBUTORS = [Contributor.Defelo]
95+
CONTRIBUTORS = [Contributor.Defelo, Contributor.NekoFanatic]
9496

9597
def __init__(self):
9698
super().__init__()
@@ -241,6 +243,52 @@ async def roles_add(self, ctx: Context, member: Member, *, role: Role):
241243
await member.add_roles(role)
242244
await ctx.message.add_reaction(name_to_emoji["white_check_mark"])
243245

246+
@roles.command(name="clone", aliases=["cl", "%"])
247+
@RolesPermission.roles_clone.check
248+
@docs(t.commands.roles_clone)
249+
async def roles_clone(self, ctx: Context, role: Role):
250+
if not await is_authorized(ctx.author, role, perma=False):
251+
raise CommandError(t.role_not_authorized)
252+
253+
permission_list = ["add_reactions", "administrator", "attach_files", "ban_members", "change_nickname",
254+
"connect", "create_instant_invite", "deafen_members", "embed_links", "external_emojis",
255+
"kick_members", "manage_channels", "manage_emojis", "manage_guild", "manage_messages",
256+
"manage_nicknames", "manage_permissions", "manage_roles", "manage_webhooks",
257+
"mention_everyone", "move_members", "mute_members", "priority_speaker",
258+
"read_message_history", "read_messages", "request_to_speak", "send_messages",
259+
"send_tts_messages", "speak", "stream", "use_external_emojis", "use_slash_commands",
260+
"use_voice_activation", "value", "view_audit_log", "view_channel", "view_guild_insights"]
261+
262+
missing_perms = []
263+
params = discord.Permissions()
264+
bot_member_object = ctx.guild.get_member(self.bot.user.id)
265+
266+
for permission in permission_list:
267+
if getattr(bot_member_object.guild_permissions, permission) == getattr(role.permissions,
268+
permission) is True:
269+
params.update(**{permission: True})
270+
else:
271+
missing_perms.append(permission)
272+
273+
await ctx.guild.create_role(
274+
name=role.name,
275+
color=role.color,
276+
permissions=params,
277+
hoist=role.hoist,
278+
mentionable=role.mentionable
279+
)
280+
await ctx.message.add_reaction(name_to_emoji["white_check_mark"])
281+
if missing_perms:
282+
descrip = ""
283+
for mis in missing_perms:
284+
descrip += f"`{mis}`\n"
285+
em = Embed(
286+
title=t.failed_to_clone_role_permissions,
287+
description=descrip,
288+
color=Colors.MissingPermissions
289+
)
290+
await send_long_embed(ctx, em, paginate=True)
291+
244292
@roles.command(name="remove", aliases=["r", "del", "d", "-"])
245293
@optional_permissions(RolesPermission.auth_write)
246294
@docs(t.commands.roles_remove)

administration/roles/colors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33

44
class Colors(MaterialColors):
55
Roles = MaterialColors.blue["a700"]
6+
MissingPermissions = MaterialColors.yellow["a700"]

administration/roles/permissions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ def description(self) -> str:
1414
auth_read = auto()
1515
auth_write = auto()
1616
list_members = auto()
17+
roles_clone = auto()

administration/roles/translations/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ permissions:
44
auth_read: read role assignment permissions
55
auth_write: write role assignment permissions
66
list_members: list role members
7+
roles_clone: clones existing roles
78

89
commands:
910
roles: manage roles
@@ -12,6 +13,7 @@ commands:
1213
roles_auth_add: add a new role assignment authorization
1314
roles_auth_remove: remove a role assignment authorization
1415
roles_add: assign a role to a member
16+
roles_clone: clone an existing role
1517
roles_remove: remove a role from a member
1618
roles_perma_add: assign a role permanently to a member
1719
roles_perma_unset: remove the perma flag from a member role
@@ -52,3 +54,4 @@ perma_reassigned: Perma role {} has been reassigned to {} ({}). If you want to r
5254
no_perma_roles: No permanent role assignments.
5355
perma_roles: Permanent Role Assignments
5456
could_not_reassign: Could not reassign perma role {} to {} ({}).
57+
failed_to_clone_role_permissions: ":warning: Could not clone following permissions:"

contributor.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ class Contributor(ContributorBase):
1111
Tristan = (277069925678317568, "MDQ6VXNlcjQ1MzMwNjY3")
1212
Tert0 = (621330363167539210, "MDQ6VXNlcjYyMDM2NDY0")
1313
MarcelCoding = (398895973490884608, "MDQ6VXNlcjM0ODE5NTI0")
14+
NekoFanatic = (544956941643022356, "MDQ6VXNlcjgzODgzODQ5")

0 commit comments

Comments
 (0)