mirror of
https://gitee.com/sui-feng-cb/AzurLaneAutoScript1
synced 2026-03-21 21:49:17 +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
|
from pypresence import AioPresence
|
||||||
|
|
||||||
RPC = AioPresence("929437173764223057")
|
RPC: AioPresence = None
|
||||||
|
|
||||||
|
|
||||||
async def run():
|
async def run():
|
||||||
|
assert RPC is not None
|
||||||
await RPC.connect()
|
await RPC.connect()
|
||||||
await RPC.update(state="Alas is playing Azurlane", start=time.time(), large_image="alas")
|
await RPC.update(state="Alas is playing Azurlane", start=time.time(), large_image="alas")
|
||||||
|
|
||||||
|
|
||||||
def init_discord_rpc():
|
def init_discord_rpc():
|
||||||
|
global RPC
|
||||||
|
RPC = AioPresence("929437173764223057")
|
||||||
asyncio.create_task(run())
|
asyncio.create_task(run())
|
||||||
|
|
||||||
|
|
||||||
def close_discord_rpc():
|
def close_discord_rpc():
|
||||||
RPC.close()
|
if RPC:
|
||||||
|
RPC.send_data(2, {'v': 1, 'client_id': RPC.client_id})
|
||||||
|
RPC.sock_writer.close()
|
||||||
if __name__ == "__main__":
|
|
||||||
init_discord_rpc()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user