Skip to content

Commit

Permalink
added new op "disconnect".
Browse files Browse the repository at this point in the history
  • Loading branch information
zRitsu committed Mar 29, 2023
1 parent fbb0f10 commit 3b0895e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,14 @@ def fix_characters(text: str, limit=30):
class RpcClient:

def __init__(self, autostart: int = 0):
self.version = 2.5
self.version = 2.6
self.last_data = {}
self.tasks = []
self.main_task = None
self.config = config
self.langs = langs
self.session: Optional[aiohttp.ClientSession] = None
self.closing = False

if os.path.isdir("./langs"):

Expand Down Expand Up @@ -607,8 +608,10 @@ async def handle_socket(self, uri):

try:
if not data['op']:
print(data)
continue
except:
traceback.print_exc()
continue

bot_id = data.pop("bot_id", None)
Expand All @@ -618,6 +621,13 @@ async def handle_socket(self, uri):

bot_name = data.pop("bot_name", None)

if data['op'] == "disconnect":
self.gui.update_log(f"op: {data['op']} | {uri} | reason: {data.get('reason')}",
log_type="error")
self.closing = True
await ws.close()
return

if bot_id:
try:
self.bots_socket[uri].add(bot_id)
Expand Down Expand Up @@ -671,6 +681,9 @@ async def handle_socket(self, uri):

await self.clear_users_presences(uri)

if self.closing:
return

self.gui.update_log(
f"Conexão perdida com o servidor: {uri} | Reconectando em {time_format(backoff)} seg. {repr(ws.exception())}",
tooltip=True, log_type="error")
Expand Down

0 comments on commit 3b0895e

Please sign in to comment.