mirror of
https://github.com/MCMi460/3DS-RPC.git
synced 2025-06-18 21:45:37 -04:00
rpc: General fix-ups
This commit is contained in:
parent
29e832ac29
commit
23573a2332
@ -36,11 +36,11 @@ class UserData:
|
|||||||
last_accessed: int
|
last_accessed: int
|
||||||
|
|
||||||
|
|
||||||
class DiscordSession():
|
class DiscordSession:
|
||||||
def retire(self, refresh):
|
def retire(self, refresh_token: str):
|
||||||
session.execute(
|
session.execute(
|
||||||
update(DiscordTable)
|
update(DiscordTable)
|
||||||
.where(DiscordTable.refresh_token == refresh)
|
.where(DiscordTable.refresh_token == refresh_token)
|
||||||
.values(
|
.values(
|
||||||
rpc_session_token=None,
|
rpc_session_token=None,
|
||||||
last_accessed=time.time()
|
last_accessed=time.time()
|
||||||
@ -147,6 +147,7 @@ class APIClient:
|
|||||||
elif time.time() - self.current_user.last_accessed <= 30:
|
elif time.time() - self.current_user.last_accessed <= 30:
|
||||||
print('[MANUAL RATE LIMITED]')
|
print('[MANUAL RATE LIMITED]')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
'Authorization': 'Bearer %s' % self.current_user.bearer_token,
|
'Authorization': 'Bearer %s' % self.current_user.bearer_token,
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
@ -158,7 +159,7 @@ class APIClient:
|
|||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
|
|
||||||
# Reset session
|
# Reset session
|
||||||
DiscordSession().create(self.current_user.rpc_session_token, None)
|
DiscordSession().retire(self.current_user.rpc_session_token)
|
||||||
|
|
||||||
|
|
||||||
def refresh_bearer(self):
|
def refresh_bearer(self):
|
||||||
@ -231,12 +232,12 @@ while True:
|
|||||||
inactive_users = session.scalars(inactive_query).all()
|
inactive_users = session.scalars(inactive_query).all()
|
||||||
|
|
||||||
if len(inactive_users) > 0:
|
if len(inactive_users) > 0:
|
||||||
print('[INACTIVES; BATCH OF %s]' % len(inactive_users))
|
print('[INACTIVES] Handling %s' % len(inactive_users))
|
||||||
|
|
||||||
for inactive_user in inactive_users:
|
for inactive_user in inactive_users:
|
||||||
api_client = APIClient(inactive_user)
|
api_client = APIClient(inactive_user)
|
||||||
try:
|
try:
|
||||||
print('[RESETTING %s]' % inactive_user.id)
|
print('[INACTIVES] Resetting %s' % inactive_user.id)
|
||||||
api_client.reset_presence()
|
api_client.reset_presence()
|
||||||
time.sleep(delay)
|
time.sleep(delay)
|
||||||
except HTTPError:
|
except HTTPError:
|
||||||
@ -276,14 +277,14 @@ 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('[FRIENDS] Resetting presence for %s on %s' % (friend_data.friend_code, friend_data.network.lower_name()))
|
||||||
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
|
||||||
|
|
||||||
print('[RUNNING %s - %s on %s]' % (discord_friend.id, discord_friend.friend_code, discord_friend.network.lower_name()))
|
print('[FRIENDS] Creating RPC for Discord ID %s - %s on %s]' % (discord_friend.id, discord_friend.friend_code, discord_friend.network.lower_name()))
|
||||||
principal_id = friend_code_to_principal_id(friend_data.friend_code)
|
principal_id = friend_code_to_principal_id(friend_data.friend_code)
|
||||||
mii = friend_data.mii
|
mii = friend_data.mii
|
||||||
if mii:
|
if mii:
|
||||||
|
Loading…
Reference in New Issue
Block a user