From 987719704d33f1c41280fbddf917dc205057f84d Mon Sep 17 00:00:00 2001 From: Super Zombi Date: Sat, 26 Jul 2025 11:11:09 +0300 Subject: [PATCH 01/10] add type User --- discordrpc/presence.py | 17 +++++++---------- discordrpc/types.py | 22 +++++++++++++++++++++- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/discordrpc/presence.py b/discordrpc/presence.py index c8ebfee..11f82fe 100644 --- a/discordrpc/presence.py +++ b/discordrpc/presence.py @@ -28,7 +28,9 @@ def __init__(self, app_id:int, debug:bool=False, output:bool=True, exit_if_disco self.app_id = str(app_id) self.exit_if_discord_close = exit_if_discord_close self.exit_on_disconnect = exit_on_disconnect - self.User={} + + self.user_data = {} + self.User = User() if debug == True: log.setLevel(logging.DEBUG) @@ -42,17 +44,12 @@ def __init__(self, app_id:int, debug:bool=False, output:bool=True, exit_if_disco def _setup(self): if sys.platform == "win32": self.ipc = WindowsPipe(self.app_id, self.exit_if_discord_close, self.exit_on_disconnect) - if not self.ipc.connected: - return - - self.User=self.ipc.handshake() - else: self.ipc = UnixPipe(self.app_id, self.exit_if_discord_close, self.exit_on_disconnect) - if not self.ipc.connected: - return - - self.User=self.ipc.handshake() + + if not self.ipc.connected: return + self.user_data = self.ipc.handshake() + self.User = User(self.user_data) def set_activity( self, diff --git a/discordrpc/types.py b/discordrpc/types.py index 31251c0..540462e 100644 --- a/discordrpc/types.py +++ b/discordrpc/types.py @@ -2,7 +2,6 @@ # https://discord.com/developers/docs/events/gateway-events#activity-object-activity-types - class Activity(Enum): Playing = 0 Streaming = 1 @@ -10,3 +9,24 @@ class Activity(Enum): Watching = 3 Custom = 4 Competing = 5 + + +class User(): + def __init__(self, data:dict=None): + data = data or {} + self.id: int = int(data.get('id', 0)) + self.username: str = data.get('username') + self.name: str = data.get('global_name') + self.avatar: str = self._parse_avatar(data) + self.bot: bool = data.get('bot', False) + self.premium_type: int = int(data.get('premium_type', 0)) # https://discord.com/developers/docs/resources/user#user-object-premium-types + + def _parse_avatar(self, data:dict, size:int=1024) -> str: + if data.get('avatar'): + ext = "gif" if data.get('avatar').startswith("a_") else "png" + return f"https://cdn.discordapp.com/avatars/{self.id}/{data.get('avatar')}.{ext}?size={size}" + else: + return f"https://cdn.discordapp.com/embed/avatars/0.png" + + def __str__(self): + return f"User({self.name})" From fe72010e4792b2f31d1f1f60d23548d44ca8c1a2 Mon Sep 17 00:00:00 2001 From: Super Zombi Date: Sat, 26 Jul 2025 11:23:19 +0300 Subject: [PATCH 02/10] Update DOCS.md --- DOCS.md | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/DOCS.md b/DOCS.md index eddc429..47e1158 100644 --- a/DOCS.md +++ b/DOCS.md @@ -79,7 +79,7 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: Parameters : - state (`str`) - details (`str`) - - 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)). + - act_type (`discordrpc.Activity`) : [Activity Types](#class-discordrpcactivity) (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. @@ -91,7 +91,7 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: - join_secret (`str`) : Secret for chat invitations and ask to join button. - spectate_secret (`str`) : Secret for spectate button. - match_secret (`str`) : Secret for for spectate and join button - - buttons (`list`) : list of dicts for buttons on user's profile. You can use `discordrpc.Button` for more easier. + - buttons (`list`) : list of dicts for buttons on user's profile. You can use [`discordrpc.Button`](#class-discordrpcbutton) for more easier. Return : `True` if rpc successfully connected. @@ -121,10 +121,15 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: Return : `True` or `False` +- variable `self.User`
+ Returns information about the user to whom the connection occurred.
+ [Available attributes](#class-discordrpcuser) + ## class `discordrpc.Activity` - Enum `Activity`
- Simplified Activity type payload in `RPC.set_activity` + Simplified Activity type payload in `RPC.set_activity`
+ [Discord docs](https://discord.com/developers/docs/topics/gateway-events#activity-object-activity-types) Available values : - Playing @@ -144,8 +149,8 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: Simplified button payload in `RPC.set_activity` Parameters : - - text (`test`) - - text (`url`) + - text (`str`) + - url (`str`) Return : Payload dict. @@ -153,6 +158,17 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: > Discord does not display buttons in your own Activity.
> You won’t see them yourself — but other users will see them correctly. + +## class `discordrpc.User()` + Attributes : + - id (`int`) + - username (`str`) + - name (`str`) + - avatar (URL `str`) + - bot (`bool`) + - premium_type (`int`) + + ## class `discordrpc.utils` - variable `discordrpc.utils.timestamp()`
Return current time in epoch timestamp (`int`). From 386d6e3233fbef0ead4131d11c65c0b31ccd9f87 Mon Sep 17 00:00:00 2001 From: Super Zombi Date: Sat, 26 Jul 2025 11:27:20 +0300 Subject: [PATCH 03/10] Create get-user.py --- examples/get-user.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 examples/get-user.py diff --git a/examples/get-user.py b/examples/get-user.py new file mode 100644 index 0000000..9fd50bd --- /dev/null +++ b/examples/get-user.py @@ -0,0 +1,10 @@ +import discordrpc + +rpc = discordrpc.RPC(app_id=1397914682659963050) + +print(rpc.User.id) +print(rpc.User.name) +print(f"@{rpc.User.username}") +print(rpc.User.avatar) + +rpc.run() From 63198a0d43e7b9f183291413f07c60b00af589d5 Mon Sep 17 00:00:00 2001 From: Super Zombi Date: Sat, 26 Jul 2025 11:33:02 +0300 Subject: [PATCH 04/10] Update DOCS.md --- DOCS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DOCS.md b/DOCS.md index 47e1158..1ab9d9e 100644 --- a/DOCS.md +++ b/DOCS.md @@ -166,7 +166,7 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: - name (`str`) - avatar (URL `str`) - bot (`bool`) - - premium_type (`int`) + - premium_type (`int`) ([details](https://discord.com/developers/docs/resources/user#user-object-premium-types)) ## class `discordrpc.utils` From 8a865ab6ed00b3274be7c0d92691779b0270a34f Mon Sep 17 00:00:00 2001 From: Super Zombi Date: Sat, 26 Jul 2025 11:59:39 +0300 Subject: [PATCH 05/10] [Add] state_url and details_url --- DOCS.md | 2 ++ discordrpc/presence.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/DOCS.md b/DOCS.md index 1ab9d9e..a6fa948 100644 --- a/DOCS.md +++ b/DOCS.md @@ -80,6 +80,8 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: - state (`str`) - details (`str`) - act_type (`discordrpc.Activity`) : [Activity Types](#class-discordrpcactivity) (Activity Type `1` and `4` is currently disabled, see [#28](https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350)). + - state_url (`str`) : URL that is linked when clicking on the state text + - details_url (`str`) : URL that is linked when clicking on the details text - 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. diff --git a/discordrpc/presence.py b/discordrpc/presence.py index 11f82fe..da856e6 100644 --- a/discordrpc/presence.py +++ b/discordrpc/presence.py @@ -54,6 +54,7 @@ def _setup(self): def set_activity( self, state: str=None, details:str=None, act_type:Activity=Activity.Playing, + state_url:str=None, details_url:str=None, ts_start:int=None, ts_end:int=None, large_image:str=None, large_text:str=None, small_image:str=None, small_text:str=None, @@ -79,6 +80,8 @@ def set_activity( "state": state, "details": details, "type": act_type.value, + "state_url": state_url, + "details_url": details_url, "timestamps": { "start": ts_start, "end": ts_end From 84a6de6f0f4ae9b6be56c3c717980364aca4ec5f Mon Sep 17 00:00:00 2001 From: Super Zombi Date: Sat, 26 Jul 2025 12:53:49 +0300 Subject: [PATCH 06/10] [Add] local_time --- DOCS.md | 5 +++-- discordrpc/presence.py | 7 ++++++- discordrpc/utils.py | 11 ++++++++--- examples/rpc-local-time.py | 11 +++++++++++ 4 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 examples/rpc-local-time.py diff --git a/DOCS.md b/DOCS.md index a6fa948..3fc30da 100644 --- a/DOCS.md +++ b/DOCS.md @@ -80,10 +80,11 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: - state (`str`) - details (`str`) - act_type (`discordrpc.Activity`) : [Activity Types](#class-discordrpcactivity) (Activity Type `1` and `4` is currently disabled, see [#28](https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350)). - - state_url (`str`) : URL that is linked when clicking on the state text - - details_url (`str`) : URL that is linked when clicking on the details text + - state_url (`str`) : URL that is linked when clicking on the state text. + - details_url (`str`) : URL that is linked when clicking on the details text. - ts_start (`int`) : Timestamp start. - ts_end (`int`) : Timestamp end. + - use_local_time (`bool`) : Display your local time. - large_image (`str`) : The name of the image that has been uploaded to the Discord Developer Portal. - large_text (`str`) : Text when user hover to `large_image`. - small_image (`str`) : The name of the image that has been uploaded to the Discord Developer Portal. diff --git a/discordrpc/presence.py b/discordrpc/presence.py index da856e6..60241fa 100644 --- a/discordrpc/presence.py +++ b/discordrpc/presence.py @@ -7,7 +7,7 @@ import re from .exceptions import * from .types import * -from .utils import remove_none +from .utils import * import logging import time @@ -56,6 +56,7 @@ def set_activity( state: str=None, details:str=None, act_type:Activity=Activity.Playing, state_url:str=None, details_url:str=None, ts_start:int=None, ts_end:int=None, + use_local_time:bool=False, large_image:str=None, large_text:str=None, small_image:str=None, small_text:str=None, party_id:str=None, party_size:list=None, @@ -75,6 +76,10 @@ def set_activity( if buttons and len(buttons) > 2: raise ButtonError("Max 2 buttons allowed") + + if use_local_time: + ts_start = ts_start_as_local_time() + ts_end = None act = { "state": state, diff --git a/discordrpc/utils.py b/discordrpc/utils.py index 1a702da..0be6991 100644 --- a/discordrpc/utils.py +++ b/discordrpc/utils.py @@ -1,5 +1,5 @@ import time -import datetime +from datetime import datetime # Credits to qwertyquerty # https://github.com/qwertyquerty/pypresence/blob/master/pypresence/utils.py#L12C1-L21C13 @@ -21,5 +21,10 @@ def remove_none(d: dict): def date_to_timestamp(date:str): return int(time.mktime( - datetime.datetime.strptime(date, "%d/%m/%Y-%H:%M:%S").timetuple() - )) \ No newline at end of file + datetime.strptime(date, "%d/%m/%Y-%H:%M:%S").timetuple() + )) + +def ts_start_as_local_time(): + now = datetime.now() + seconds_since_midnight = now.hour * 3600 + now.minute * 60 + now.second + return int(time.time()) - seconds_since_midnight diff --git a/examples/rpc-local-time.py b/examples/rpc-local-time.py new file mode 100644 index 0000000..aaec303 --- /dev/null +++ b/examples/rpc-local-time.py @@ -0,0 +1,11 @@ +import discordrpc + +rpc = discordrpc.RPC(app_id=123456789) + +rpc.set_activity( + state="Wow! It's shows my clock", + details="Local time example", + use_local_time=True +) + +rpc.run() From d11ec5a5da81759b5d43bd9c3a6515cd06068e1b Mon Sep 17 00:00:00 2001 From: Super Zombi Date: Sat, 26 Jul 2025 13:22:12 +0300 Subject: [PATCH 07/10] clear without disconnect --- DOCS.md | 5 +++++ discordrpc/presence.py | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/DOCS.md b/DOCS.md index 3fc30da..0022dbe 100644 --- a/DOCS.md +++ b/DOCS.md @@ -97,6 +97,11 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: - buttons (`list`) : list of dicts for buttons on user's profile. You can use [`discordrpc.Button`](#class-discordrpcbutton) for more easier. Return : `True` if rpc successfully connected. + +- method `RPC.clear()`
+ Clear activity status. + + Return : nothing. - method `RPC.disconnect()`
Disconnecting and closing RPC socket. diff --git a/discordrpc/presence.py b/discordrpc/presence.py index 60241fa..1a2bfc1 100644 --- a/discordrpc/presence.py +++ b/discordrpc/presence.py @@ -61,7 +61,8 @@ def set_activity( small_image:str=None, small_text:str=None, party_id:str=None, party_size:list=None, join_secret:str=None, spectate_secret:str=None, - match_secret:str=None, buttons:list=None + match_secret:str=None, buttons:list=None, + clear=False ) -> bool: if type(party_id) == int: @@ -113,7 +114,7 @@ def set_activity( 'cmd': 'SET_ACTIVITY', 'args': { 'pid': os.getpid(), - 'activity': remove_none(act) + 'activity': None if clear else remove_none(act) }, 'nonce': str(uuid.uuid4()) } @@ -133,6 +134,9 @@ def set_activity( log.error('Failed to set RPC') self.disconnect() + def clear(self): + self.set_activity(clear=True) + def disconnect(self): if not self.ipc.connected: return From cf92e0fdba97d8874493e7dc138a461c155c8d49 Mon Sep 17 00:00:00 2001 From: Super Zombi Date: Sun, 27 Jul 2025 01:24:08 +0300 Subject: [PATCH 08/10] Progressbar --- DOCS.md | 25 ++++++++++++++++++++----- discordrpc/__init__.py | 1 + discordrpc/button.py | 2 +- discordrpc/exceptions.py | 6 +++++- discordrpc/presence.py | 12 +++++++++--- discordrpc/progressbar.py | 14 ++++++++++++++ examples/rpc-with-progressbar.py | 13 +++++++++++++ 7 files changed, 63 insertions(+), 10 deletions(-) create mode 100644 discordrpc/progressbar.py create mode 100644 examples/rpc-with-progressbar.py diff --git a/DOCS.md b/DOCS.md index 0022dbe..d1ee52d 100644 --- a/DOCS.md +++ b/DOCS.md @@ -84,6 +84,7 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: - details_url (`str`) : URL that is linked when clicking on the details text. - ts_start (`int`) : Timestamp start. - ts_end (`int`) : Timestamp end. + - progressbar (`dict`) : Use [`discordrpc.Progressbar`](#function-discordrpcprogressbar). - use_local_time (`bool`) : Display your local time. - large_image (`str`) : The name of the image that has been uploaded to the Discord Developer Portal. - large_text (`str`) : Text when user hover to `large_image`. @@ -94,10 +95,10 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: - join_secret (`str`) : Secret for chat invitations and ask to join button. - spectate_secret (`str`) : Secret for spectate button. - match_secret (`str`) : Secret for for spectate and join button - - buttons (`list`) : list of dicts for buttons on user's profile. You can use [`discordrpc.Button`](#class-discordrpcbutton) for more easier. + - buttons (`list`) : list of dicts for buttons on user's profile. You can use [`discordrpc.Button`](#function-discordrpcbutton) for more easier. Return : `True` if rpc successfully connected. - + - method `RPC.clear()`
Clear activity status. @@ -152,9 +153,8 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: > [Details](https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350) -## class `discordrpc.Button()` -- function `Button()`
- Simplified button payload in `RPC.set_activity` +## function `discordrpc.Button()` +- Simplified button payload in `RPC.set_activity` Parameters : - text (`str`) @@ -167,6 +167,16 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: > You won’t see them yourself — but other users will see them correctly. +## function `discordrpc.Progressbar()` +- Simplified `ts_start` and `ts_end` payload in `RPC.set_activity` + + Parameters : + - current (`int`) + - duration (`int`) + + Return : Payload dict. + + ## class `discordrpc.User()` Attributes : - id (`int`) @@ -225,6 +235,11 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: How-to-Fix : Check if `Button` function are set correctly +- `ProgressbarError`
+ There is an error in the `Progressbar` function, usually because the first parameter (current) is more then second parameter (duration). + + How-to-Fix : Make sure that duration > current + ## Links - [Github Repository](https://github.com/Senophyx/Discord-RPC) diff --git a/discordrpc/__init__.py b/discordrpc/__init__.py index e8598b3..5e27041 100644 --- a/discordrpc/__init__.py +++ b/discordrpc/__init__.py @@ -1,5 +1,6 @@ from .presence import RPC from .button import Button +from .progressbar import Progressbar from .exceptions import * from .types import * from .utils import timestamp, date_to_timestamp diff --git a/discordrpc/button.py b/discordrpc/button.py index 154220b..de78c25 100644 --- a/discordrpc/button.py +++ b/discordrpc/button.py @@ -3,5 +3,5 @@ def Button(text:str, url:str): if not url.startswith(("http://", "https://")): - raise InvalidURL + raise InvalidURL() return {"label": text, "url": url} diff --git a/discordrpc/exceptions.py b/discordrpc/exceptions.py index 740152e..7635c03 100644 --- a/discordrpc/exceptions.py +++ b/discordrpc/exceptions.py @@ -28,6 +28,10 @@ class ButtonError(RPCException): def __init__(self, message: str = None): super().__init__(message=message) +class ProgressbarError(RPCException): + def __init__(self, message): + super().__init__(message=message) + class InvalidActivityType(RPCException): def __init__(self, message): super().__init__(f"Activity type must be , not {message}") @@ -35,4 +39,4 @@ def __init__(self, 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") \ No newline at end of file + super().__init__(f"Activity Type 1 and 4 currently disabled. See https://github.com/Senophyx/Discord-RPC/issues/28#issuecomment-2301287350") diff --git a/discordrpc/presence.py b/discordrpc/presence.py index 1a2bfc1..8d76514 100644 --- a/discordrpc/presence.py +++ b/discordrpc/presence.py @@ -56,6 +56,7 @@ def set_activity( state: str=None, details:str=None, act_type:Activity=Activity.Playing, state_url:str=None, details_url:str=None, ts_start:int=None, ts_end:int=None, + progressbar:dict=None, use_local_time:bool=False, large_image:str=None, large_text:str=None, small_image:str=None, small_text:str=None, @@ -78,7 +79,12 @@ def set_activity( if buttons and len(buttons) > 2: raise ButtonError("Max 2 buttons allowed") - if use_local_time: + if progressbar: + act_type = Activity.Listening + ts_start = progressbar["ts_start"] + ts_end = progressbar["ts_end"] + + elif use_local_time: ts_start = ts_start_as_local_time() ts_end = None @@ -228,7 +234,7 @@ def handshake(self): except KeyError: if data['code'] == 4000: - raise InvalidID + raise InvalidID() def disconnect(self): try: @@ -309,7 +315,7 @@ def handshake(self): except KeyError: if data['code'] == 4000: - raise InvalidID + raise InvalidID() def disconnect(self): try: diff --git a/discordrpc/progressbar.py b/discordrpc/progressbar.py new file mode 100644 index 0000000..67e1379 --- /dev/null +++ b/discordrpc/progressbar.py @@ -0,0 +1,14 @@ +import time +from .exceptions import * + + +def Progressbar(current:int, duration:int) -> dict: + if int(current) > int(duration): + raise ProgressbarError("Current cannot exceed Duration") + + current_time = int(time.time()) - int(current) + finish_time = current_time + int(duration) + + return { + "ts_start": current_time, "ts_end": finish_time + } diff --git a/examples/rpc-with-progressbar.py b/examples/rpc-with-progressbar.py new file mode 100644 index 0000000..1652f68 --- /dev/null +++ b/examples/rpc-with-progressbar.py @@ -0,0 +1,13 @@ +import discordrpc +from discordrpc import Progressbar + + +rpc = discordrpc.RPC(app_id=123456789) + +rpc.set_activity( + state="With Progressbar", + details="Music", + progressbar=Progressbar(50, 200) +) + +rpc.run() From 5886427db1c5a440648989bd02a0680573c44384 Mon Sep 17 00:00:00 2001 From: Super Zombi Date: Sun, 27 Jul 2025 03:04:59 +0300 Subject: [PATCH 09/10] remove hardcoded activity --- discordrpc/presence.py | 3 ++- examples/rpc-with-progressbar.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/discordrpc/presence.py b/discordrpc/presence.py index 8d76514..44d9293 100644 --- a/discordrpc/presence.py +++ b/discordrpc/presence.py @@ -80,7 +80,8 @@ def set_activity( raise ButtonError("Max 2 buttons allowed") if progressbar: - act_type = Activity.Listening + if not act_type in [Activity.Listening, Activity.Watching]: + log.warning("Progressbar works only with Activities: Listening and Watching") ts_start = progressbar["ts_start"] ts_end = progressbar["ts_end"] diff --git a/examples/rpc-with-progressbar.py b/examples/rpc-with-progressbar.py index 1652f68..cd377a9 100644 --- a/examples/rpc-with-progressbar.py +++ b/examples/rpc-with-progressbar.py @@ -1,5 +1,5 @@ import discordrpc -from discordrpc import Progressbar +from discordrpc import Activity, Progressbar rpc = discordrpc.RPC(app_id=123456789) @@ -7,6 +7,7 @@ rpc.set_activity( state="With Progressbar", details="Music", + act_type=Activity.Listening, progressbar=Progressbar(50, 200) ) From 63033c95ce3c4071d88a89dc668f8b3061fc3e8b Mon Sep 17 00:00:00 2001 From: Super Zombi Date: Tue, 29 Jul 2025 12:20:06 +0300 Subject: [PATCH 10/10] remove non-api args --- DOCS.md | 5 +++-- discordrpc/__init__.py | 2 +- discordrpc/presence.py | 14 ++------------ discordrpc/utils.py | 6 ++++-- examples/rpc-local-time.py | 6 ++++-- examples/rpc-with-progressbar.py | 4 ++-- 6 files changed, 16 insertions(+), 21 deletions(-) diff --git a/DOCS.md b/DOCS.md index 1e62309..c36d056 100644 --- a/DOCS.md +++ b/DOCS.md @@ -87,8 +87,6 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: - details_url (`str`) : URL that is linked when clicking on the details text. - ts_start (`int`) : Timestamp start. - ts_end (`int`) : Timestamp end. - - progressbar (`dict`) : Use [`discordrpc.Progressbar`](#function-discordrpcprogressbar). - - use_local_time (`bool`) : Display your local time. - large_image (`str`) : The name of the image that has been uploaded to the Discord Developer Portal. - large_text (`str`) : Text when user hover to `large_image`. - small_image (`str`) : The name of the image that has been uploaded to the Discord Developer Portal. @@ -203,6 +201,9 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: date_to_timestamp('14/06/2025-00:00:00') ``` +- function `discordrpc.utils.use_local_time()`
+ Simplified `ts_start` payload in `RPC.set_activity` + ## Exceptions & Errors - `RPCException`
diff --git a/discordrpc/__init__.py b/discordrpc/__init__.py index 5e27041..5782154 100644 --- a/discordrpc/__init__.py +++ b/discordrpc/__init__.py @@ -3,7 +3,7 @@ from .progressbar import Progressbar from .exceptions import * from .types import * -from .utils import timestamp, date_to_timestamp +from .utils import timestamp, date_to_timestamp, use_local_time __title__ = "Discord RPC" __version__ = "5.1" diff --git a/discordrpc/presence.py b/discordrpc/presence.py index 44d9293..80744ad 100644 --- a/discordrpc/presence.py +++ b/discordrpc/presence.py @@ -56,8 +56,8 @@ def set_activity( state: str=None, details:str=None, act_type:Activity=Activity.Playing, state_url:str=None, details_url:str=None, ts_start:int=None, ts_end:int=None, - progressbar:dict=None, - use_local_time:bool=False, + # progressbar:dict=None, + # use_local_time:bool=False, large_image:str=None, large_text:str=None, small_image:str=None, small_text:str=None, party_id:str=None, party_size:list=None, @@ -78,16 +78,6 @@ def set_activity( if buttons and len(buttons) > 2: raise ButtonError("Max 2 buttons allowed") - - if progressbar: - if not act_type in [Activity.Listening, Activity.Watching]: - log.warning("Progressbar works only with Activities: Listening and Watching") - ts_start = progressbar["ts_start"] - ts_end = progressbar["ts_end"] - - elif use_local_time: - ts_start = ts_start_as_local_time() - ts_end = None act = { "state": state, diff --git a/discordrpc/utils.py b/discordrpc/utils.py index 0be6991..7667048 100644 --- a/discordrpc/utils.py +++ b/discordrpc/utils.py @@ -24,7 +24,9 @@ def date_to_timestamp(date:str): datetime.strptime(date, "%d/%m/%Y-%H:%M:%S").timetuple() )) -def ts_start_as_local_time(): +def use_local_time(): now = datetime.now() seconds_since_midnight = now.hour * 3600 + now.minute * 60 + now.second - return int(time.time()) - seconds_since_midnight + return { + "ts_start": int(time.time()) - seconds_since_midnight + } diff --git a/examples/rpc-local-time.py b/examples/rpc-local-time.py index aaec303..004adfd 100644 --- a/examples/rpc-local-time.py +++ b/examples/rpc-local-time.py @@ -1,11 +1,13 @@ import discordrpc +from discordrpc import use_local_time -rpc = discordrpc.RPC(app_id=123456789) + +rpc = discordrpc.RPC(app_id=1397914682659963050) rpc.set_activity( state="Wow! It's shows my clock", details="Local time example", - use_local_time=True + **use_local_time() ) rpc.run() diff --git a/examples/rpc-with-progressbar.py b/examples/rpc-with-progressbar.py index cd377a9..0b2f2e4 100644 --- a/examples/rpc-with-progressbar.py +++ b/examples/rpc-with-progressbar.py @@ -2,13 +2,13 @@ from discordrpc import Activity, Progressbar -rpc = discordrpc.RPC(app_id=123456789) +rpc = discordrpc.RPC(app_id=1397914682659963050) rpc.set_activity( state="With Progressbar", details="Music", act_type=Activity.Listening, - progressbar=Progressbar(50, 200) + **Progressbar(50, 200) ) rpc.run()