|
15 | 15 | from .channel import Channel, ChannelType, Thread, ThreadMember |
16 | 16 | from .emoji import Emoji |
17 | 17 | from .member import Member |
18 | | -from .message import Sticker |
| 18 | +from .message import Sticker, StickerPack |
19 | 19 | from .misc import ( |
20 | 20 | AutoModAction, |
21 | 21 | AutoModTriggerMetadata, |
22 | 22 | AutoModTriggerType, |
| 23 | + File, |
23 | 24 | IDMixin, |
24 | 25 | Image, |
25 | 26 | Overwrite, |
@@ -2019,6 +2020,158 @@ async def delete_emoji( |
2019 | 2020 | if int(item.id) == int(emoji_id): |
2020 | 2021 | return self.emojis.remove(item) |
2021 | 2022 |
|
| 2023 | + async def get_stickers(self) -> Optional[List[Sticker]]: |
| 2024 | + """ |
| 2025 | + Get the stickers for a guild. |
| 2026 | +
|
| 2027 | + :return: List of stickers of the guild. |
| 2028 | + :rtype: Optional[List[Sticker]] |
| 2029 | + """ |
| 2030 | + if not self._client: |
| 2031 | + raise LibraryException(code=13) |
| 2032 | + |
| 2033 | + res = await self._client.list_guild_stickers(guild_id=int(self.id)) |
| 2034 | + |
| 2035 | + stickers = [Sticker(**sticker) for sticker in res] |
| 2036 | + self.stickers = stickers |
| 2037 | + |
| 2038 | + return self.stickers |
| 2039 | + |
| 2040 | + async def get_nitro_sticker_packs(self) -> List[StickerPack]: |
| 2041 | + """ |
| 2042 | + Gets the list of sticker packs available to Nitro subscribers. |
| 2043 | +
|
| 2044 | + :return: List of sticker packs. |
| 2045 | + :rtype: List[StickerPack] |
| 2046 | + """ |
| 2047 | + if not self._client: |
| 2048 | + raise LibraryException(code=13) |
| 2049 | + |
| 2050 | + res = await self._client.list_nitro_sticker_packs() |
| 2051 | + |
| 2052 | + return [StickerPack(**sticker_pack) for sticker_pack in res["sticker_packs"]] |
| 2053 | + |
| 2054 | + async def create_sticker( |
| 2055 | + self, |
| 2056 | + file: File, |
| 2057 | + tags: str, |
| 2058 | + name: Optional[str] = MISSING, |
| 2059 | + description: Optional[str] = MISSING, |
| 2060 | + reason: Optional[str] = None, |
| 2061 | + ) -> Sticker: |
| 2062 | + """ |
| 2063 | + Creates a new sticker for the guild. |
| 2064 | +
|
| 2065 | + :param file: The file of the sticker. |
| 2066 | + :type file: File |
| 2067 | + :param tags: The tags of the sticker. |
| 2068 | + :type tags: str |
| 2069 | + :param name?: The name of the sticker. |
| 2070 | + :type name?: Optional[str] |
| 2071 | + :param description?: The description of the sticker. |
| 2072 | + :type description?: Optional[str] |
| 2073 | + :param reason?: The reason of the creation. |
| 2074 | + :type reason?: Optional[str] |
| 2075 | + :return: Created sticker for the guild. |
| 2076 | + :rtype: Sticker |
| 2077 | + """ |
| 2078 | + if not self._client: |
| 2079 | + raise LibraryException(code=13) |
| 2080 | + |
| 2081 | + _name = name if name is not MISSING else file._filename |
| 2082 | + |
| 2083 | + payload: dict = { |
| 2084 | + "name": _name, |
| 2085 | + "tags": tags, |
| 2086 | + "description": description if description is not MISSING else None, |
| 2087 | + } |
| 2088 | + |
| 2089 | + res = await self._client.create_guild_sticker( |
| 2090 | + payload=payload, file=file, guild_id=int(self.id), reason=reason |
| 2091 | + ) |
| 2092 | + |
| 2093 | + if self.stickers is None: |
| 2094 | + self.stickers = [] |
| 2095 | + |
| 2096 | + _sticker = Sticker(**res) |
| 2097 | + self.stickers.append(_sticker) |
| 2098 | + return _sticker |
| 2099 | + |
| 2100 | + async def modify_sticker( |
| 2101 | + self, |
| 2102 | + sticker_id: Union[Sticker, Snowflake, int, str], |
| 2103 | + name: Optional[str] = MISSING, |
| 2104 | + description: Optional[str] = MISSING, |
| 2105 | + reason: Optional[str] = None, |
| 2106 | + ) -> Sticker: |
| 2107 | + """ |
| 2108 | + Modifies the sticker of the guild. |
| 2109 | +
|
| 2110 | + :param sticker_id: The sticker or ID of the sticker. |
| 2111 | + :type sticker_id: Union[Sticker, Snowflake, int] |
| 2112 | + :param name?: The name of the sticker. |
| 2113 | + :type name?: Optional[str] |
| 2114 | + :param description?: The description of the sticker. |
| 2115 | + :type description?: Optional[str] |
| 2116 | + :param reason?: The reason of the modification. |
| 2117 | + :type reason?: Optional[str] |
| 2118 | + :return: Modified sticker. |
| 2119 | + :rtype: Sticker |
| 2120 | + """ |
| 2121 | + if not self._client: |
| 2122 | + raise LibraryException(code=13) |
| 2123 | + |
| 2124 | + _id = int(sticker_id.id) if isinstance(sticker_id, Sticker) else int(sticker_id) |
| 2125 | + |
| 2126 | + payload: dict = {} |
| 2127 | + |
| 2128 | + if name is not MISSING: |
| 2129 | + payload["name"] = name |
| 2130 | + if description is not MISSING: |
| 2131 | + payload["description"] = description |
| 2132 | + |
| 2133 | + res = await self._client.modify_guild_sticker( |
| 2134 | + payload=payload, guild_id=int(self.id), sticker_id=_id, reason=reason |
| 2135 | + ) |
| 2136 | + _sticker = Sticker(**res) |
| 2137 | + |
| 2138 | + if not self.stickers: |
| 2139 | + self.stickers = [_sticker] |
| 2140 | + return _sticker |
| 2141 | + |
| 2142 | + for sticker in self.stickers: |
| 2143 | + if sticker.id == _sticker.id: |
| 2144 | + sticker.update(res) |
| 2145 | + return sticker |
| 2146 | + |
| 2147 | + async def delete_sticker( |
| 2148 | + self, |
| 2149 | + sticker_id: Union[Sticker, Snowflake, int, str], |
| 2150 | + reason: Optional[str] = None, |
| 2151 | + ): |
| 2152 | + """Deletes the sticker of the guild. |
| 2153 | +
|
| 2154 | + :param sticker_id: The sticker or ID of the sticker. |
| 2155 | + :type sticker_id: Union[Sticker, Snowflake, int] |
| 2156 | + :param reason?: The reason of the deletion. |
| 2157 | + :type reason?: Optional[str] |
| 2158 | + """ |
| 2159 | + if not self._client: |
| 2160 | + raise LibraryException(code=13) |
| 2161 | + |
| 2162 | + _id = int(sticker_id.id) if isinstance(sticker_id, Sticker) else int(sticker_id) |
| 2163 | + |
| 2164 | + await self._client.delete_guild_sticker( |
| 2165 | + guild_id=int(self.id), sticker_id=_id, reason=reason |
| 2166 | + ) |
| 2167 | + |
| 2168 | + if not self.stickers: |
| 2169 | + return |
| 2170 | + for sticker in self.stickers: |
| 2171 | + if int(sticker.id) == _id: |
| 2172 | + self.stickers.remove(sticker) |
| 2173 | + break |
| 2174 | + |
2022 | 2175 | async def get_list_of_members( |
2023 | 2176 | self, |
2024 | 2177 | limit: Optional[int] = 1, |
|
0 commit comments