-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
bridge_mod.js
80 lines (63 loc) · 2.58 KB
/
bridge_mod.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// NOTE: you may have to run this after onload
(() => {
let Dispatcher, lookupAsset, lookupApp, apps = {};
const ws = new WebSocket('ws://127.0.0.1:1337'); // connect to arRPC bridge websocket
ws.onmessage = async x => {
msg = JSON.parse(x.data);
if (!Dispatcher) {
let wpRequire;
window.webpackChunkdiscord_app.push([[ Symbol() ], {}, x => wpRequire = x]);
window.webpackChunkdiscord_app.pop();
const modules = wpRequire.c;
for (const id in modules) {
const mod = modules[id].exports;
if (!mod?.__esModule) continue;
for (const prop in mod) {
if (!mod.hasOwnProperty(prop)) continue;
const candidate = mod[prop];
if (candidate && candidate.register && candidate.wait) {
Dispatcher = candidate;
break;
}
}
if (Dispatcher) break;
}
const factories = wpRequire.m;
for (const id in factories) {
if (factories[id].toString().includes('getAssetImage: size must === [number, number] for Twitch')) {
const mod = wpRequire(id);
// fetchAssetIds
const _lookupAsset = Object.values(mod).find(e => typeof e === 'function' && e.toString().includes('APPLICATION_ASSETS_FETCH_SUCCESS'));
if (_lookupAsset) lookupAsset = async (appId, name) => (await _lookupAsset(appId, [ name, undefined ]))[0];
}
if (lookupAsset) break;
}
for (const id in factories) {
if (factories[id].toString().includes('APPLICATION_RPC(')) {
const mod = wpRequire(id);
// fetchApplicationsRPC
const _lookupApp = Object.values(mod).find(e => {
if (typeof e !== 'function') return;
const str = e.toString();
return str.includes(',coverImage:') && str.includes('INVALID_ORIGIN');
});
if (_lookupApp) lookupApp = async appId => {
let socket = {};
await _lookupApp(socket, appId);
return socket.application;
};
}
if (lookupApp) break;
}
}
if (msg.activity?.assets?.large_image) msg.activity.assets.large_image = await lookupAsset(msg.activity.application_id, msg.activity.assets.large_image);
if (msg.activity?.assets?.small_image) msg.activity.assets.small_image = await lookupAsset(msg.activity.application_id, msg.activity.assets.small_image);
if (msg.activity) {
const appId = msg.activity.application_id;
if (!apps[appId]) apps[appId] = await lookupApp(appId);
const app = apps[appId];
if (!msg.activity.name) msg.activity.name = app.name;
}
Dispatcher.dispatch({ type: 'LOCAL_ACTIVITY_UPDATE', ...msg }); // set RPC status
};
})();