From a4d6277e72d430f68b1402b66f07d729b6c51653 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Sat, 17 Dec 2022 21:47:15 +0300 Subject: [PATCH] a --- minearchy_bot/cogs/utils.py | 149 +++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 72 deletions(-) diff --git a/minearchy_bot/cogs/utils.py b/minearchy_bot/cogs/utils.py index e710baa..4cd0ed4 100644 --- a/minearchy_bot/cogs/utils.py +++ b/minearchy_bot/cogs/utils.py @@ -56,9 +56,11 @@ class Utils(Cog): continue if isinstance(channel, CategoryChannel): - string.append(f"category {channel.name}:") - string.append(f" id: {channel.id}") + string.append(f"category `{channel.name}`: ") + # Category perms start. + + # " permissions:" perms = [] for thing, overwrites in channel.overwrites.items(): @@ -72,9 +74,6 @@ class Utils(Cog): typ = repr(thing.type) name = "unknown" - perms.append(f" {typ} {name}:") - perms.append(f" id: {thing.id}") - allow, deny = [], [] for perm, value in overwrites._values.items(): @@ -84,74 +83,79 @@ class Utils(Cog): deny.append(perm) if allow or deny: + perms.append(f" {typ} {name}: {thing.id}") perms.append(" permissions:") for a in allow: perms.append(f" {a}: ✅") for d in deny: perms.append(f" {d}: ❌") - - perms.append(" channels:") - - for child in channel.channels: - if isinstance(child, TextChannel): - typ = "text" - elif isinstance(child, ForumChannel): - typ = "forum" - elif isinstance(child, VoiceChannel): - typ = "voice" - elif isinstance(child, StageChannel): - typ = "stage" - else: - typ = "unknown" - - string.append(f" {typ} channel `{child.name}`:") - string.append(f" id: {child.id}") - - child_perms = [] - - for child_thing, child_overwrites in child.overwrites.items(): - if isinstance(child_thing, Role): - typ = "role" - name = child_thing.name - elif isinstance(child_thing, Member): - typ = "member" - name = f"{child_thing.name}#{child_thing.discriminator}" - else: - typ = repr(child_thing.type) - name = "unknown" - - child_perms.append(f" {typ} {name}:") - child_perms.append(f" id: {child_thing.id}") - - allow, deny = [], [] - - for perm, value in overwrites._values.items(): - channel_corresponding_value = child_overwrites._values.get(perm) - - unique = value is not channel_corresponding_value - if not unique: - continue - - if value is True: - allow.append(perm) - elif value is False: - deny.append(perm) - - if allow or deny: - string.append(" permissions:") - - for a in allow: - string.append(f" {a}: ✅") - for d in deny: - string.append(f" {d}: ❌") - - if child_perms: - string.append(" permissions:") - string.extend(child_perms) + if perms: string.append(" permissions:") string.extend(perms) + + # Category perms end. + + # Channel perms start. + + string.append(" channels:") + + for child in channel.channels: + if isinstance(child, TextChannel): + typ = "text" + elif isinstance(child, ForumChannel): + typ = "forum" + elif isinstance(child, VoiceChannel): + typ = "voice" + elif isinstance(child, StageChannel): + typ = "stage" + else: + typ = "unknown" + + string.append(f" {typ} channel `{child.name}`: {child.id}") + + child_perms = [] + + for child_thing, child_overwrites in child.overwrites.items(): + if isinstance(child_thing, Role): + typ = "role" + name = child_thing.name + elif isinstance(child_thing, Member): + typ = "member" + name = f"{child_thing.name}#{child_thing.discriminator}" + else: + typ = repr(child_thing.type) + name = "unknown" + + allow, deny = [], [] + + for perm, value in overwrites._values.items(): + channel_corresponding_value = child_overwrites._values.get(perm) + + unique = value is not channel_corresponding_value + if not unique: + continue + + if value is True: + allow.append(perm) + elif value is False: + deny.append(perm) + + if allow or deny: + child_perms.append(f" {typ} {name}: {child_thing.id}") + string.append(" permissions:") + + for a in allow: + string.append(f" {a}: ✅") + for d in deny: + string.append(f" {d}: ❌") + + if child_perms: + string.append(" permissions:") + string.extend(child_perms) + + # Child perms end. else: if isinstance(channel, TextChannel): @@ -165,9 +169,10 @@ class Utils(Cog): else: typ = "unknown" - string.append(f"{typ} channel `{channel.name}`:") - string.append(f" id: {channel.id}") + string.append(f"{typ} channel `{channel.name}`: {channel.id}") + # Root perms start. + # " permissions:" perms = [] for thing, overwrites in channel.overwrites.items(): @@ -181,9 +186,6 @@ class Utils(Cog): typ = repr(thing.type) name = "unknown" - string.append(f" {typ} {name}:") - string.append(f" id: {thing.id}") - allow, deny = [], [] for perm, value in overwrites._values.items(): @@ -193,16 +195,19 @@ class Utils(Cog): deny.append(perm) if allow or deny: - string.append(" permissions:") + string.append(f" {typ} {name}: {thing.id}") + string.append(" permissions:") for a in allow: - string.append(f" {a}: ✅") + string.append(f" {a}: ✅") for d in deny: - string.append(f" {d}: ❌") + string.append(f" {d}: ❌") if perms: string.append(" permissions:") string.extend(perms) + + # Root perms end. await ctx.reply( file=File(