Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_TinkoffBotTwitch-main/venv/lib/python3.8/site-packages/twitchio/message.py
7774 views
1
"""
2
The MIT License (MIT)
3
4
Copyright (c) 2017-2021 TwitchIO
5
6
Permission is hereby granted, free of charge, to any person obtaining a
7
copy of this software and associated documentation files (the "Software"),
8
to deal in the Software without restriction, including without limitation
9
the rights to use, copy, modify, merge, publish, distribute, sublicense,
10
and/or sell copies of the Software, and to permit persons to whom the
11
Software is furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22
DEALINGS IN THE SOFTWARE.
23
"""
24
25
import datetime
26
import time
27
from typing import TYPE_CHECKING, Union
28
29
if TYPE_CHECKING:
30
from .channel import Channel
31
from .chatter import Chatter, PartialChatter
32
33
34
class Message:
35
"""
36
Attributes
37
-----------
38
content: :class:`str`
39
The content of this message.
40
echo: :class:`bool`
41
Boolean representing if this is a self-message or not.
42
43
"""
44
45
__slots__ = (
46
"_raw_data",
47
"content",
48
"_author",
49
"echo",
50
"_timestamp",
51
"_channel",
52
"_tags",
53
"_id",
54
)
55
56
def __init__(self, **kwargs):
57
self._raw_data = kwargs.get("raw_data")
58
self.content = kwargs.get("content")
59
self._author = kwargs.get("author")
60
self._channel = kwargs.get("channel")
61
self._tags = kwargs.get("tags")
62
self.echo = kwargs.get("echo", False)
63
64
try:
65
self._id = self._tags["id"]
66
self._timestamp = self._tags["tmi-sent-ts"]
67
except KeyError:
68
self._id = None
69
self._timestamp = datetime.datetime.now().timestamp() * 1000
70
71
@property
72
def id(self) -> str:
73
"""The Message ID."""
74
return self._id
75
76
@property
77
def author(self) -> Union["Chatter", "PartialChatter"]:
78
"""The User object associated with the Message."""
79
return self._author
80
81
@property
82
def channel(self) -> "Channel":
83
"""The Channel object associated with the Message."""
84
return self._channel
85
86
@property
87
def raw_data(self) -> str:
88
"""The raw data received from Twitch for this Message."""
89
return self._raw_data
90
91
@property
92
def tags(self) -> dict:
93
"""The tags associated with the Message.
94
95
Could be None.
96
"""
97
return self._tags
98
99
@property
100
def timestamp(self) -> datetime.datetime:
101
"""The Twitch timestamp for this Message.
102
103
Returns
104
---------
105
timestamp:
106
UTC datetime object of the Twitch timestamp.
107
"""
108
return datetime.datetime.utcfromtimestamp(int(self._timestamp) / 1000)
109
110