Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https:
Parameters :
- state (`str`)
- details (`str`)
- act_type (`int`) : [Activity Types](https://discord.com/developers/docs/topics/gateway-events#activity-object-activity-types) (Activity Type `1` and `4` is currently disabled, see [#28](https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350)).
- act_type (`discordrpc.Activity`) : [Activity Types](https://discord.com/developers/docs/topics/gateway-events#activity-object-activity-types) (Activity Type `1` and `4` is currently disabled, see [#28](https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350)).
- ts_start (`int`) : Timestamp start.
- ts_end (`int`) : Timestamp end.
- large_image (`str`) : The name of the image that has been uploaded to the Discord Developer Portal.
Expand Down Expand Up @@ -122,6 +122,23 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https:
Return : `True` or `False`


## class `discordrpc.Activity`
- Enum `Activity`<br>
Simplified Activity type payload in `RPC.set_activity`

Available values :
- Playing
- Streaming
- Listening
- Watching
- Custom
- Competing

> [!NOTE]
> Activity Type `Streaming` and `Custom` currently disabled.<br>
> [Details](https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350)


## class `discordrpc.Button()`
- function `Button()`<br>
Simplified button payload in `RPC.set_activity`
Expand Down
1 change: 1 addition & 0 deletions discordrpc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .presence import RPC
from .button import Button
from .exceptions import *
from .types import *
from .utils import timestamp, date_to_timestamp

__title__ = "Discord RPC"
Expand Down
6 changes: 5 additions & 1 deletion discordrpc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class ButtonError(RPCException):
def __init__(self, message: str = None):
super().__init__(message=message)

# https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350
class InvalidActivityType(RPCException):
def __init__(self, message):
super().__init__(f"Activity type must be <Activity>, not {message}")

# https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350
class ActivityTypeDisabled(RPCException):
def __init__(self):
super().__init__(f"Activity Type 1 and 4 currently disabled. See https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350")
11 changes: 7 additions & 4 deletions discordrpc/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uuid
import re
from .exceptions import *
from .types import *
from .utils import remove_none
import logging
import time
Expand Down Expand Up @@ -55,7 +56,7 @@ def _setup(self):

def set_activity(
self,
state: str=None, details:str=None, act_type:int=0,
state: str=None, details:str=None, act_type:Activity=Activity.Playing,
ts_start:int=None, ts_end:int=None,
large_image:str=None, large_text:str=None,
small_image:str=None, small_text:str=None,
Expand All @@ -67,15 +68,17 @@ def set_activity(
if type(party_id) == int:
party_id = str(party_id)

if type(act_type) != Activity:
raise InvalidActivityType(type(act_type))

# https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350
invalidType = ["1", "4"]
if any(invtype in str(act_type) for invtype in invalidType):
if act_type in [Activity.Streaming, Activity.Custom]:
raise InvalidActivityType()

act = {
"state": state,
"details": details,
"type": act_type,
"type": act_type.value,
"timestamps": {
"start": ts_start,
"end": ts_end
Expand Down
11 changes: 11 additions & 0 deletions discordrpc/types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from enum import Enum


# https://discord.com/developers/docs/events/gateway-events#activity-object-activity-types
class Activity(Enum):
Playing = 0
Streaming = 1
Listening = 2
Watching = 3
Custom = 4
Competing = 5
21 changes: 21 additions & 0 deletions examples/rpc-with-activitytype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import discordrpc
from discordrpc import Activity
import time


rpc = discordrpc.RPC(app_id=123456789)


current_time = int(time.time())
finish_time = current_time + 200

rpc.set_activity(
state="With activity type",
details="Music",
act_type=Activity.Listening,
ts_start=current_time,
ts_end=finish_time
)


rpc.run()