Skip to content

Commit a785675

Browse files
committed
Add new pinned chat receiving over IRC
1 parent c882f54 commit a785675

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

docs/reference.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,13 @@ Goal
223223
:members:
224224
:inherited-members:
225225

226+
HypeChatData
227+
228+
.. attributetable:: HypeChatData
229+
230+
.. autoclass:: HypeChatData
231+
:members:
232+
226233
HypeTrainContribution
227234
-----------------------
228235
.. attributetable:: HypeTrainContribution

twitchio/message.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,36 @@
2323
"""
2424

2525
import datetime
26-
from typing import TYPE_CHECKING, Union
26+
from typing import TYPE_CHECKING, Union, Optional
2727

2828
if TYPE_CHECKING:
2929
from .channel import Channel
3030
from .chatter import Chatter, PartialChatter
3131

32+
class HypeChatData:
33+
"""
34+
Represents information about hype chats.
35+
36+
Attributes
37+
-----------
38+
amount: :class:`int`
39+
The amount paid.
40+
canonical_amount: :class:`int`
41+
The canonical amount paid(?) # FIXME: figure this out before next version release
42+
currency: :class:`str`
43+
The currency paid in, in standard form (eg. USD, EUR, GBP).
44+
is_system_message: :class:`bool`
45+
Whether this Hype Chat originated from a user or Twitch.
46+
level: :class:`str`
47+
The level this Hype Chat reached. For some reason this is a spelled out number (ex ``TWO``).
48+
"""
49+
50+
def __init__(self, tags: dict) -> None:
51+
self.amount: int = int(tags["pinned-chat-paid-amount"])
52+
self.canonical_amount: int = int(tags["pinned-chat-paid-canonical-amount"])
53+
self.currency: str = tags["pinned-chat-paid-currency"]
54+
self.is_system_message: bool = tags["pinned-chat-paid-is-system-message"] == "1"
55+
self.level: str = tags["pinned-chat-paid-level"]
3256

3357
class Message:
3458
"""
@@ -40,12 +64,14 @@ class Message:
4064
Boolean representing if this is a self-message or not.
4165
first: :class:`bool`
4266
Boolean representing whether it's a first message or not.
43-
67+
hype_chat_data: Optional[:class:`HypeChatData`]
68+
Any hype chat information associated with the message. This will be ``None`` when the message is not a hype chat.
4469
"""
4570

4671
__slots__ = (
4772
"_raw_data",
4873
"content",
74+
"hype_chat_data",
4975
"_author",
5076
"echo",
5177
"first",
@@ -76,6 +102,11 @@ def __init__(self, **kwargs):
76102
self._id = None
77103
self._timestamp = datetime.datetime.now().timestamp() * 1000
78104

105+
if "pinned-chat-paid-amount" in self._tags:
106+
self.hype_chat_data: Optional[HypeChatData] = HypeChatData(self._tags)
107+
else:
108+
self.hype_chat_data: Optional[HypeChatData] = None
109+
79110
@property
80111
def id(self) -> str:
81112
"""The Message ID."""

0 commit comments

Comments
 (0)