|
14 | 14 | from .channel import Channel, ChannelType, Thread
|
15 | 15 | from .member import Member
|
16 | 16 | from .message import Emoji, Sticker
|
17 |
| -from .misc import Image, Overwrite, Snowflake |
| 17 | +from .misc import ( |
| 18 | + AutoModAction, |
| 19 | + AutoModTriggerMetadata, |
| 20 | + AutoModTriggerType, |
| 21 | + Image, |
| 22 | + Overwrite, |
| 23 | + Snowflake, |
| 24 | +) |
18 | 25 | from .presence import PresenceActivity
|
19 | 26 | from .role import Role
|
20 | 27 | from .team import Application
|
@@ -1932,6 +1939,179 @@ async def get_webhooks(self) -> List[Webhook]:
|
1932 | 1939 |
|
1933 | 1940 | return [Webhook(**_, _client=self._client) for _ in res]
|
1934 | 1941 |
|
| 1942 | + async def list_auto_moderation_rules(self) -> List["AutoModerationRule"]: # noqa |
| 1943 | + """ |
| 1944 | + Lists all AutoMod rules |
| 1945 | + """ |
| 1946 | + if not self._client: |
| 1947 | + raise LibraryException(code=13) |
| 1948 | + |
| 1949 | + from .gw import AutoModerationRule |
| 1950 | + |
| 1951 | + res = await self._client.list_auto_moderation_rules(int(self.id)) |
| 1952 | + |
| 1953 | + return [AutoModerationRule(**_) for _ in res] |
| 1954 | + |
| 1955 | + async def get_auto_moderation_rule( |
| 1956 | + self, rule_id: Union[int, Snowflake] |
| 1957 | + ) -> "AutoModerationRule": # noqa |
| 1958 | + """ |
| 1959 | + Gets a AutoMod rule from its ID |
| 1960 | +
|
| 1961 | + :param rule_id: The ID of the rule to get |
| 1962 | + :type rule_id: Union[int, Snowflake] |
| 1963 | + :return: A AutoMod rule |
| 1964 | + :rtype: AutoModerationRule |
| 1965 | + """ |
| 1966 | + if not self._client: |
| 1967 | + raise LibraryException(code=13) |
| 1968 | + |
| 1969 | + from .gw import AutoModerationRule |
| 1970 | + |
| 1971 | + res = await self._client.get_auto_moderation_rule(int(self.id), int(rule_id)) |
| 1972 | + |
| 1973 | + return AutoModerationRule(**res) |
| 1974 | + |
| 1975 | + async def create_auto_moderation_rule( |
| 1976 | + self, |
| 1977 | + name: str, |
| 1978 | + # event_type: int, # only 1 exists |
| 1979 | + trigger_type: AutoModTriggerType, |
| 1980 | + actions: List[AutoModAction], |
| 1981 | + trigger_metadata: Optional[AutoModTriggerMetadata] = MISSING, |
| 1982 | + enabled: Optional[bool] = False, |
| 1983 | + exempt_roles: Optional[List[int]] = MISSING, |
| 1984 | + exempt_channels: Optional[List[int]] = MISSING, |
| 1985 | + reason: Optional[str] = None, |
| 1986 | + ) -> "AutoModerationRule": # noqa |
| 1987 | + """ |
| 1988 | + Creates an AutoMod rule |
| 1989 | +
|
| 1990 | + :param name: The name of the new rule. |
| 1991 | + :type name: str |
| 1992 | + :param trigger_type: The trigger type of the new rule. |
| 1993 | + :type trigger_type: AutoModTriggerType |
| 1994 | + :param trigger_metadata: The trigger metadata payload representation. This can be omitted based on the trigger type. |
| 1995 | + :type trigger_metadata: Optional[AutoModTriggerMetadata] |
| 1996 | + :param actions: The actions that will execute when the rule is triggered. |
| 1997 | + :type actions: List[AutoModAction] |
| 1998 | + :param enabled: Whether the rule will be enabled upon creation. False by default. |
| 1999 | + :type enabled: Optional[bool] |
| 2000 | + :param exempt_roles: The role IDs that are whitelisted by the rule, if given. The maximum is 20. |
| 2001 | + :type exempt_roles: Optional[List[int]] |
| 2002 | + :param exempt_channels: The channel IDs that are whitelisted by the rule, if given. The maximum is 20 |
| 2003 | + :type exempt_channels: Optional[List[int]] |
| 2004 | + :param reason: The reason of the creation |
| 2005 | + :type reason: Optional[str] |
| 2006 | + :return: The new AutoMod rule |
| 2007 | + :rtype: AutoModerationRule |
| 2008 | + """ |
| 2009 | + |
| 2010 | + if not self._client: |
| 2011 | + raise LibraryException(code=13) |
| 2012 | + |
| 2013 | + from .gw import AutoModerationRule |
| 2014 | + |
| 2015 | + event_type = 1 |
| 2016 | + _actions = None if actions is MISSING else [_._json for _ in actions] |
| 2017 | + _trigger_metadata = None if trigger_metadata is MISSING else trigger_metadata._json |
| 2018 | + _trigger_type = ( |
| 2019 | + None |
| 2020 | + if trigger_type is MISSING |
| 2021 | + else trigger_type |
| 2022 | + if isinstance(trigger_type, int) |
| 2023 | + else trigger_type.value |
| 2024 | + ) |
| 2025 | + |
| 2026 | + res = await self._client.create_auto_moderation_rule( |
| 2027 | + guild_id=int(self.id), |
| 2028 | + event_type=event_type, |
| 2029 | + actions=_actions, |
| 2030 | + trigger_type=_trigger_type, |
| 2031 | + trigger_metadata=_trigger_metadata, |
| 2032 | + name=name, |
| 2033 | + enabled=enabled, |
| 2034 | + exempt_roles=exempt_roles, |
| 2035 | + exempt_channels=exempt_channels, |
| 2036 | + reason=reason, |
| 2037 | + ) |
| 2038 | + |
| 2039 | + return AutoModerationRule(**res) |
| 2040 | + |
| 2041 | + async def modify_auto_moderation_rule( |
| 2042 | + self, |
| 2043 | + rule: Union[int, Snowflake, "AutoModerationRule"], # noqa |
| 2044 | + name: str = MISSING, |
| 2045 | + # event_type: int, # only 1 exists |
| 2046 | + trigger_type: AutoModTriggerType = MISSING, |
| 2047 | + actions: List[AutoModAction] = MISSING, |
| 2048 | + trigger_metadata: Optional[AutoModTriggerMetadata] = MISSING, |
| 2049 | + enabled: Optional[bool] = MISSING, |
| 2050 | + exempt_roles: Optional[List[int]] = MISSING, |
| 2051 | + exempt_channels: Optional[List[int]] = MISSING, |
| 2052 | + reason: Optional[str] = None, |
| 2053 | + ) -> "AutoModerationRule": # noqa |
| 2054 | + """ |
| 2055 | + Edits an AutoMod rule |
| 2056 | +
|
| 2057 | + :param rule: The rule to modify |
| 2058 | + :type rule: Union[int, Snowflake, AutoModerationRule] |
| 2059 | + :param name: The name of the new rule. |
| 2060 | + :type name: str |
| 2061 | + :param trigger_type: The trigger type of the new rule. |
| 2062 | + :type trigger_type: AutoModTriggerType |
| 2063 | + :param trigger_metadata: The trigger metadata payload representation. This can be omitted based on the trigger type. |
| 2064 | + :type trigger_metadata: Optional[AutoModTriggerMetadata] |
| 2065 | + :param actions: The actions that will execute when the rule is triggered. |
| 2066 | + :type actions: List[AutoModAction] |
| 2067 | + :param enabled: Whether the rule will be enabled upon creation. False by default. |
| 2068 | + :type enabled: Optional[bool] |
| 2069 | + :param exempt_roles: The role IDs that are whitelisted by the rule, if given. The maximum is 20. |
| 2070 | + :type exempt_roles: Optional[List[int]] |
| 2071 | + :param exempt_channels: The channel IDs that are whitelisted by the rule, if given. The maximum is 20 |
| 2072 | + :type exempt_channels: Optional[List[int]] |
| 2073 | + :param reason: The reason of the creation |
| 2074 | + :type reason: Optional[str] |
| 2075 | + :return: The new AutoMod rule |
| 2076 | + :rtype: AutoModerationRule |
| 2077 | + """ |
| 2078 | + |
| 2079 | + if not self._client: |
| 2080 | + raise LibraryException(code=13) |
| 2081 | + |
| 2082 | + from .gw import AutoModerationRule |
| 2083 | + |
| 2084 | + if isinstance(rule, (int, Snowflake)): |
| 2085 | + rule = await self.get_auto_moderation_rule(rule) |
| 2086 | + |
| 2087 | + event_type = 1 |
| 2088 | + |
| 2089 | + _actions = actions if actions is not MISSING else [_._json for _ in rule.actions] |
| 2090 | + _trigger_type = trigger_type if trigger_type is not MISSING else rule.trigger_type |
| 2091 | + _trigger_metadata = ( |
| 2092 | + trigger_metadata if trigger_metadata is not MISSING else rule.trigger_metadata._json |
| 2093 | + ) |
| 2094 | + _name = name if name is not MISSING else rule.name |
| 2095 | + _enabled = enabled if enabled is not MISSING else rule.enabled |
| 2096 | + _exempt_roles = exempt_roles if exempt_roles is not MISSING else rule.exempt_roles |
| 2097 | + _exempt_channels = ( |
| 2098 | + exempt_channels if exempt_channels is not MISSING else rule.exempt_channels |
| 2099 | + ) |
| 2100 | + |
| 2101 | + res = await self._client.create_auto_moderation_rule( |
| 2102 | + guild_id=int(self.id), |
| 2103 | + event_type=event_type, |
| 2104 | + actions=_actions, |
| 2105 | + trigger_type=_trigger_type, |
| 2106 | + trigger_metadata=_trigger_metadata, |
| 2107 | + name=_name, |
| 2108 | + enabled=_enabled, |
| 2109 | + exempt_roles=_exempt_roles, |
| 2110 | + exempt_channels=_exempt_channels, |
| 2111 | + reason=reason, |
| 2112 | + ) |
| 2113 | + return AutoModerationRule(**res) |
| 2114 | + |
1935 | 2115 | @property
|
1936 | 2116 | def icon_url(self) -> Optional[str]:
|
1937 | 2117 | """
|
|
0 commit comments