Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/twitchio/message.py
7774 views
"""1The MIT License (MIT)23Copyright (c) 2017-2021 TwitchIO45Permission is hereby granted, free of charge, to any person obtaining a6copy of this software and associated documentation files (the "Software"),7to deal in the Software without restriction, including without limitation8the rights to use, copy, modify, merge, publish, distribute, sublicense,9and/or sell copies of the Software, and to permit persons to whom the10Software is furnished to do so, subject to the following conditions:1112The above copyright notice and this permission notice shall be included in13all copies or substantial portions of the Software.1415THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS16OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE18AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER19LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING20FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER21DEALINGS IN THE SOFTWARE.22"""2324import datetime25import time26from typing import TYPE_CHECKING, Union2728if TYPE_CHECKING:29from .channel import Channel30from .chatter import Chatter, PartialChatter313233class Message:34"""35Attributes36-----------37content: :class:`str`38The content of this message.39echo: :class:`bool`40Boolean representing if this is a self-message or not.4142"""4344__slots__ = (45"_raw_data",46"content",47"_author",48"echo",49"_timestamp",50"_channel",51"_tags",52"_id",53)5455def __init__(self, **kwargs):56self._raw_data = kwargs.get("raw_data")57self.content = kwargs.get("content")58self._author = kwargs.get("author")59self._channel = kwargs.get("channel")60self._tags = kwargs.get("tags")61self.echo = kwargs.get("echo", False)6263try:64self._id = self._tags["id"]65self._timestamp = self._tags["tmi-sent-ts"]66except KeyError:67self._id = None68self._timestamp = datetime.datetime.now().timestamp() * 10006970@property71def id(self) -> str:72"""The Message ID."""73return self._id7475@property76def author(self) -> Union["Chatter", "PartialChatter"]:77"""The User object associated with the Message."""78return self._author7980@property81def channel(self) -> "Channel":82"""The Channel object associated with the Message."""83return self._channel8485@property86def raw_data(self) -> str:87"""The raw data received from Twitch for this Message."""88return self._raw_data8990@property91def tags(self) -> dict:92"""The tags associated with the Message.9394Could be None.95"""96return self._tags9798@property99def timestamp(self) -> datetime.datetime:100"""The Twitch timestamp for this Message.101102Returns103---------104timestamp:105UTC datetime object of the Twitch timestamp.106"""107return datetime.datetime.utcfromtimestamp(int(self._timestamp) / 1000)108109110