Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@property
def channel(self):
"""The channel associated with the user."""
return self._channel
def _fetch_channel(self):
return self._name # Abstract method
def _fetch_websocket(self):
return self._ws # Abstract method
def _bot_is_mod(self):
return False
class User(Messageable):
__slots__ = ('_name', '_channel', '_tags', '_ws', '_bot', 'id', '_turbo', '_sub', '_mod',
'_display_name', '_colour')
__messageable_channel__ = False
def __init__(self, websocket, **kwargs):
self._name = kwargs.get('name')
self._channel = kwargs.get('channel', self._name)
self._tags = kwargs.get('tags', None)
self._ws = websocket
self._bot = kwargs.get('bot')
if not self._tags:
return
self.id = self._tags.get('user-id')
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from .abcs import Messageable
class PartialUser(Messageable):
__messageable_channel__ = False
def __init__(self, websocket, **kwargs):
self._name = kwargs.get('name')
self._ws = websocket
self._bot = kwargs.get('bot')
self._channel = kwargs.get('channel', self._name)
def __str__(self):
return self._name
def __repr__(self):
return f''
def __eq__(self, other):
Could be an empty Dict if no tags were received.
"""
return self._tags
@property
def is_mod(self) -> bool:
"""A boolean indicating whether the User is a moderator of the current channel."""
if self._mod == 1:
return True
if self.channel.name == self.display_name.lower():
return True
else:
return False
class Context(Messageable):
"""
The context of which a command is invoked under.
Attributes
------------
author : :class:`.User`
The author of the command.
prefix : str
The prefix associated with the command.
message : :class:`.Message`
The message associated with the command.
channel : :class:`.Channel`
The channel associated with the command.
command : :class:`twitchio.ext.core.Command`
The command which was invoked.
return self._tags
@property
def timestamp(self) -> datetime.datetime.timestamp:
"""The Twitch timestamp for this Message.
Returns
---------
timestamp:
UTC datetime object of the Twitch timestamp.
"""
timestamp = datetime.datetime.utcfromtimestamp(int(self._timestamp) / 1000)
return timestamp
class Channel(Messageable):
__slots__ = ('_channel', '_ws', '_http', '_echo', '_users')
def __init__(self, name, ws, http):
self._channel = name
self._http = http
self._ws = ws
self._echo = False
self._users = {}
def __str__(self):
return self._channel
@property
def name(self) -> str:
"""The channel name."""
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
"""
from typing import Optional
from .abcs import Messageable
class Channel(Messageable):
__slots__ = ('_name', '_ws', '_bot')
__messageable_channel__ = True
def __init__(self, **kwargs):
self._name = kwargs.get('name')
self._ws = kwargs.get('websocket')
self._bot = kwargs.get('bot')
def __eq__(self, other):
return other.name == self._name
def __hash__(self):
return hash(self.name)