Fix README code block and format code (#52)
This commit is contained in:
parent
6fd1f93bab
commit
dd6cf9ad9e
@ -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
|
||||
|
@ -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'<MemberCacheFlags value={self.value}>'
|
||||
return f"<MemberCacheFlags value={self.value}>"
|
||||
|
||||
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:
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user