mirror of
https://github.com/MCMi460/3DS-RPC.git
synced 2025-06-18 21:45:37 -04:00
rpc: Have class functions be voids
This commit is contained in:
parent
5755a272de
commit
f4aca03a60
@ -135,7 +135,6 @@ class APIClient:
|
|||||||
response = r.json()
|
response = r.json()
|
||||||
DiscordSession().create(self.current_user.refresh_token, response['token'])
|
DiscordSession().create(self.current_user.refresh_token, response['token'])
|
||||||
DiscordSession().update(response['token'])
|
DiscordSession().update(response['token'])
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def reset_presence(self):
|
def reset_presence(self):
|
||||||
@ -158,14 +157,9 @@ class APIClient:
|
|||||||
|
|
||||||
# Reset session
|
# Reset session
|
||||||
DiscordSession().create(self.current_user.rpc_session_token, None)
|
DiscordSession().create(self.current_user.rpc_session_token, None)
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def refresh_bearer(self):
|
def refresh_bearer(self):
|
||||||
# We only need to refresh 30 minutes before the token expires.
|
|
||||||
if time.time() - self.current_user.generation_date < 604800 - 1800:
|
|
||||||
return False
|
|
||||||
|
|
||||||
print('[REFRESH BEARER %s]' % self.current_user.id)
|
print('[REFRESH BEARER %s]' % self.current_user.id)
|
||||||
current_refresh_token = self.current_user.refresh_token
|
current_refresh_token = self.current_user.refresh_token
|
||||||
data = {
|
data = {
|
||||||
@ -191,7 +185,6 @@ class APIClient:
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
session.commit()
|
session.commit()
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
def delete_discord_user(self):
|
def delete_discord_user(self):
|
||||||
@ -205,15 +198,20 @@ class APIClient:
|
|||||||
delay = 2
|
delay = 2
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(delay)
|
# First, refresh all OAuth2 bearer tokens if necessary.
|
||||||
|
|
||||||
# First, refresh all OAuth2 bearer tokens.
|
|
||||||
all_users = session.scalars(select(DiscordTable)).all()
|
all_users = session.scalars(select(DiscordTable)).all()
|
||||||
for oauth_user in all_users:
|
for oauth_user in all_users:
|
||||||
|
# We only need to refresh 30 minutes before the token expires.
|
||||||
|
if time.time() - oauth_user.generation_date < 604800 - 1800:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Any HTTP error expected here is a 403.
|
||||||
|
# This would mean that the refresh token is now invalid,
|
||||||
|
# likely due to the user removing access via Discord.
|
||||||
api_client = APIClient(oauth_user)
|
api_client = APIClient(oauth_user)
|
||||||
try:
|
try:
|
||||||
if api_client.refresh_bearer():
|
api_client.refresh_bearer()
|
||||||
time.sleep(delay * 2)
|
time.sleep(delay * 2)
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
api_client.delete_discord_user()
|
api_client.delete_discord_user()
|
||||||
|
|
||||||
@ -237,8 +235,8 @@ while True:
|
|||||||
api_client = APIClient(inactive_user)
|
api_client = APIClient(inactive_user)
|
||||||
try:
|
try:
|
||||||
print('[RESETTING %s]' % inactive_user.id)
|
print('[RESETTING %s]' % inactive_user.id)
|
||||||
if api_client.reset_presence():
|
api_client.reset_presence()
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
api_client.delete_discord_user()
|
api_client.delete_discord_user()
|
||||||
|
|
||||||
@ -277,8 +275,8 @@ while True:
|
|||||||
# Remove our presence for this now-offline user.
|
# Remove our presence for this now-offline user.
|
||||||
try:
|
try:
|
||||||
print('[RESETTING %s on %s]' % (friend_data.friend_code, friend_data.network.lower_name()))
|
print('[RESETTING %s on %s]' % (friend_data.friend_code, friend_data.network.lower_name()))
|
||||||
if api_client.reset_presence():
|
api_client.reset_presence()
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
api_client.delete_discord_user()
|
api_client.delete_discord_user()
|
||||||
continue
|
continue
|
||||||
@ -303,8 +301,8 @@ while True:
|
|||||||
last_accessed=friend_data.last_accessed
|
last_accessed=friend_data.last_accessed
|
||||||
)
|
)
|
||||||
|
|
||||||
if api_client.update_presence(discord_user_data, discord_friend.network):
|
api_client.update_presence(discord_user_data, discord_friend.network)
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
api_client.delete_discord_user()
|
api_client.delete_discord_user()
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
|
Loading…
Reference in New Issue
Block a user