-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiscordrpc.py
40 lines (35 loc) · 1.27 KB
/
discordrpc.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
'''
Communication with Discord, updating User status.
'''
import pypresence
import errors
import logging
class Discord():
def __init__(self, log):
self.client = pypresence.Presence('1056071283491749928')
if log:
self.logging = True
logging.getLogger(__name__) ## set up logger if the -log flag is set
def set_user(self, user_name):
self.user_name = user_name
def connect(self):
try:
logging.info('Attempting to establish connection to Discord.')
self.client.connect()
except ConnectionRefusedError:
logging.error("Couldn't find an active Discord instance.")
raise errors.DiscordError() from None
logging.info('Connection to Discord established.')
def update(self, large_image, small_image, status, start=None):
try:
self.client.update(
large_image=large_image,
small_image=small_image,
details=status,
start=start
)
logging.info(f'Status: {status}')
except pypresence.exceptions.InvalidID:
if self.logging:
logging.error("Couldn't find active Discord instance.")
raise errors.DiscordError() from None