Skip to content

Commit 81e644c

Browse files
committed
Added token configuration.
1 parent 1aee361 commit 81e644c

File tree

4 files changed

+68
-18
lines changed

4 files changed

+68
-18
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ ws://localhost/ws
4242

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

45-
Após adicionar pelo menos um link de websocket no app você pode clicar em "Iniciar Presence".
45+
* Adicione o link do websocket na aba Socket Settings.
46+
47+
* Obtenha o token de acesso através do bot usando o comando `/rich_presence` (ou mencionando o bot em uma mensagem: `@bot richpresence`).
48+
49+
* Adicione o token na aba Socket Settings.
50+
51+
Após configurar esses dois itens, basta clicar em "Iniciar Presence".
4652

4753
---

config_loader.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def read_config():
2020
"heartbeat": 30,
2121
"reconnect_timeout": 7,
2222
"enable_queue_text": True,
23+
"token": "",
2324
"assets": {
2425
"loop": "https://cdn.discordapp.com/emojis/912965656624889916.gif",
2526
"loop_queue": "https://i.ibb.co/5Mj4HjT/loop-track.gif",

main_window.py

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,28 @@ def get_window(self):
9999
tab_urls = [
100100
[
101101
sg.Frame("", [
102-
[sg.Text("Links Ativados:", size=(39, 1), font=("arial",11), justification="center",
103-
background_color="green2"),
104-
sg.Text("Links Desativados:", size=(39, 1), font=("arial",11), justification="center",
105-
text_color="white", background_color="red")],
106-
[sg.Listbox(values=self.config["urls"], size=(30, 11),expand_x=True, key="url_list",
107-
horizontal_scroll=True, bind_return_key=True),
108-
sg.Listbox(values=self.config["urls_disabled"], size=(30, 11), expand_x=True,
109-
horizontal_scroll=True, key="url_list_disabled", bind_return_key=True)
102+
[
103+
sg.Text('Token de acesso:'),
104+
sg.InputText(default_text=self.config["token"], key="token", size=(73,1), disabled=True),
105+
sg.Button("Colar Token", key="btn_paste_token", enable_events=True)
106+
],
107+
[
108+
sg.Text("Links Ativados:", size=(39, 1), font=("arial", 11), justification="center",
109+
background_color="green2"),
110+
sg.Text("Links Desativados:", size=(39, 1), font=("arial", 11), justification="center",
111+
text_color="white", background_color="red")
112+
],
113+
[
114+
sg.Listbox(values=self.config["urls"], size=(30, 12), expand_x=True, key="url_list",
115+
horizontal_scroll=True, bind_return_key=True),
116+
sg.Listbox(values=self.config["urls_disabled"], size=(30, 12), expand_x=True,
117+
horizontal_scroll=True, key="url_list_disabled", bind_return_key=True)
110118
],
111-
[sg.Button("Adicionar", key="btn_add_url", enable_events=True),
112-
sg.Button("Editar", key="btn_edit_url", enable_events=True),
113-
sg.Button("Remover", key="btn_remove_url", enable_events=True)]
119+
[
120+
sg.Button("Adicionar", key="btn_add_url", enable_events=True),
121+
sg.Button("Editar", key="btn_edit_url", enable_events=True),
122+
sg.Button("Remover", key="btn_remove_url", enable_events=True)
123+
]
114124
], expand_x=True)
115125
]
116126
]
@@ -120,8 +130,8 @@ def get_window(self):
120130
sg.TabGroup(
121131
[
122132
[
123-
sg.Tab('Config', tab_config, element_justification='center'),
124-
sg.Tab('Socket URL\'s', tab_urls, key="sockets_url"),
133+
sg.Tab('Main Settings', tab_config, element_justification='center'),
134+
sg.Tab('Socket Settings', tab_urls, key="sockets_url"),
125135
sg.Tab('Assets', tab_assets, element_justification='center')
126136
]
127137
], key="main_tab"
@@ -223,6 +233,19 @@ def window_loop(self):
223233
elif event == "clear_log":
224234
self.window[MLINE_KEY].update("Log limpo com sucesso!\n", text_color_for_value='green2')
225235

236+
elif event == "btn_paste_token":
237+
238+
token = self.window.TKroot.clipboard_get()
239+
240+
if len(token) != 50:
241+
sg.popup_ok(f"O token colado não possui 50 caracteres:\n"
242+
f"{' '.join(token.split())[:100]}")
243+
continue
244+
245+
self.config["token"] = token
246+
self.window["token"].update(value=token)
247+
self.update_data()
248+
226249
elif event == "btn_add_url":
227250

228251
while True:
@@ -299,6 +322,13 @@ def window_loop(self):
299322
sg.popup_ok(f"Você deve adicionar pelo menos um link WS antes de iniciar presence!")
300323
self.window["sockets_url"].select()
301324
continue
325+
326+
if not self.config["token"]:
327+
sg.popup_ok(f"Você deve incluir o token de acesso para iniciar presence!\n"
328+
f"Caso não tenha, use o comando /rich_presence no bot.")
329+
self.window["sockets_url"].select()
330+
continue
331+
302332
self.client.gui = self
303333
try:
304334
self.client.get_app_instances()
@@ -309,17 +339,16 @@ def window_loop(self):
309339
self.rpc_started = True
310340
self.update_buttons(
311341
enable=["stop_presence"],
312-
disable=["start_presence", "load_all_instances", "dummy_app_id", "override_appid"]
342+
disable=["start_presence", "load_all_instances", "dummy_app_id", "override_appid", "btn_paste_token"]
313343
)
314344

315345
elif event == "stop_presence":
316346
self.client.close_app_instances()
317347
self.client.exit()
318-
#time.sleep(2)
319348
self.update_log("RPC Finalizado!\n-----", tooltip=True)
320349
self.update_buttons(
321350
disable=["stop_presence"],
322-
enable=["start_presence", "load_all_instances", "dummy_app_id", "override_appid"]
351+
enable=["start_presence", "load_all_instances", "dummy_app_id", "override_appid", "btn_paste_token"]
323352
)
324353
self.rpc_started = False
325354

rpc_client.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,16 @@ async def handle_socket(self, uri):
569569

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

572-
await ws.send_str(json.dumps({"op": "rpc_update", "user_ids": list(user_clients), "version": 2.0}))
572+
await ws.send_str(
573+
json.dumps(
574+
{
575+
"op": "rpc_update",
576+
"user_ids": list(user_clients),
577+
"token": self.config["token"].replace(" ", ""),
578+
"version": 2.1
579+
}
580+
)
581+
)
573582

574583
async for msg in ws:
575584

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

634+
try:
635+
del data["token"]
636+
except KeyError:
637+
pass
638+
625639
self.process_data(user_ws, bot_id, data)
626640

627641
elif msg.type in (aiohttp.WSMsgType.CLOSED,

0 commit comments

Comments
 (0)