Skip to content

Commit

Permalink
Added token configuration.
Browse files Browse the repository at this point in the history
  • Loading branch information
zRitsu committed Mar 21, 2023
1 parent 1aee361 commit 81e644c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 18 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ ws://localhost/ws

![](https://cdn.discordapp.com/attachments/554468640942981147/1087148423767130112/image.png)

Após adicionar pelo menos um link de websocket no app você pode clicar em "Iniciar Presence".
* Adicione o link do websocket na aba Socket Settings.

* Obtenha o token de acesso através do bot usando o comando `/rich_presence` (ou mencionando o bot em uma mensagem: `@bot richpresence`).

* Adicione o token na aba Socket Settings.

Após configurar esses dois itens, basta clicar em "Iniciar Presence".

---
1 change: 1 addition & 0 deletions config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def read_config():
"heartbeat": 30,
"reconnect_timeout": 7,
"enable_queue_text": True,
"token": "",
"assets": {
"loop": "https://cdn.discordapp.com/emojis/912965656624889916.gif",
"loop_queue": "https://i.ibb.co/5Mj4HjT/loop-track.gif",
Expand Down
61 changes: 45 additions & 16 deletions main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,28 @@ def get_window(self):
tab_urls = [
[
sg.Frame("", [
[sg.Text("Links Ativados:", size=(39, 1), font=("arial",11), justification="center",
background_color="green2"),
sg.Text("Links Desativados:", size=(39, 1), font=("arial",11), justification="center",
text_color="white", background_color="red")],
[sg.Listbox(values=self.config["urls"], size=(30, 11),expand_x=True, key="url_list",
horizontal_scroll=True, bind_return_key=True),
sg.Listbox(values=self.config["urls_disabled"], size=(30, 11), expand_x=True,
horizontal_scroll=True, key="url_list_disabled", bind_return_key=True)
[
sg.Text('Token de acesso:'),
sg.InputText(default_text=self.config["token"], key="token", size=(73,1), disabled=True),
sg.Button("Colar Token", key="btn_paste_token", enable_events=True)
],
[
sg.Text("Links Ativados:", size=(39, 1), font=("arial", 11), justification="center",
background_color="green2"),
sg.Text("Links Desativados:", size=(39, 1), font=("arial", 11), justification="center",
text_color="white", background_color="red")
],
[
sg.Listbox(values=self.config["urls"], size=(30, 12), expand_x=True, key="url_list",
horizontal_scroll=True, bind_return_key=True),
sg.Listbox(values=self.config["urls_disabled"], size=(30, 12), expand_x=True,
horizontal_scroll=True, key="url_list_disabled", bind_return_key=True)
],
[sg.Button("Adicionar", key="btn_add_url", enable_events=True),
sg.Button("Editar", key="btn_edit_url", enable_events=True),
sg.Button("Remover", key="btn_remove_url", enable_events=True)]
[
sg.Button("Adicionar", key="btn_add_url", enable_events=True),
sg.Button("Editar", key="btn_edit_url", enable_events=True),
sg.Button("Remover", key="btn_remove_url", enable_events=True)
]
], expand_x=True)
]
]
Expand All @@ -120,8 +130,8 @@ def get_window(self):
sg.TabGroup(
[
[
sg.Tab('Config', tab_config, element_justification='center'),
sg.Tab('Socket URL\'s', tab_urls, key="sockets_url"),
sg.Tab('Main Settings', tab_config, element_justification='center'),
sg.Tab('Socket Settings', tab_urls, key="sockets_url"),
sg.Tab('Assets', tab_assets, element_justification='center')
]
], key="main_tab"
Expand Down Expand Up @@ -223,6 +233,19 @@ def window_loop(self):
elif event == "clear_log":
self.window[MLINE_KEY].update("Log limpo com sucesso!\n", text_color_for_value='green2')

elif event == "btn_paste_token":

token = self.window.TKroot.clipboard_get()

if len(token) != 50:
sg.popup_ok(f"O token colado não possui 50 caracteres:\n"
f"{' '.join(token.split())[:100]}")
continue

self.config["token"] = token
self.window["token"].update(value=token)
self.update_data()

elif event == "btn_add_url":

while True:
Expand Down Expand Up @@ -299,6 +322,13 @@ def window_loop(self):
sg.popup_ok(f"Você deve adicionar pelo menos um link WS antes de iniciar presence!")
self.window["sockets_url"].select()
continue

if not self.config["token"]:
sg.popup_ok(f"Você deve incluir o token de acesso para iniciar presence!\n"
f"Caso não tenha, use o comando /rich_presence no bot.")
self.window["sockets_url"].select()
continue

self.client.gui = self
try:
self.client.get_app_instances()
Expand All @@ -309,17 +339,16 @@ def window_loop(self):
self.rpc_started = True
self.update_buttons(
enable=["stop_presence"],
disable=["start_presence", "load_all_instances", "dummy_app_id", "override_appid"]
disable=["start_presence", "load_all_instances", "dummy_app_id", "override_appid", "btn_paste_token"]
)

elif event == "stop_presence":
self.client.close_app_instances()
self.client.exit()
#time.sleep(2)
self.update_log("RPC Finalizado!\n-----", tooltip=True)
self.update_buttons(
disable=["stop_presence"],
enable=["start_presence", "load_all_instances", "dummy_app_id", "override_appid"]
enable=["start_presence", "load_all_instances", "dummy_app_id", "override_appid", "btn_paste_token"]
)
self.rpc_started = False

Expand Down
16 changes: 15 additions & 1 deletion rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,16 @@ async def handle_socket(self, uri):

self.gui.update_log(f"Websocket conectado: {uri}", tooltip=True)

await ws.send_str(json.dumps({"op": "rpc_update", "user_ids": list(user_clients), "version": 2.0}))
await ws.send_str(
json.dumps(
{
"op": "rpc_update",
"user_ids": list(user_clients),
"token": self.config["token"].replace(" ", ""),
"version": 2.1
}
)
)

async for msg in ws:

Expand Down Expand Up @@ -622,6 +631,11 @@ async def handle_socket(self, uri):
except KeyError:
self.last_data[user_ws] = {bot_id: data}

try:
del data["token"]
except KeyError:
pass

self.process_data(user_ws, bot_id, data)

elif msg.type in (aiohttp.WSMsgType.CLOSED,
Expand Down

0 comments on commit 81e644c

Please sign in to comment.