Skip to content

Commit 402bb42

Browse files
committed
buttons
1 parent 2311e25 commit 402bb42

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

examples/buttons.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from pypresence import Presence
2+
import time
3+
4+
client_id = "client_id" # Enter your Application ID here.
5+
RPC = Presence(client_id=client_id)
6+
RPC.connect()
7+
8+
9+
RPC.update(buttons=[{"label": "Website", "url": "https://qtqt.cf"}, {"label": "Server", "url": "https://discord.gg/JF3kg77"}]) # Can specify up to 2 buttons
10+
11+
while 1:
12+
time.sleep(15) #Can only update presence every 15 seconds

pypresence/client.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,12 @@ def set_activity(self, pid: int = os.getpid(),
114114
small_image: str = None, small_text: str = None,
115115
party_id: str = None, party_size: list = None,
116116
join: str = None, spectate: str = None,
117-
match: str = None, instance: bool = True):
118-
payload = Payload.set_activity(pid, state, details, start, end, large_image, large_text,
119-
small_image, small_text, party_id, party_size, join, spectate,
120-
match, instance, activity=True)
117+
match: str = None, buttons: list = None,
118+
instance: bool = True):
119+
payload = Payload.set_activity(pid=pid, state=state, details=details, start=start, end=end, large_image=large_image, large_text=large_text,
120+
small_image=small_image, small_text=small_text, party_id=party_id, party_size=party_size, join=join, spectate=spectate,
121+
match=match, buttons=buttons, instance=instance, activity=True)
122+
121123
self.send_data(1, payload)
122124
return self.loop.run_until_complete(self.read_output())
123125

pypresence/payloads.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def set_activity(cls, pid: int = os.getpid(),
2828
small_image: str = None, small_text: str = None,
2929
party_id: str = None, party_size: list = None,
3030
join: str = None, spectate: str = None,
31-
match: str = None, instance: bool = True,
32-
activity: Union[bool, None] = True,
31+
match: str = None, buttons: list = None,
32+
instance: bool = True, activity: Union[bool, None] = True,
3333
_rn: bool = True):
3434

3535
# They should already be an int because we give typehints, but some people are fucking stupid and use
@@ -65,6 +65,7 @@ def set_activity(cls, pid: int = os.getpid(),
6565
"spectate": spectate,
6666
"match": match
6767
},
68+
"buttons": buttons,
6869
"instance": instance
6970
}
7071
clear = False

pypresence/presence.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ def update(self, pid: int = os.getpid(),
1919
small_image: str = None, small_text: str = None,
2020
party_id: str = None, party_size: list = None,
2121
join: str = None, spectate: str = None,
22-
match: str = None, instance: bool = True,
22+
match: str = None, buttons: list = None,
23+
instance: bool = True,
2324
_donotuse=True):
2425

2526
if _donotuse is True:
26-
payload = Payload.set_activity(pid, state, details, start, end, large_image, large_text,
27-
small_image, small_text, party_id, party_size, join, spectate,
28-
match, instance, activity=True)
27+
payload = Payload.set_activity(pid=pid, state=state, details=details, start=start, end=end, large_image=large_image, large_text=large_text,
28+
small_image=small_image, small_text=small_text, party_id=party_id, party_size=party_size, join=join, spectate=spectate,
29+
match=match, buttons=buttons, instance=instance, activity=True)
30+
print(payload)
2931
else:
3032
payload = _donotuse
3133
self.send_data(1, payload)

pypresence/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def remove_none(d: dict):
1212
if isinstance(d[item], dict):
1313
if len(d[item]):
1414
d[item] = remove_none(d[item])
15-
else:
15+
if not len(d[item]):
1616
del d[item]
1717
elif d[item] is None:
1818
del d[item]

0 commit comments

Comments
 (0)