Skip to content

Commit

Permalink
More Literal changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chillymosh committed Jan 2, 2025
1 parent 2a17329 commit bc0b740
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
17 changes: 11 additions & 6 deletions twitchio/models/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"<ChannelEmote id={self.id} name={self.name} set_id={self.set_id}>"
Expand Down
10 changes: 5 additions & 5 deletions twitchio/models/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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"),
Expand All @@ -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):
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions twitchio/types_/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit bc0b740

Please sign in to comment.