Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 68 additions & 24 deletions examples/bridge_mod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
(() => {
let Dispatcher, lookupAsset, lookupApp, apps = {};

function getToken() {
let a = [];
webpackChunkdiscord_app.push([[0],,e=>Object.keys(e.c).find(t=>(t=e(t)?.default?.getToken?.())&&a.push(t))]);
return a[0];
}

const token = getToken()

const ws = new WebSocket('ws://127.0.0.1:1337'); // connect to arRPC bridge websocket
ws.onmessage = async x => {
msg = JSON.parse(x.data);
Expand All @@ -14,36 +22,26 @@ ws.onmessage = async x => {
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 mod = modules[id].exports;

for (const prop in mod) {
const candidate = mod[prop];
try {
if (candidate && candidate.register && candidate.wait) {
Dispatcher = candidate;
break;
}
} catch {}
}

if (Dispatcher) break;
if (candidate && candidate.register && candidate.wait) {
Dispatcher = candidate;
break;
}
} catch {
continue;
}
}

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 (Dispatcher) break;
}

if (lookupAsset) break;
}

const factories = wpRequire.m;


for (const id in factories) {
if (factories[id].toString().includes('APPLICATION_RPC(')) {
Expand All @@ -66,6 +64,52 @@ ws.onmessage = async x => {
}
}

async function lookupAsset(id, d) {
const authHeaders = new Headers();
authHeaders.append("Authorization", token);

const uploadHeaders = new Headers();
uploadHeaders.append("Authorization", token);
uploadHeaders.append("content-type", "application/json");

const isUrl = string => {
try { return Boolean(new URL(string)); }
catch(e){ return false; }
}
if (isUrl(d)) {
const response_upload = await fetch("https://discord.com/api/v9/applications/" + id + "/external-assets", {
headers: uploadHeaders,
method: "POST",
body: JSON.stringify({ urls: [d] }),
});

data = await response_upload.json()
return "mp:" + data[0]["external_asset_path"]


}

const response = await fetch("https://discord.com/api/v9/oauth2/applications/" + id + "/assets?nocache=true", {
headers: authHeaders,
});

data = await response.json()
let trip = false
let iid = ''

for (let i in data) {
let real = data[i]
if (trip) {
break
}
if (real["name"] == d) {
trip = true
iid = real["id"]
}
}
return iid
}

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);

Expand Down