From 9abe3ce8bc40f186df9403b2ae3a6fbcc857aef0 Mon Sep 17 00:00:00 2001 From: IAmTomahawkx Date: Sun, 17 Mar 2024 07:48:19 -0700 Subject: [PATCH] run black --- twitchio/ext/eventsub/websocket.py | 4 ++-- twitchio/http.py | 2 +- twitchio/models.py | 29 ++++++++++++++++++++--------- twitchio/user.py | 7 ++++--- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/twitchio/ext/eventsub/websocket.py b/twitchio/ext/eventsub/websocket.py index 4c3d889f..cc0ce219 100644 --- a/twitchio/ext/eventsub/websocket.py +++ b/twitchio/ext/eventsub/websocket.py @@ -209,10 +209,10 @@ async def pump(self) -> None: await self.connect() return - except TypeError as e: + except TypeError as e: logger.warning(f"Received bad frame: {e.args[0]}") - if e.args[0] is None: # websocket was closed, reconnect + if e.args[0] is None: # websocket was closed, reconnect logger.info("Known bad frame, restarting connection") await self.connect() return diff --git a/twitchio/http.py b/twitchio/http.py index ec713081..104d8d6d 100644 --- a/twitchio/http.py +++ b/twitchio/http.py @@ -709,7 +709,7 @@ async def get_user_emotes(self, user_id: str, broadcaster_id: Optional[str], tok q: List = [("user_id", user_id)] if broadcaster_id: q.append(("broadcaster_id", broadcaster_id)) - + return await self.request(Route("GET", "chat/emotes/user", query=q, token=token)) async def get_stream_key(self, token: str, broadcaster_id: str): diff --git a/twitchio/models.py b/twitchio/models.py index 483f20ea..80c98797 100644 --- a/twitchio/models.py +++ b/twitchio/models.py @@ -659,7 +659,7 @@ class Emote: Represents an Emote. .. note:: - + It seems twitch is sometimes returning duplicate information from the emotes endpoint. To deduplicate your emotes, you can call ``set()`` on the list of emotes (or any other hashmap), which will remove the duplicates. @@ -667,7 +667,7 @@ class Emote: my_list_of_emotes = await user.get_user_emotes(...) deduplicated_emotes = set(my_list_of_emotes) - + Attributes ----------- id: :class:`str` @@ -701,7 +701,18 @@ class Emote: Whether this emote is available in dark theme background mode. """ - __slots__ = "id", "set_id", "owner_id", "name", "type", "scales", "format_static", "format_animated", "theme_light", "theme_dark" + __slots__ = ( + "id", + "set_id", + "owner_id", + "name", + "type", + "scales", + "format_static", + "format_animated", + "theme_light", + "theme_dark", + ) def __init__(self, data: dict) -> None: self.id: str = data["id"] @@ -714,7 +725,7 @@ def __init__(self, data: dict) -> None: self.theme_light: bool = "light" in data["theme_mode"] self.format_static: bool = "static" in data["format"] self.format_animated: bool = "animated" in data["format"] - + def url_for(self, format: Literal["static", "animated"], theme: Literal["dark", "light"], scale: str) -> str: """ Returns a cdn url that can be used to download or serve the emote on a website. @@ -729,26 +740,26 @@ def url_for(self, format: Literal["static", "animated"], theme: Literal["dark", scale: :class:`str` The scale of the emote. This should be formatted in this format: ``"1.0"``. The scales available for this emote can be checked via :attr:`~.scales`. - + Returns -------- :class:`str` """ if scale not in self.scales: raise ValueError(f"scale for this emote must be one of {', '.join(self.scales)}, not {scale}") - + if (theme == "dark" and not self.theme_dark) or (theme == "light" and not self.theme_light): raise ValueError(f"theme {theme} is not an available value for this emote") if (format == "static" and not self.format_static) or (format == "animated" and not self.format_animated): raise ValueError(f"format {format} is not an available value for this emote") - + return f"https://static-cdn.jtvnw.net/emoticons/v2/{self.id}/{format}/{theme}/{scale}" - + def __repr__(self) -> str: return f"" - def __hash__(self) -> int: # this exists so we can do set(list of emotes) to get rid of duplicates + def __hash__(self) -> int: # this exists so we can do set(list of emotes) to get rid of duplicates return hash(self.id) diff --git a/twitchio/user.py b/twitchio/user.py index 14595398..d0ab62f3 100644 --- a/twitchio/user.py +++ b/twitchio/user.py @@ -639,17 +639,17 @@ async def fetch_channel_emotes(self): data = await self._http.get_channel_emotes(str(self.id)) return [ChannelEmote(self._http, x) for x in data] - + async def fetch_user_emotes(self, token: str, broadcaster: Optional[PartialUser] = None) -> List[Emote]: """|coro| - + Fetches emotes the user has access to. Optionally, you can filter by a broadcaster. .. note:: As of writing, this endpoint seems extrememly unoptimized by twitch, and may (read: will) take a lot of API requests to load. See https://github.com/twitchdev/issues/issues/921 . - + Parameters ----------- token: :class:`str` @@ -663,6 +663,7 @@ async def fetch_user_emotes(self, token: str, broadcaster: Optional[PartialUser] List[:class:`~twitchio.Emote`] """ from .models import Emote + data = await self._http.get_user_emotes(str(self.id), broadcaster and str(broadcaster.id), token) return [Emote(d) for d in data]