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
14 changes: 8 additions & 6 deletions DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.<br>
> You won’t see them yourself — but other users will see them correctly.

## class `discordrpc.utils`
- variable `discordrpc.utils.timestamp()`<br>
Expand Down
31 changes: 3 additions & 28 deletions discordrpc/button.py
Original file line number Diff line number Diff line change
@@ -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
return {"label": text, "url": url}
3 changes: 3 additions & 0 deletions discordrpc/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 5 additions & 8 deletions examples/rpc-with-button.py
Original file line number Diff line number Diff line change
@@ -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"),
]
)


Expand Down