mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-04-22 16:51:59 +00:00
Expose _ActivityTag as BaseActivity to easily refer to.
This commit is contained in:
parent
a841efa087
commit
42a084028c
@ -33,6 +33,7 @@ from .partial_emoji import PartialEmoji
|
||||
from .utils import _get_as_snowflake
|
||||
|
||||
__all__ = (
|
||||
'BaseActivity',
|
||||
'Activity',
|
||||
'Streaming',
|
||||
'Game',
|
||||
@ -85,7 +86,24 @@ t.ActivityFlags = {
|
||||
}
|
||||
"""
|
||||
|
||||
class _ActivityTag:
|
||||
class BaseActivity:
|
||||
"""The base activity that all user-settable activities inherit from.
|
||||
A user-settable activity is one that can be used in :meth:`Client.change_presence`.
|
||||
|
||||
The following types currently count as user-settable:
|
||||
|
||||
- :class:`Activity`
|
||||
- :class:`Game`
|
||||
- :class:`Streaming`
|
||||
- :class:`CustomActivity`
|
||||
|
||||
Note that although these types are considered user-settable by the library,
|
||||
Discord typically ignores certain combinations of activity depending on
|
||||
what is currently set. This behaviour may change in the future so there are
|
||||
no guarantees on whether Discord will actually let you set these types.
|
||||
|
||||
.. versionadded:: 1.3.0
|
||||
"""
|
||||
__slots__ = ('_created_at',)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
@ -100,7 +118,7 @@ class _ActivityTag:
|
||||
if self._created_at is not None:
|
||||
return datetime.datetime.utcfromtimestamp(self._created_at / 1000)
|
||||
|
||||
class Activity(_ActivityTag):
|
||||
class Activity(BaseActivity):
|
||||
"""Represents an activity in Discord.
|
||||
|
||||
This could be an activity such as streaming, playing, listening
|
||||
@ -257,7 +275,7 @@ class Activity(_ActivityTag):
|
||||
return self.assets.get('small_text', None)
|
||||
|
||||
|
||||
class Game(_ActivityTag):
|
||||
class Game(BaseActivity):
|
||||
"""A slimmed down version of :class:`Activity` that represents a Discord game.
|
||||
|
||||
This is typically displayed via **Playing** on the official Discord client.
|
||||
@ -369,7 +387,7 @@ class Game(_ActivityTag):
|
||||
def __hash__(self):
|
||||
return hash(self.name)
|
||||
|
||||
class Streaming(_ActivityTag):
|
||||
class Streaming(BaseActivity):
|
||||
"""A slimmed down version of :class:`Activity` that represents a Discord streaming status.
|
||||
|
||||
This is typically displayed via **Streaming** on the official Discord client.
|
||||
@ -627,7 +645,7 @@ class Spotify:
|
||||
""":class:`str`: The party ID of the listening party."""
|
||||
return self._party.get('id', '')
|
||||
|
||||
class CustomActivity(_ActivityTag):
|
||||
class CustomActivity(BaseActivity):
|
||||
"""Represents a Custom activity from Discord.
|
||||
|
||||
.. container:: operations
|
||||
|
@ -45,7 +45,7 @@ from .member import Member
|
||||
from .errors import *
|
||||
from .enums import Status, VoiceRegion
|
||||
from .gateway import *
|
||||
from .activity import _ActivityTag, create_activity
|
||||
from .activity import BaseActivity, create_activity
|
||||
from .voice_client import VoiceClient
|
||||
from .http import HTTPClient
|
||||
from .state import ConnectionState
|
||||
@ -147,7 +147,7 @@ class Client:
|
||||
must be used to fetch the offline members of the guild.
|
||||
status: Optional[:class:`.Status`]
|
||||
A status to start your presence with upon logging on to Discord.
|
||||
activity: Optional[Union[:class:`.Activity`, :class:`.Game`, :class:`.Streaming`]]
|
||||
activity: Optional[:class:`BaseActivity`]
|
||||
An activity to start your presence with upon logging on to Discord.
|
||||
heartbeat_timeout: :class:`float`
|
||||
The maximum numbers of seconds before timing out and restarting the
|
||||
@ -647,7 +647,7 @@ class Client:
|
||||
|
||||
@property
|
||||
def activity(self):
|
||||
"""Optional[Union[:class:`.Activity`, :class:`.Game`, :class:`.Streaming`]]: The activity being used upon
|
||||
"""Optional[:class:`BaseActivity`]: The activity being used upon
|
||||
logging in.
|
||||
"""
|
||||
return create_activity(self._connection._activity)
|
||||
@ -656,10 +656,10 @@ class Client:
|
||||
def activity(self, value):
|
||||
if value is None:
|
||||
self._connection._activity = None
|
||||
elif isinstance(value, _ActivityTag):
|
||||
elif isinstance(value, BaseActivity):
|
||||
self._connection._activity = value.to_dict()
|
||||
else:
|
||||
raise TypeError('activity must be one of Game, Streaming, or Activity.')
|
||||
raise TypeError('activity must derive from BaseActivity.')
|
||||
|
||||
# helpers/getters
|
||||
|
||||
@ -918,7 +918,7 @@ class Client:
|
||||
|
||||
Parameters
|
||||
----------
|
||||
activity: Optional[Union[:class:`.Game`, :class:`.Streaming`, :class:`.Activity`]]
|
||||
activity: Optional[:class:`BaseActivity`]
|
||||
The activity being done. ``None`` if no currently active activity is done.
|
||||
status: Optional[:class:`.Status`]
|
||||
Indicates what status to change to. If ``None``, then
|
||||
|
@ -38,7 +38,7 @@ import zlib
|
||||
import websockets
|
||||
|
||||
from . import utils
|
||||
from .activity import _ActivityTag
|
||||
from .activity import BaseActivity
|
||||
from .enums import SpeakingState
|
||||
from .errors import ConnectionClosed, InvalidArgument
|
||||
|
||||
@ -490,8 +490,8 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
||||
|
||||
async def change_presence(self, *, activity=None, status=None, afk=False, since=0.0):
|
||||
if activity is not None:
|
||||
if not isinstance(activity, _ActivityTag):
|
||||
raise InvalidArgument('activity must be one of Game, Streaming, or Activity.')
|
||||
if not isinstance(activity, BaseActivity):
|
||||
raise InvalidArgument('activity must derive from BaseActivity.')
|
||||
activity = activity.to_dict()
|
||||
|
||||
if status == 'idle':
|
||||
|
@ -150,7 +150,7 @@ class Member(discord.abc.Messageable, _BaseUser):
|
||||
joined_at: Optional[:class:`datetime.datetime`]
|
||||
A datetime object that specifies the date and time in UTC that the member joined the guild for
|
||||
the first time. In certain cases, this can be ``None``.
|
||||
activities: Tuple[Union[:class:`Game`, :class:`Streaming`, :class:`Spotify`, :class:`Activity`]]
|
||||
activities: Tuple[Union[:class:`BaseActivity`, :class:`Spotify`]]
|
||||
The activities that the user is currently doing.
|
||||
guild: :class:`Guild`
|
||||
The guild that the member belongs to.
|
||||
@ -381,7 +381,7 @@ class Member(discord.abc.Messageable, _BaseUser):
|
||||
|
||||
@property
|
||||
def activity(self):
|
||||
"""Union[:class:`Game`, :class:`Streaming`, :class:`Spotify`, :class:`Activity`]: Returns the primary
|
||||
"""Union[:class:`BaseActivity`, :class:`Spotify`]: Returns the primary
|
||||
activity the user is currently doing. Could be None if no activity is being done.
|
||||
|
||||
.. note::
|
||||
|
@ -311,7 +311,7 @@ class AutoShardedClient(Client):
|
||||
|
||||
Parameters
|
||||
----------
|
||||
activity: Optional[Union[:class:`Game`, :class:`Streaming`, :class:`Activity`]]
|
||||
activity: Optional[:class:`BaseActivity`]
|
||||
The activity being done. ``None`` if no currently active activity is done.
|
||||
status: Optional[:class:`Status`]
|
||||
Indicates what status to change to. If ``None``, then
|
||||
|
@ -36,7 +36,7 @@ import inspect
|
||||
import gc
|
||||
|
||||
from .guild import Guild
|
||||
from .activity import _ActivityTag
|
||||
from .activity import BaseActivity
|
||||
from .user import User, ClientUser
|
||||
from .emoji import Emoji
|
||||
from .partial_emoji import PartialEmoji
|
||||
@ -83,8 +83,8 @@ class ConnectionState:
|
||||
|
||||
activity = options.get('activity', None)
|
||||
if activity:
|
||||
if not isinstance(activity, _ActivityTag):
|
||||
raise TypeError('activity parameter must be one of Game, Streaming, or Activity.')
|
||||
if not isinstance(activity, BaseActivity):
|
||||
raise TypeError('activity parameter must derive from BaseActivity.')
|
||||
|
||||
activity = activity.to_dict()
|
||||
|
||||
|
@ -113,7 +113,7 @@ class WidgetMember(BaseUser):
|
||||
The member's nickname.
|
||||
avatar: Optional[:class:`str`]
|
||||
The member's avatar hash.
|
||||
activity: Optional[Union[:class:`Activity`, :class:`Game`, :class:`Streaming`, :class:`Spotify`]]
|
||||
activity: Optional[Union[:class:`BaseActivity`, :class:`Spotify`]]
|
||||
The member's activity.
|
||||
deafened: Optional[:class:`bool`]
|
||||
Whether the member is currently deafened.
|
||||
|
Loading…
x
Reference in New Issue
Block a user