diff --git a/DOCS.md b/DOCS.md index d66c334..4b2b71a 100644 --- a/DOCS.md +++ b/DOCS.md @@ -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.Button` for more easier. + - buttons (`list`) : list of dicts for buttons on user's profile. You can use `discordrpc.Button` for more easier. Return : nothing. @@ -127,12 +127,14 @@ Examples can be seen in the repository (`Discord-RPC/examples`) or [here](https: Simplified button payload in `RPC.set_activity` Parameters : - - button_one_label (`str`) : Label for button one. - - button_one_url (`str`) : Url for button one. - - button_two_label (`str`) : Label for button two. - - button_two_url (`str`) : Url for button two. + - text (`test`) + - text (`url`) - Return : List of button dict. + Return : Payload dict. + +> [!NOTE] +> Discord does not display buttons in your own Activity.
+> You won’t see them yourself — but other users will see them correctly. ## class `discordrpc.utils` - variable `discordrpc.utils.timestamp()`
diff --git a/discordrpc/button.py b/discordrpc/button.py index b053e00..56334bd 100644 --- a/discordrpc/button.py +++ b/discordrpc/button.py @@ -1,32 +1,7 @@ from .exceptions import * -valid_url = ["https://", "http://"] -def _payload(label:str, url:str): - if any(v in url for v in valid_url): - payloads = {"label": label, "url": url} - return payloads - else: +def Button(text:str, url:str) -> dict: + if not url.startswith(("http://", "https://")): raise InvalidURL - - -def Button( - button_one_label:str, - button_one_url:str, - button_two_label:str, - button_two_url:str): - - if button_one_label == None: - raise ButtonError('"button_one_label" cannot None') - if button_one_url == None: - raise ButtonError('"button_one_url" cannot None') - if button_two_label == None: - raise ButtonError('"button_two_label" cannot None') - if button_two_url == None: - raise ButtonError('"button_two_url" cannot None') - - btn_one = _payload(label=button_one_label, url=button_one_url) - btn_two = _payload(label=button_two_label, url=button_two_url) - payloads = [btn_one, btn_two] - - return payloads \ No newline at end of file + return {"label": text, "url": url} diff --git a/discordrpc/presence.py b/discordrpc/presence.py index fba93b3..901c700 100644 --- a/discordrpc/presence.py +++ b/discordrpc/presence.py @@ -71,6 +71,9 @@ def set_activity( invalidType = ["1", "4"] if any(invtype in str(act_type) for invtype in invalidType): raise InvalidActivityType() + + if len(buttons) > 2: + raise ButtonError("Max 2 buttons allowed") act = { "state": state, diff --git a/examples/rpc-with-button.py b/examples/rpc-with-button.py index 388b307..2e710b2 100644 --- a/examples/rpc-with-button.py +++ b/examples/rpc-with-button.py @@ -1,19 +1,16 @@ import discordrpc -from discordrpc.button import Button +from discordrpc import Button rpc = discordrpc.RPC(app_id=1234567891011) -button = Button( - button_one_label="Repository", - button_one_url="https://github.com/Senophyx/discord-rpc", - button_two_label="Discord Server", - button_two_url="https://discord.gg/qpT2AeYZRN" - ) rpc.set_activity( state="Made by Senophyx", details="Discord-RPC", - buttons=button + buttons=[ + Button("Repository", "https://github.com/Senophyx/discord-rpc"), + Button("Discord", "https://discord.gg/qpT2AeYZRN"), + ] )