Fix README code block and format code (#52)

This commit is contained in:
Slipstream 2025-06-11 14:27:06 -06:00 committed by GitHub
parent 6fd1f93bab
commit dd6cf9ad9e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 21 deletions

View File

@ -134,6 +134,7 @@ async def show(ctx: AppCommandContext, key: str):
@slash_command(name="set", description="Update a setting.", parent=admin_group) @slash_command(name="set", description="Update a setting.", parent=admin_group)
async def set_setting(ctx: AppCommandContext, key: str, value: str): async def set_setting(ctx: AppCommandContext, key: str, value: str):
... ...
```
## Fetching Guilds ## Fetching Guilds
Use `Client.fetch_guild` to retrieve a guild from the Discord API if it Use `Client.fetch_guild` to retrieve a guild from the Discord API if it

View File

@ -8,10 +8,10 @@ class _MemberCacheFlagValue:
flag: int flag: int
def __init__(self, func: Callable[[Any], bool]): def __init__(self, func: Callable[[Any], bool]):
self.flag = getattr(func, 'flag', 0) self.flag = getattr(func, "flag", 0)
self.__doc__ = func.__doc__ self.__doc__ = func.__doc__
def __get__(self, instance: 'MemberCacheFlags', owner: type) -> Any: def __get__(self, instance: "MemberCacheFlags", owner: type) -> Any:
if instance is None: if instance is None:
return self return self
return instance.value & self.flag != 0 return instance.value & self.flag != 0
@ -23,23 +23,24 @@ class _MemberCacheFlagValue:
instance.value &= ~self.flag instance.value &= ~self.flag
def __repr__(self) -> str: def __repr__(self) -> str:
return f'<{self.__class__.__name__} flag={self.flag}>' return f"<{self.__class__.__name__} flag={self.flag}>"
def flag_value(flag: int) -> Callable[[Callable[[Any], bool]], _MemberCacheFlagValue]: def flag_value(flag: int) -> Callable[[Callable[[Any], bool]], _MemberCacheFlagValue]:
def decorator(func: Callable[[Any], bool]) -> _MemberCacheFlagValue: def decorator(func: Callable[[Any], bool]) -> _MemberCacheFlagValue:
setattr(func, 'flag', flag) setattr(func, "flag", flag)
return _MemberCacheFlagValue(func) return _MemberCacheFlagValue(func)
return decorator return decorator
class MemberCacheFlags: class MemberCacheFlags:
__slots__ = ('value',) __slots__ = ("value",)
VALID_FLAGS: ClassVar[Dict[str, int]] = { VALID_FLAGS: ClassVar[Dict[str, int]] = {
'joined': 1 << 0, "joined": 1 << 0,
'voice': 1 << 1, "voice": 1 << 1,
'online': 1 << 2, "online": 1 << 2,
} }
DEFAULT_FLAGS: ClassVar[int] = 1 | 2 | 4 DEFAULT_FLAGS: ClassVar[int] = 1 | 2 | 4
ALL_FLAGS: ClassVar[int] = sum(VALID_FLAGS.values()) ALL_FLAGS: ClassVar[int] = sum(VALID_FLAGS.values())
@ -48,7 +49,7 @@ class MemberCacheFlags:
self.value = self.DEFAULT_FLAGS self.value = self.DEFAULT_FLAGS
for key, value in kwargs.items(): for key, value in kwargs.items():
if key not in self.VALID_FLAGS: if key not in self.VALID_FLAGS:
raise TypeError(f'{key!r} is not a valid member cache flag.') raise TypeError(f"{key!r} is not a valid member cache flag.")
setattr(self, key, value) setattr(self, key, value)
@classmethod @classmethod
@ -67,7 +68,7 @@ class MemberCacheFlags:
return hash(self.value) return hash(self.value)
def __repr__(self) -> str: def __repr__(self) -> str:
return f'<MemberCacheFlags value={self.value}>' return f"<MemberCacheFlags value={self.value}>"
def __iter__(self) -> Iterator[Tuple[str, bool]]: def __iter__(self) -> Iterator[Tuple[str, bool]]:
for name in self.VALID_FLAGS: for name in self.VALID_FLAGS:
@ -92,17 +93,17 @@ class MemberCacheFlags:
@classmethod @classmethod
def only_joined(cls) -> MemberCacheFlags: def only_joined(cls) -> MemberCacheFlags:
"""A factory method that creates a :class:`MemberCacheFlags` with only the `joined` flag enabled.""" """A factory method that creates a :class:`MemberCacheFlags` with only the `joined` flag enabled."""
return cls._from_value(cls.VALID_FLAGS['joined']) return cls._from_value(cls.VALID_FLAGS["joined"])
@classmethod @classmethod
def only_voice(cls) -> MemberCacheFlags: def only_voice(cls) -> MemberCacheFlags:
"""A factory method that creates a :class:`MemberCacheFlags` with only the `voice` flag enabled.""" """A factory method that creates a :class:`MemberCacheFlags` with only the `voice` flag enabled."""
return cls._from_value(cls.VALID_FLAGS['voice']) return cls._from_value(cls.VALID_FLAGS["voice"])
@classmethod @classmethod
def only_online(cls) -> MemberCacheFlags: def only_online(cls) -> MemberCacheFlags:
"""A factory method that creates a :class:`MemberCacheFlags` with only the `online` flag enabled.""" """A factory method that creates a :class:`MemberCacheFlags` with only the `online` flag enabled."""
return cls._from_value(cls.VALID_FLAGS['online']) return cls._from_value(cls.VALID_FLAGS["online"])
@flag_value(1 << 0) @flag_value(1 << 0)
def joined(self) -> bool: def joined(self) -> bool:
@ -117,4 +118,4 @@ class MemberCacheFlags:
@flag_value(1 << 2) @flag_value(1 << 2)
def online(self) -> bool: def online(self) -> bool:
"""Whether to cache members that are online.""" """Whether to cache members that are online."""
return False return False

View File

@ -218,6 +218,7 @@ def requires_permissions(
return check(predicate) return check(predicate)
def has_role( def has_role(
name_or_id: str | int, name_or_id: str | int,
) -> Callable[[Callable[..., Awaitable[None]]], Callable[..., Awaitable[None]]]: ) -> Callable[[Callable[..., Awaitable[None]]], Callable[..., Awaitable[None]]]:
@ -241,9 +242,7 @@ def has_role(
raise CheckFailure("Could not resolve author to a guild member.") raise CheckFailure("Could not resolve author to a guild member.")
# Create a list of the member's role objects by looking them up in the guild's roles list # Create a list of the member's role objects by looking them up in the guild's roles list
member_roles = [ member_roles = [role for role in ctx.guild.roles if role.id in author.roles]
role for role in ctx.guild.roles if role.id in author.roles
]
if any( if any(
role.id == str(name_or_id) or role.name == name_or_id role.id == str(name_or_id) or role.name == name_or_id
@ -278,9 +277,7 @@ def has_any_role(
if not author: if not author:
raise CheckFailure("Could not resolve author to a guild member.") raise CheckFailure("Could not resolve author to a guild member.")
member_roles = [ member_roles = [role for role in ctx.guild.roles if role.id in author.roles]
role for role in ctx.guild.roles if role.id in author.roles
]
# Convert names_or_ids to a set for efficient lookup # Convert names_or_ids to a set for efficient lookup
names_or_ids_set = set(map(str, names_or_ids)) names_or_ids_set = set(map(str, names_or_ids))

View File

@ -72,7 +72,7 @@ class View:
rows: List[ActionRow] = [] rows: List[ActionRow] = []
for item in self.children: for item in self.children:
rows.append(ActionRow(components=[item])) rows.append(ActionRow(components=[item]))
return rows return rows