mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-12 07:28:21 +08:00
Fix: Close discord RPC will close current event loop
Fix: Initial RPC outside of init function
This commit is contained in:
@@ -3,21 +3,22 @@ import time
|
||||
|
||||
from pypresence import AioPresence
|
||||
|
||||
RPC = AioPresence("929437173764223057")
|
||||
RPC: AioPresence = None
|
||||
|
||||
|
||||
async def run():
|
||||
assert RPC is not None
|
||||
await RPC.connect()
|
||||
await RPC.update(state="Alas is playing Azurlane", start=time.time(), large_image="alas")
|
||||
|
||||
|
||||
def init_discord_rpc():
|
||||
global RPC
|
||||
RPC = AioPresence("929437173764223057")
|
||||
asyncio.create_task(run())
|
||||
|
||||
|
||||
def close_discord_rpc():
|
||||
RPC.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
init_discord_rpc()
|
||||
if RPC:
|
||||
RPC.send_data(2, {'v': 1, 'client_id': RPC.client_id})
|
||||
RPC.sock_writer.close()
|
||||
|
||||
Reference in New Issue
Block a user