-
Notifications
You must be signed in to change notification settings - Fork 73
/
activity.py
67 lines (51 loc) · 2.77 KB
/
activity.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
from time import time
from .exceptions import PyPresenceException
from .payloads import Payload
from .presence import Presence
from .response import Response
from .utils import remove_none
class Activity:
def __init__(self, client: Presence, pid: int = os.getpid(),
state: str = None, details: str = None,
start: int = None, end: int = None,
large_image: str = None, large_text: str = None,
small_image: str = None, small_text: str = None,
party_id: str = None, party_size: list = None,
join: str = None, spectate: str = None,
match: str = None, instance: bool = True):
self.payload = Payload.set_activity(pid, state, details, start, end, large_image, large_text,
small_image, small_text, party_id, party_size, join, spectate,
match, instance, _rn=False)
self.p_properties = ('pid', 'state', 'details', 'start', 'end', 'large_image', 'large_text', 'small_image', 'small_text', 'party_id', 'party_size', 'join', 'spectate', 'match', 'instance')
self.response = Response.from_dict(self.payload.data)
if not isinstance(client, Presence):
raise NotImplementedError
self.client = client
def __setattr__(self, name, value):
p = getattr(self, 'p_properties', None)
r = getattr(self, 'response', None)
if p and name in p:
r.set_prop(name,value)
payload = remove_none(self.response.to_dict())
self.client.update(_donotuse=payload)
else:
self.__dict__[name] = value
def __getattr__(self, name):
p = object.__getattribute__(self, 'p_properties')
r = object.__getattribute__(self, 'response')
if p and name in p:
return r.get_prop(name)
return getattr(self, name, None)
def started_at(self, seconds_ago: int):
if seconds_ago < 0 or not isinstance(seconds_ago, int):
raise PyPresenceException('Must be a positive integer of how many seconds it has been since the start of the activity.')
self.start = int(time()) - seconds_ago
def end_in(self, time_until_end: int):
if time_until_end < 0 or not isinstance(time_until_end, int):
raise PyPresenceException('Must be a positive integer of how many seconds the activity will end in.')
self.end = int(time()) + time_until_end
# This SHOULD work, but is untested. Currently unsure if how I've done
# this is "right"... When you do Activity.state = 'my state here', it
# should call Presence.update() with a working payload. Had to do a bit
# of a hack to make it easier and ended up easing the Response class because it