Skip to content

Commit 6c47e76

Browse files
committed
Add is_lead_moderator guard
1 parent e16d070 commit 6c47e76

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

twitchio/ext/commands/core.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"guard",
5757
"is_broadcaster",
5858
"is_elevated",
59+
"is_lead_moderator",
5960
"is_moderator",
6061
"is_owner",
6162
"is_staff",
@@ -1691,6 +1692,37 @@ def predicate(context: Context[BotT]) -> bool:
16911692
return guard(predicate)
16921693

16931694

1695+
def is_lead_moderator() -> Any:
1696+
"""|deco|
1697+
1698+
A decorator which adds a :func:`~.commands.guard` to a :class:`~.commands.Command`.
1699+
1700+
This guards adds a predicate which prevents any chatter from using a command
1701+
who does not possess the ``Lead Moderator`` badge.
1702+
1703+
See also, :func:`~.commands.is_elevated` for a guard to allow the ``broadcaster``, any ``moderator`` or ``VIP`` chatter
1704+
to use the command.
1705+
1706+
.. warning::
1707+
1708+
Due to Twitch limitations, you cannot use this Guard on a :class:`.commands.RewardCommand`. If you do, it will always
1709+
fail.
1710+
1711+
Raises
1712+
------
1713+
GuardFailure
1714+
The guard predicate returned ``False`` and prevented the chatter from using the command.
1715+
"""
1716+
1717+
def predicate(context: Context[BotT]) -> bool:
1718+
if context.type is ContextType.REWARD:
1719+
raise TypeError("This Guard can not be used on a RewardCommand instance.")
1720+
1721+
return context.chatter.lead_moderator # type: ignore
1722+
1723+
return guard(predicate)
1724+
1725+
16941726
def is_vip() -> Any:
16951727
"""|deco|
16961728

0 commit comments

Comments
 (0)