Skip to content

Activity

attrs class ActivityTimestamps (DictSerializationMixin)

Attr attributes:

Name Type Description
start Optional[naff.models.discord.timestamp.Timestamp]

The start time of the activity. Shows "elapsed" timer on discord client.

end Optional[naff.models.discord.timestamp.Timestamp]

The end time of the activity. Shows "remaining" timer on discord client.

Source code in naff/models/discord/activity.py
@define()
class ActivityTimestamps(DictSerializationMixin):
    start: Optional[Timestamp] = field(default=None, converter=optional(timestamp_converter))
    """The start time of the activity. Shows "elapsed" timer on discord client."""
    end: Optional[Timestamp] = field(default=None, converter=optional(timestamp_converter))
    """The end time of the activity. Shows "remaining" timer on discord client."""

inherited method update_from_dict(self, data)

Updates object attribute(s) with new json data received from discord api.

Parameters:

Name Type Description Default
data Dict[str, Any]

The json data received from discord api.

required

Returns:

Type Description
~T

The updated object class instance.

Source code in naff/models/discord/activity.py
def update_from_dict(self: Type[const.T], data: Dict[str, Any]) -> const.T:
    """
    Updates object attribute(s) with new json data received from discord api.

    Args:
        data: The json data received from discord api.

    Returns:
        The updated object class instance.

    """
    data = self._process_dict(data)
    for key, value in self._filter_kwargs(data, self._get_keys()).items():
        # todo improve
        setattr(self, key, value)

    return self

inherited method to_dict(self)

Exports object into dictionary representation, ready to be sent to discord api.

Returns:

Type Description
Dict[str, Any]

The exported dictionary.

Source code in naff/models/discord/activity.py
def to_dict(self) -> Dict[str, Any]:
    """
    Exports object into dictionary representation, ready to be sent to discord api.

    Returns:
        The exported dictionary.

    """
    self._check_object()
    return serializer.to_dict(self)

attrs class ActivityParty (DictSerializationMixin)

Attr attributes:

Name Type Description
id Optional[str]

A unique identifier for this party

size Optional[List[int]]

Info about the size of the party

Source code in naff/models/discord/activity.py
@define()
class ActivityParty(DictSerializationMixin):
    id: Optional[str] = field(default=None)
    """A unique identifier for this party"""
    size: Optional[List[int]] = field(default=None)
    """Info about the size of the party"""

inherited method update_from_dict(self, data)

Updates object attribute(s) with new json data received from discord api.

Parameters:

Name Type Description Default
data Dict[str, Any]

The json data received from discord api.

required

Returns:

Type Description
~T

The updated object class instance.

Source code in naff/models/discord/activity.py
def update_from_dict(self: Type[const.T], data: Dict[str, Any]) -> const.T:
    """
    Updates object attribute(s) with new json data received from discord api.

    Args:
        data: The json data received from discord api.

    Returns:
        The updated object class instance.

    """
    data = self._process_dict(data)
    for key, value in self._filter_kwargs(data, self._get_keys()).items():
        # todo improve
        setattr(self, key, value)

    return self

inherited method to_dict(self)

Exports object into dictionary representation, ready to be sent to discord api.

Returns:

Type Description
Dict[str, Any]

The exported dictionary.

Source code in naff/models/discord/activity.py
def to_dict(self) -> Dict[str, Any]:
    """
    Exports object into dictionary representation, ready to be sent to discord api.

    Returns:
        The exported dictionary.

    """
    self._check_object()
    return serializer.to_dict(self)

attrs class ActivityAssets (DictSerializationMixin)

Attr attributes:

Name Type Description
large_image Optional[str]

The large image for this activity. Uses discord's asset image url format.

large_text Optional[str]

Hover text for the large image

small_image Optional[str]

The large image for this activity. Uses discord's asset image url format.

small_text Optional[str]

Hover text for the small image

Source code in naff/models/discord/activity.py
@define()
class ActivityAssets(DictSerializationMixin):
    large_image: Optional[str] = field(default=None)
    """The large image for this activity. Uses discord's asset image url format."""
    large_text: Optional[str] = field(default=None)
    """Hover text for the large image"""
    small_image: Optional[str] = field(default=None)
    """The large image for this activity. Uses discord's asset image url format."""
    small_text: Optional[str] = field(default=None)
    """Hover text for the small image"""

inherited method update_from_dict(self, data)

Updates object attribute(s) with new json data received from discord api.

Parameters:

Name Type Description Default
data Dict[str, Any]

The json data received from discord api.

required

Returns:

Type Description
~T

The updated object class instance.

Source code in naff/models/discord/activity.py
def update_from_dict(self: Type[const.T], data: Dict[str, Any]) -> const.T:
    """
    Updates object attribute(s) with new json data received from discord api.

    Args:
        data: The json data received from discord api.

    Returns:
        The updated object class instance.

    """
    data = self._process_dict(data)
    for key, value in self._filter_kwargs(data, self._get_keys()).items():
        # todo improve
        setattr(self, key, value)

    return self

inherited method to_dict(self)

Exports object into dictionary representation, ready to be sent to discord api.

Returns:

Type Description
Dict[str, Any]

The exported dictionary.

Source code in naff/models/discord/activity.py
def to_dict(self) -> Dict[str, Any]:
    """
    Exports object into dictionary representation, ready to be sent to discord api.

    Returns:
        The exported dictionary.

    """
    self._check_object()
    return serializer.to_dict(self)

attrs class ActivitySecrets (DictSerializationMixin)

Attr attributes:

Name Type Description
join Optional[str]

The secret for joining a party

spectate Optional[str]

The secret for spectating a party

match Optional[str]

The secret for a specific instanced match

Source code in naff/models/discord/activity.py
@define()
class ActivitySecrets(DictSerializationMixin):
    join: Optional[str] = field(default=None)
    """The secret for joining a party"""
    spectate: Optional[str] = field(default=None)
    """The secret for spectating a party"""
    match: Optional[str] = field(default=None)
    """The secret for a specific instanced match"""

inherited method update_from_dict(self, data)

Updates object attribute(s) with new json data received from discord api.

Parameters:

Name Type Description Default
data Dict[str, Any]

The json data received from discord api.

required

Returns:

Type Description
~T

The updated object class instance.

Source code in naff/models/discord/activity.py
def update_from_dict(self: Type[const.T], data: Dict[str, Any]) -> const.T:
    """
    Updates object attribute(s) with new json data received from discord api.

    Args:
        data: The json data received from discord api.

    Returns:
        The updated object class instance.

    """
    data = self._process_dict(data)
    for key, value in self._filter_kwargs(data, self._get_keys()).items():
        # todo improve
        setattr(self, key, value)

    return self

inherited method to_dict(self)

Exports object into dictionary representation, ready to be sent to discord api.

Returns:

Type Description
Dict[str, Any]

The exported dictionary.

Source code in naff/models/discord/activity.py
def to_dict(self) -> Dict[str, Any]:
    """
    Exports object into dictionary representation, ready to be sent to discord api.

    Returns:
        The exported dictionary.

    """
    self._check_object()
    return serializer.to_dict(self)

attrs class Activity (DictSerializationMixin)

Represents a discord activity object use for rich presence in discord.

Attr attributes:

Name Type Description
name str

The activity's name

type ActivityType

The type of activity

url Optional[str]

Stream url, is validated when type is 1

created_at Optional[naff.models.discord.timestamp.Timestamp]

When the activity was added to the user's session

timestamps Optional[naff.models.discord.activity.ActivityTimestamps]

Start and/or end of the game

application_id Snowflake_Type

Application id for the game

details Optional[str]

What the player is currently doing

state Optional[str]

The user's current party status

emoji Optional[naff.models.discord.emoji.PartialEmoji]

The emoji used for a custom status

party Optional[naff.models.discord.activity.ActivityParty]

Information for the current party of the player

assets Optional[naff.models.discord.activity.ActivityAssets]

Assets to display on the player's profile

secrets Optional[naff.models.discord.activity.ActivitySecrets]

Secrets for Rich Presence joining and spectating

instance Optional[bool]

Whether or not the activity is an instanced game session

flags Optional[naff.models.discord.enums.ActivityFlags]

Activity flags bitwise OR together, describes what the payload includes

buttons List[str]

The custom buttons shown in the Rich Presence (max 2)

Source code in naff/models/discord/activity.py
@define(kw_only=False)
class Activity(DictSerializationMixin):
    """Represents a discord activity object use for rich presence in discord."""

    name: str = field(repr=True)
    """The activity's name"""
    type: ActivityType = field(repr=True, default=ActivityType.GAME)
    """The type of activity"""
    url: Optional[str] = field(repr=True, default=None)
    """Stream url, is validated when type is 1"""
    created_at: Optional[Timestamp] = field(repr=True, default=None, converter=optional(timestamp_converter))
    """When the activity was added to the user's session"""
    timestamps: Optional[ActivityTimestamps] = field(default=None, converter=optional(ActivityTimestamps.from_dict))
    """Start and/or end of the game"""
    application_id: "Snowflake_Type" = field(default=None)
    """Application id for the game"""
    details: Optional[str] = field(default=None)
    """What the player is currently doing"""
    state: Optional[str] = field(default=None)
    """The user's current party status"""
    emoji: Optional[PartialEmoji] = field(default=None, converter=optional(PartialEmoji.from_dict))
    """The emoji used for a custom status"""
    party: Optional[ActivityParty] = field(default=None, converter=optional(ActivityParty.from_dict))
    """Information for the current party of the player"""
    assets: Optional[ActivityAssets] = field(default=None, converter=optional(ActivityAssets.from_dict))
    """Assets to display on the player's profile"""
    secrets: Optional[ActivitySecrets] = field(default=None, converter=optional(ActivitySecrets.from_dict))
    """Secrets for Rich Presence joining and spectating"""
    instance: Optional[bool] = field(default=False)
    """Whether or not the activity is an instanced game session"""
    flags: Optional[ActivityFlags] = field(default=None, converter=optional(ActivityFlags))
    """Activity flags bitwise OR together, describes what the payload includes"""
    buttons: List[str] = field(factory=list)
    """The custom buttons shown in the Rich Presence (max 2)"""

    @classmethod
    def create(cls, name: str, type: ActivityType = ActivityType.GAME, url: Optional[str] = None) -> "Activity":
        """
        Creates an activity object for the bot.

        Args:
            name: The new activity's name
            type: Type of activity to create
            url: Stream link for the activity

        Returns:
            The new activity object

        """
        return cls(name=name, type=type, url=url)  # noqa

    def to_dict(self) -> dict:
        return dict_filter_none({"name": self.name, "type": self.type, "url": self.url})

inherited method update_from_dict(self, data)

Updates object attribute(s) with new json data received from discord api.

Parameters:

Name Type Description Default
data Dict[str, Any]

The json data received from discord api.

required

Returns:

Type Description
~T

The updated object class instance.

Source code in naff/models/discord/activity.py
def update_from_dict(self: Type[const.T], data: Dict[str, Any]) -> const.T:
    """
    Updates object attribute(s) with new json data received from discord api.

    Args:
        data: The json data received from discord api.

    Returns:
        The updated object class instance.

    """
    data = self._process_dict(data)
    for key, value in self._filter_kwargs(data, self._get_keys()).items():
        # todo improve
        setattr(self, key, value)

    return self

classmethod method create(name, type, url)

Creates an activity object for the bot.

Parameters:

Name Type Description Default
name str

The new activity's name

required
type ActivityType

Type of activity to create

<ActivityType.GAME: 0>
url Optional[str]

Stream link for the activity

None

Returns:

Type Description
Activity

The new activity object

Source code in naff/models/discord/activity.py
@classmethod
def create(cls, name: str, type: ActivityType = ActivityType.GAME, url: Optional[str] = None) -> "Activity":
    """
    Creates an activity object for the bot.

    Args:
        name: The new activity's name
        type: Type of activity to create
        url: Stream link for the activity

    Returns:
        The new activity object

    """
    return cls(name=name, type=type, url=url)  # noqa

method to_dict(self)

Exports object into dictionary representation, ready to be sent to discord api.

Returns:

Type Description
dict

The exported dictionary.

Source code in naff/models/discord/activity.py
def to_dict(self) -> dict:
    return dict_filter_none({"name": self.name, "type": self.type, "url": self.url})