|
53 | 53 | from .models.charity import CharityCampaign, CharityDonation |
54 | 54 | from .models.chat import ChannelEmote, ChatBadge, ChatSettings, Chatters, SentMessage, SharedChatSession, UserEmote |
55 | 55 | from .models.clips import Clip, CreatedClip |
| 56 | + from .models.eventsub_ import ChannelChatMessageEvent, ChatMessageBadge |
56 | 57 | from .models.goals import Goal |
57 | 58 | from .models.hype_train import HypeTrainEvent |
58 | 59 | from .models.moderation import ( |
@@ -101,6 +102,17 @@ def __init__(self, id: str | int, name: str | None = None, *, http: HTTPClient) |
101 | 102 | def __repr__(self) -> str: |
102 | 103 | return f"<PartialUser id={self.id}, name={self.name}>" |
103 | 104 |
|
| 105 | + def __str__(self) -> str: |
| 106 | + return self.name or "..." |
| 107 | + |
| 108 | + @property |
| 109 | + def mention(self) -> str: |
| 110 | + """Property returning the users name formatted to mention them in chat. |
| 111 | +
|
| 112 | + E.g. "@kappa" |
| 113 | + """ |
| 114 | + return f"@{self}" |
| 115 | + |
104 | 116 | async def start_commercial(self, *, length: int, token_for: str) -> CommercialStart: |
105 | 117 | """Starts a commercial on the specified channel. |
106 | 118 |
|
@@ -858,10 +870,10 @@ def fetch_user_emotes( |
858 | 870 | max_results=max_results, |
859 | 871 | ) |
860 | 872 |
|
861 | | - async def fetch_chat_badges(self, token_for: str | None = None) -> list[ChatBadge]: |
| 873 | + async def fetch_badges(self, token_for: str | None = None) -> list[ChatBadge]: |
862 | 874 | """Fetches the broadcaster's list of custom chat badges. |
863 | 875 |
|
864 | | - If you wish to fetch globally available chat badges use If you wish to fetch a specific broadcaster's chat badges use [`client.fetch_chat_badges`][twitchio.client.fetch_chat_badges] |
| 876 | + If you wish to fetch globally available chat badges use If you wish to fetch a specific broadcaster's chat badges use [`client.fetch_badges`][twitchio.client.fetch_badges] |
865 | 877 |
|
866 | 878 | Parameters |
867 | 879 | ---------- |
@@ -3480,3 +3492,97 @@ def _to_dict(self) -> dict[str, dict[str, dict[str, bool | str | int | None]]]: |
3480 | 3492 | "overlay": {str(i + 1): overlay._to_dict() for i, overlay in enumerate(self.overlays)}, |
3481 | 3493 | "component": {str(i + 1): component._to_dict() for i, component in enumerate(self.components)}, |
3482 | 3494 | } |
| 3495 | + |
| 3496 | + |
| 3497 | +class Chatter(PartialUser): |
| 3498 | + __slots__ = ( |
| 3499 | + "__dict__", |
| 3500 | + "_is_staff", |
| 3501 | + "_is_admin", |
| 3502 | + "_is_broadcaster", |
| 3503 | + "_is_moderator", |
| 3504 | + "_is_verified", |
| 3505 | + "_is_vip", |
| 3506 | + "_is_artist_badge", |
| 3507 | + "_is_founder", |
| 3508 | + "_is_subscriber", |
| 3509 | + "_is_no_audio", |
| 3510 | + "_is_no_video", |
| 3511 | + "_is_turbo", |
| 3512 | + "_is_premium", |
| 3513 | + "channel", |
| 3514 | + ) |
| 3515 | + |
| 3516 | + def __init__( |
| 3517 | + self, |
| 3518 | + payload: ChannelChatMessageEvent, |
| 3519 | + *, |
| 3520 | + http: HTTPClient, |
| 3521 | + broadcaster: PartialUser, |
| 3522 | + badges: list[ChatMessageBadge], |
| 3523 | + ) -> None: |
| 3524 | + super().__init__(id=payload["chatter_user_id"], name=payload["chatter_user_login"], http=http) |
| 3525 | + |
| 3526 | + slots = [s for s in self.__slots__ if not s.startswith("__")] |
| 3527 | + for badge in badges: |
| 3528 | + name = f"_is_{badge.set_id}".replace("-", "_") |
| 3529 | + |
| 3530 | + if name in slots: |
| 3531 | + setattr(self, name, True) |
| 3532 | + |
| 3533 | + self.channel: PartialUser = broadcaster |
| 3534 | + |
| 3535 | + def __repr__(self) -> str: |
| 3536 | + return f"<Chatter id={self.id}, name={self.name}, channel={self.channel}>" |
| 3537 | + |
| 3538 | + @property |
| 3539 | + def staff(self) -> bool: |
| 3540 | + return getattr(self, "_is_staff", False) |
| 3541 | + |
| 3542 | + @property |
| 3543 | + def admin(self) -> bool: |
| 3544 | + return getattr(self, "_is_admin", False) |
| 3545 | + |
| 3546 | + @property |
| 3547 | + def broadcaster(self) -> bool: |
| 3548 | + return getattr(self, "_is_broadcaster", False) |
| 3549 | + |
| 3550 | + @property |
| 3551 | + def moderator(self) -> bool: |
| 3552 | + return getattr(self, "_is_moderator", False) or self.broadcaster |
| 3553 | + |
| 3554 | + @property |
| 3555 | + def vip(self) -> bool: |
| 3556 | + return getattr(self, "_is_vip", False) |
| 3557 | + |
| 3558 | + @property |
| 3559 | + def artist(self) -> bool: |
| 3560 | + return getattr(self, "_is_artist_badge", False) |
| 3561 | + |
| 3562 | + @property |
| 3563 | + def founder(self) -> bool: |
| 3564 | + return getattr(self, "_is_founder", False) |
| 3565 | + |
| 3566 | + @property |
| 3567 | + def subscriber(self) -> bool: |
| 3568 | + return getattr(self, "_is_subscriber", False) |
| 3569 | + |
| 3570 | + @property |
| 3571 | + def no_audio(self) -> bool: |
| 3572 | + return getattr(self, "_is_no_audio", False) |
| 3573 | + |
| 3574 | + @property |
| 3575 | + def no_video(self) -> bool: |
| 3576 | + return getattr(self, "_is_no_video", False) |
| 3577 | + |
| 3578 | + @property |
| 3579 | + def partner(self) -> bool: |
| 3580 | + return getattr(self, "_is_partner", False) |
| 3581 | + |
| 3582 | + @property |
| 3583 | + def turbo(self) -> bool: |
| 3584 | + return getattr(self, "_is_turbo", False) |
| 3585 | + |
| 3586 | + @property |
| 3587 | + def prime(self) -> bool: |
| 3588 | + return getattr(self, "_is_premium", False) |
0 commit comments