From dd6cf9ad9e3a040cf9228d7a33948c7d0e35be72 Mon Sep 17 00:00:00 2001 From: Slipstream Date: Wed, 11 Jun 2025 14:27:06 -0600 Subject: [PATCH] Fix README code block and format code (#52) --- README.md | 1 + disagreement/caching.py | 29 +++++++++++++------------ disagreement/ext/commands/decorators.py | 9 +++----- disagreement/ui/view.py | 2 +- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 140b60f..3661be5 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,7 @@ async def show(ctx: AppCommandContext, key: str): @slash_command(name="set", description="Update a setting.", parent=admin_group) async def set_setting(ctx: AppCommandContext, key: str, value: str): ... +``` ## Fetching Guilds Use `Client.fetch_guild` to retrieve a guild from the Discord API if it diff --git a/disagreement/caching.py b/disagreement/caching.py index 7aca2b8..e9a481f 100644 --- a/disagreement/caching.py +++ b/disagreement/caching.py @@ -8,10 +8,10 @@ class _MemberCacheFlagValue: flag: int def __init__(self, func: Callable[[Any], bool]): - self.flag = getattr(func, 'flag', 0) + self.flag = getattr(func, "flag", 0) self.__doc__ = func.__doc__ - def __get__(self, instance: 'MemberCacheFlags', owner: type) -> Any: + def __get__(self, instance: "MemberCacheFlags", owner: type) -> Any: if instance is None: return self return instance.value & self.flag != 0 @@ -23,23 +23,24 @@ class _MemberCacheFlagValue: instance.value &= ~self.flag 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 decorator(func: Callable[[Any], bool]) -> _MemberCacheFlagValue: - setattr(func, 'flag', flag) + setattr(func, "flag", flag) return _MemberCacheFlagValue(func) + return decorator class MemberCacheFlags: - __slots__ = ('value',) + __slots__ = ("value",) VALID_FLAGS: ClassVar[Dict[str, int]] = { - 'joined': 1 << 0, - 'voice': 1 << 1, - 'online': 1 << 2, + "joined": 1 << 0, + "voice": 1 << 1, + "online": 1 << 2, } DEFAULT_FLAGS: ClassVar[int] = 1 | 2 | 4 ALL_FLAGS: ClassVar[int] = sum(VALID_FLAGS.values()) @@ -48,7 +49,7 @@ class MemberCacheFlags: self.value = self.DEFAULT_FLAGS for key, value in kwargs.items(): 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) @classmethod @@ -67,7 +68,7 @@ class MemberCacheFlags: return hash(self.value) def __repr__(self) -> str: - return f'' + return f"" def __iter__(self) -> Iterator[Tuple[str, bool]]: for name in self.VALID_FLAGS: @@ -92,17 +93,17 @@ class MemberCacheFlags: @classmethod def only_joined(cls) -> MemberCacheFlags: """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 def only_voice(cls) -> MemberCacheFlags: """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 def only_online(cls) -> MemberCacheFlags: """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) def joined(self) -> bool: @@ -117,4 +118,4 @@ class MemberCacheFlags: @flag_value(1 << 2) def online(self) -> bool: """Whether to cache members that are online.""" - return False \ No newline at end of file + return False diff --git a/disagreement/ext/commands/decorators.py b/disagreement/ext/commands/decorators.py index 7400118..b2d6680 100644 --- a/disagreement/ext/commands/decorators.py +++ b/disagreement/ext/commands/decorators.py @@ -218,6 +218,7 @@ def requires_permissions( return check(predicate) + def has_role( name_or_id: str | int, ) -> Callable[[Callable[..., Awaitable[None]]], Callable[..., Awaitable[None]]]: @@ -241,9 +242,7 @@ def has_role( 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 - member_roles = [ - role for role in ctx.guild.roles if role.id in author.roles - ] + member_roles = [role for role in ctx.guild.roles if role.id in author.roles] if any( role.id == str(name_or_id) or role.name == name_or_id @@ -278,9 +277,7 @@ def has_any_role( if not author: raise CheckFailure("Could not resolve author to a guild member.") - member_roles = [ - role for role in ctx.guild.roles if role.id in author.roles - ] + member_roles = [role for role in ctx.guild.roles if role.id in author.roles] # Convert names_or_ids to a set for efficient lookup names_or_ids_set = set(map(str, names_or_ids)) diff --git a/disagreement/ui/view.py b/disagreement/ui/view.py index a1a13da..3e17b28 100644 --- a/disagreement/ui/view.py +++ b/disagreement/ui/view.py @@ -72,7 +72,7 @@ class View: rows: List[ActionRow] = [] for item in self.children: - rows.append(ActionRow(components=[item])) + rows.append(ActionRow(components=[item])) return rows