Skip to content

Commit

Permalink
trocar matchcase por if/elif (compatibilidade com py 3.8 pra corrigir…
Browse files Browse the repository at this point in the history
… um erro ao usar no win7)...
  • Loading branch information
zRitsu committed Jan 11, 2022
1 parent 2137474 commit 5ad8899
Showing 1 changed file with 32 additions and 39 deletions.
71 changes: 32 additions & 39 deletions rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def __init__(self, *args, **kwargs):
self.next = None
self.updating = False


def _send(self, opcode, payload):

encoded_payload = self._encode(opcode, payload)
Expand Down Expand Up @@ -69,8 +68,8 @@ def __repr__(self):

langs = {}

def get_thumb(url):

def get_thumb(url):
if "youtube.com" in url:
return ["yt", "Youtube"]
if "spotify.com" in url:
Expand All @@ -96,7 +95,6 @@ def fix_characters(text: str, limit=30):
with open(f"./langs/{f}", encoding="utf-8") as file:
langs[f[:-5]] = json.load(file)


for i in range(10):

try:
Expand All @@ -115,7 +113,6 @@ def fix_characters(text: str, limit=30):
rpc.user = user
print(f"RPC conectado: {user} [{user_id_}] pipe: {i}")


if not user_clients:
print("Não foi detectado nenhuma instância do discord em execução.")
time.sleep(10)
Expand Down Expand Up @@ -268,7 +265,7 @@ async def update(self, user_id: int, bot_id: int, data: dict):

if 'youtube.com' in playlist_url:
playlist_url = "https://www.youtube.com/playlist?list=" + \
(playlist_url.split('?list=' if '?list=' in playlist_url else '&list='))[1]
(playlist_url.split('?list=' if '?list=' in playlist_url else '&list='))[1]

if (playlist_size := len(playlist_name)) > 25:
state += f' | {self.get_lang("playlist")}: {playlist_name}'
Expand Down Expand Up @@ -337,7 +334,6 @@ async def update(self, user_id: int, bot_id: int, data: dict):
del self.users_rpc[user_id]
del user_clients[user_id]


def get_lang(self, key: str) -> str:

try:
Expand All @@ -349,7 +345,6 @@ def get_lang(self, key: str) -> str:
txt = langs["en-us"].get(key)
return txt


async def clear_users_presences(self, users: set, bots: set):

for bot_id in bots:
Expand All @@ -359,7 +354,6 @@ async def clear_users_presences(self, users: set, bots: set):
except:
continue


async def handle_socket(self, uri):

backoff = 7
Expand Down Expand Up @@ -420,49 +414,47 @@ async def handle_socket(self, uri):

print(f"op: {op} | {user} [{u_id}] | bot: {bot_id}")

match op:

case "update":
if op == "update":

await self.update(u_id, bot_id, data)
await self.update(u_id, bot_id, data)

case "idle":
elif op == "idle":

text_idle = self.get_lang("idle")
text_idle = self.get_lang("idle")

data = {
"assets": {
"large_image": data.pop("thumb", config["assets"]["app"])
},
"details": text_idle[0],
}
data = {
"assets": {
"large_image": data.pop("thumb", config["assets"]["app"])
},
"details": text_idle[0],
}

if len(text_idle) > 1:
data['state'] = text_idle[1]
if len(text_idle) > 1:
data['state'] = text_idle[1]

if public:
invite = f"https://discord.com/api/oauth2/authorize?client_id={bot_id}&permissions=8&scope=bot%20applications.commands"
if public:
invite = f"https://discord.com/api/oauth2/authorize?client_id={bot_id}&permissions=8&scope=bot%20applications.commands"

data["buttons"] = [
{
"label": self.get_lang("invite"),
"url": invite
}
]
data["buttons"] = [
{
"label": self.get_lang("invite"),
"url": invite
}
]

await self.update(u_id, bot_id, data)
await self.update(u_id, bot_id, data)

case "close":
elif op == "close":

try:
users.remove(u_id)
except:
pass
try:
users.remove(u_id)
except Exception:
pass

await self.update(u_id, bot_id, {})
await self.update(u_id, bot_id, {})

case _:
print(f"unknow op: {msg.data}")
else:
print(f"unknow op: {msg.data}")


except (websockets.ConnectionClosedError, ConnectionResetError, websockets.InvalidStatusCode) as e:
Expand All @@ -481,4 +473,5 @@ async def handle_socket(self, uri):
async def handler(self):
await asyncio.wait([asyncio.create_task(self.handle_socket(uri)) for uri in list(set(config["urls"]))])


asyncio.run(RpcClient().handler())

0 comments on commit 5ad8899

Please sign in to comment.