From bc0b74017fa17c1650eab2f2d605cbd006674cf3 Mon Sep 17 00:00:00 2001 From: chillymosh <86857777+chillymosh@users.noreply.github.com> Date: Thu, 2 Jan 2025 19:53:50 +0000 Subject: [PATCH] More Literal changes --- twitchio/models/chat.py | 17 +++++++++++------ twitchio/models/subscriptions.py | 10 +++++----- twitchio/types_/responses.py | 4 ++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/twitchio/models/chat.py b/twitchio/models/chat.py index feaa406e..6d37ceaa 100644 --- a/twitchio/models/chat.py +++ b/twitchio/models/chat.py @@ -398,12 +398,17 @@ class ChannelEmote(Emote): The name of the emote. images: dict[str, str] Contains the image URLs for the emote. These image URLs will always provide a static (i.e., non-animated) emote image with a light background. - tier: str - This field contains the tier information only if type is set to ``subscriptions``, otherwise, it's an empty string. + tier: typing.Literal["1000", "2000", "3000"] | None + This field contains the tier information only if type is set to ``subscriptions``, otherwise it's `None`. set_id: str An ID that identifies the emote set that the emote belongs to. - type: str - The type of emote. The possible values are: ``bitstier``, ``follower``, ``subscriptions``. + type: typing.Literal["bitstier", "follower", "subscriptions"] + The type of emote. The possible values are: + + - bitstier — A custom Bits tier emote. + - follower — A custom follower emote. + - subscriptions — A custom subscriber emote. + owner: PartialUser The :class:`~twitchio.PartialUser` who owns this emote. format: list[str] @@ -419,9 +424,9 @@ class ChannelEmote(Emote): def __init__(self, data: ChannelEmotesResponseData, *, template: str, http: HTTPClient) -> None: super().__init__(data, template=template, http=http) self.images: ChannelEmotesResponseImages = data["images"] - self.tier: str = data["tier"] + self.tier: Literal["1000", "2000", "3000"] | None = data.get("tier") self.set_id: str = data["emote_set_id"] - self.type: str = data["emote_type"] + self.type: Literal["bitstier", "follower", "subscriptions"] = data["emote_type"] def __repr__(self) -> str: return f"" diff --git a/twitchio/models/subscriptions.py b/twitchio/models/subscriptions.py index e5fabf85..efd4790e 100644 --- a/twitchio/models/subscriptions.py +++ b/twitchio/models/subscriptions.py @@ -24,7 +24,7 @@ from __future__ import annotations -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, Literal from twitchio.types_.responses import ( CheckUserSubscriptionResponseData, @@ -53,7 +53,7 @@ class UserSubscription: The broadcaster being subscribed to. gift: bool A Boolean value that determines whether the subscription is a gift subscription. Is ``True`` if the subscription was gifted. - tier: int + tier: typing.Literal["1000", "2000", "3000"] The type of subscription. Possible values are: - 1000: Tier 1 @@ -78,7 +78,7 @@ def __init__( data["broadcaster_id"], data["broadcaster_login"], data["broadcaster_name"], http=http ) self.gift: bool = bool(data["is_gift"]) - self.tier: int = int(data["tier"]) + self.tier: Literal["1000", "2000", "3000"] = data["tier"] _gifter_id, _gifter_login, _gifter_display_name = ( data.get("gifter_id"), data.get("gifter_login"), @@ -96,7 +96,7 @@ def __repr__(self) -> str: @property def rounded_tier(self) -> int: """Returns the tier as a single digit. e.g. Tier 1000 = 1.""" - return round(self.tier / 1000) + return round(int(self.tier) / 1000) class BroadcasterSubscription(UserSubscription): @@ -108,7 +108,7 @@ class BroadcasterSubscription(UserSubscription): The broadcaster being subscribed to. gift: bool A Boolean value that determines whether the subscription is a gift subscription. Is ``True`` if the subscription was gifted. - tier: int + tier: typing.Literal["1000", "2000", "3000"] The type of subscription. Possible values are: - 1000: Tier 1 diff --git a/twitchio/types_/responses.py b/twitchio/types_/responses.py index ef395369..1dcfefd3 100644 --- a/twitchio/types_/responses.py +++ b/twitchio/types_/responses.py @@ -476,8 +476,8 @@ class ChannelEmotesResponseData(TypedDict): id: str name: str images: ChannelEmotesResponseImages - tier: str - emote_type: str + tier: Literal["1000", "2000", "3000"] + emote_type: Literal["bitstier", "follower", "subscriptions"] emote_set_id: str format: list[str] scale: list[str]