mirror of
https://github.com/RGBCube/minearchy-bot
synced 2025-07-27 08:57:46 +00:00
Rewrite channel_perm_tree
This commit is contained in:
parent
a99219a8c0
commit
300de3f3b2
3 changed files with 142 additions and 30 deletions
|
@ -51,7 +51,7 @@ class Miscellaneous(
|
||||||
help="Sets you as AFK.",
|
help="Sets you as AFK.",
|
||||||
)
|
)
|
||||||
async def afk(self, ctx: Context) -> None:
|
async def afk(self, ctx: Context) -> None:
|
||||||
# no error cuz it will un-afk them
|
# No error because it will un-afk the caller.
|
||||||
if ctx.author.display_name.lower().startswith("[AFK]"):
|
if ctx.author.display_name.lower().startswith("[AFK]"):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Moderation(Cog):
|
||||||
# days, hours, minutes, seconds
|
# days, hours, minutes, seconds
|
||||||
clean_time_name = self.time_values[duration[-1]]
|
clean_time_name = self.time_values[duration[-1]]
|
||||||
|
|
||||||
# this is so cursed but works
|
# This is so cursed but works.
|
||||||
await member.timeout(
|
await member.timeout(
|
||||||
TimeDelta(**{clean_time_name: time}), reason=f"Timed out by moderator {ctx.author}"
|
TimeDelta(**{clean_time_name: time}), reason=f"Timed out by moderator {ctx.author}"
|
||||||
)
|
)
|
||||||
|
@ -63,7 +63,8 @@ class Moderation(Cog):
|
||||||
" isn't specified, it uses the current channel."
|
" isn't specified, it uses the current channel."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@commands.has_permissions(manage_messages=True) # needs to be able to delete messages to run the command
|
# Needs to be able to delete messages to run the command.
|
||||||
|
@commands.has_permissions(manage_messages=True)
|
||||||
async def snipe(self, ctx: Context, channel: TextChannel | None = None) -> None:
|
async def snipe(self, ctx: Context, channel: TextChannel | None = None) -> None:
|
||||||
if channel is None:
|
if channel is None:
|
||||||
channel = ctx.channel
|
channel = ctx.channel
|
||||||
|
|
|
@ -4,7 +4,16 @@ from io import BytesIO
|
||||||
from time import monotonic as get_monotonic
|
from time import monotonic as get_monotonic
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from discord import CategoryChannel, File
|
from discord import (
|
||||||
|
CategoryChannel,
|
||||||
|
File,
|
||||||
|
ForumChannel,
|
||||||
|
Member,
|
||||||
|
Role,
|
||||||
|
StageChannel,
|
||||||
|
TextChannel,
|
||||||
|
VoiceChannel,
|
||||||
|
)
|
||||||
from discord.ext.commands import Cog, command
|
from discord.ext.commands import Cog, command
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
@ -42,39 +51,141 @@ class Utils(Cog):
|
||||||
string = []
|
string = []
|
||||||
|
|
||||||
for channel in ctx.guild.channels:
|
for channel in ctx.guild.channels:
|
||||||
ind = " "
|
# Only root level categories.
|
||||||
ind_nr = 1 if getattr(channel, "category", False) else 0
|
if hasattr(channel, "category") or channel.category is not None:
|
||||||
|
continue
|
||||||
|
|
||||||
string.append(ind*ind_nr + f"{'category' if isinstance(channel, CategoryChannel) else 'channel'} {channel.name}:")
|
if isinstance(channel, CategoryChannel):
|
||||||
|
string.append(f"category {channel.name}:")
|
||||||
|
string.append(f" id: {channel.id}")
|
||||||
|
|
||||||
if channel.permissions_synced:
|
|
||||||
string.append(ind*(ind_nr+1) + "permissions: synced")
|
|
||||||
else:
|
|
||||||
string.append(ind*(ind_nr+1) + "permissions:")
|
|
||||||
|
|
||||||
if not channel.category:
|
|
||||||
for thing, overwrites in channel.overwrites.items():
|
for thing, overwrites in channel.overwrites.items():
|
||||||
allows, denies = overwrites.pair()
|
if isinstance(thing, Role):
|
||||||
|
typ = "role"
|
||||||
|
name = thing.name
|
||||||
|
if isinstance(thing, Member):
|
||||||
|
typ = "member"
|
||||||
|
name = f"{thing.name}#{thing.discriminator}"
|
||||||
|
else:
|
||||||
|
typ = repr(thing.type)
|
||||||
|
name = "unknown"
|
||||||
|
|
||||||
for allow in allows:
|
string.append(f" {typ} {name}:")
|
||||||
string.append(ind*(ind_nr+2) + f"{allow[0]}: ✅")
|
string.append(f" id: {thing.id}")
|
||||||
for deny in denies:
|
|
||||||
string.append(ind*(ind_nr+2) + f"{deny[0]}: ❌")
|
allow, deny = [], []
|
||||||
|
|
||||||
|
for perm, value in overwrites._values.items():
|
||||||
|
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}: ❌")
|
||||||
|
|
||||||
|
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}`:")
|
||||||
|
string.append(f" id: {child.id}")
|
||||||
|
|
||||||
|
for child_thing, child_overwrites in child.overwrites.items():
|
||||||
|
if isinstance(child_thing, Role):
|
||||||
|
typ = "role"
|
||||||
|
name = child_thing.name
|
||||||
|
if isinstance(child_thing, Member):
|
||||||
|
typ = "member"
|
||||||
|
name = f"{child_thing.name}#{child_thing.discriminator}"
|
||||||
|
else:
|
||||||
|
typ = repr(child_thing.type)
|
||||||
|
name = "unknown"
|
||||||
|
|
||||||
|
string.append(f" {typ} {name}:")
|
||||||
|
string.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}: ❌")
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
if isinstance(channel, TextChannel):
|
||||||
|
typ = "text"
|
||||||
|
elif isinstance(channel, ForumChannel):
|
||||||
|
typ = "forum"
|
||||||
|
elif isinstance(channel, VoiceChannel):
|
||||||
|
typ = "voice"
|
||||||
|
elif isinstance(channel, StageChannel):
|
||||||
|
typ = "stage"
|
||||||
|
else:
|
||||||
|
typ = "unknown"
|
||||||
|
|
||||||
|
string.append(f"{typ} channel `{channel.name}`:")
|
||||||
|
string.append(f" id: {channel.id}")
|
||||||
|
|
||||||
for thing, overwrites in channel.overwrites.items():
|
for thing, overwrites in channel.overwrites.items():
|
||||||
parent_overwrites = channel.category.overwrites.get(thing)
|
if isinstance(thing, Role):
|
||||||
|
typ = "role"
|
||||||
|
name = thing.name
|
||||||
|
if isinstance(thing, Member):
|
||||||
|
typ = "member"
|
||||||
|
name = f"{thing.name}#{thing.discriminator}"
|
||||||
|
else:
|
||||||
|
typ = repr(thing.type)
|
||||||
|
name = "unknown"
|
||||||
|
|
||||||
allows, denies = overwrites.pair()
|
string.append(f" {typ} {name}:")
|
||||||
parent_allows, parent_denies = parent_overwrites.pair() if parent_overwrites else ((), ())
|
string.append(f" id: {thing.id}")
|
||||||
|
|
||||||
for allow in allows:
|
allow, deny = [], []
|
||||||
if allow not in parent_allows:
|
|
||||||
string.append(ind*(ind_nr+2) + f"{allow[0]}: ✅")
|
|
||||||
|
|
||||||
for deny in denies:
|
for perm, value in overwrites._values.items():
|
||||||
if deny not in parent_denies:
|
if value is True:
|
||||||
string.append(ind*(ind_nr+2) + f"{deny[0]}: ❌")
|
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}: ❌")
|
||||||
|
|
||||||
await ctx.reply(
|
await ctx.reply(
|
||||||
file=File(
|
file=File(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue