Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
wont-stream committed Nov 20, 2024
1 parent 899ca51 commit a6e1715
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 7 deletions.
Binary file modified bun.lockb
Binary file not shown.
17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"devDependencies": {
"@biomejs/biome": "1.9.2",
"@uwu/lune": "^1.4.2",
"@uwu/shelter-defs": "^1.4.1"
},
"type": "module",
"workspaces": ["plugins/*"]
"devDependencies": {
"@biomejs/biome": "1.9.2",
"@uwu/lune": "^1.4.2",
"@uwu/shelter-defs": "^1.4.1"
},
"type": "module",
"workspaces": ["plugins/*"],
"trustedDependencies": [
"@biomejs/biome"
]
}
66 changes: 66 additions & 0 deletions plugins/rpc/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const {
flux: {
dispatcher: FluxDispatcher,
stores: { ApplicationStore },
},
http,
} = shelter;
const apps = {};
const assetCache = {};

const fetchAssetId = async (applicationId, assetName) => {
// TO-DO Use APPLICATION_ASSETS_UPDATE and APPLICATION_ASSETS_FETCH
if (!assetCache[applicationId]) {
try {
if (http.get) {
const response = await http.get(`/oauth2/applications/${applicationId}/assets`);

if (response.status !== 200) {
console.error("Error fetching resources");
return null;
}

assetCache[applicationId] = response.body;
}
} catch (error) {
console.error("Request failed", error);
return null;
}
}

// Find the resource ID by its name in the cached resources
const resource = assetCache[applicationId].find((item) => item.name === assetName);
return resource ? resource.id : null;
};
export function onLoad() {
const ws = new WebSocket('ws://127.0.0.1:1337');

if (ws) ws.onmessage = async x => {
const msg = JSON.parse(x.data);

if (msg.activity?.assets?.large_image.startsWith("https://")) {
msg.activity.assets.large_image = `https://images-ext-1.discordapp.net/external/${msg.activity.assets.large_image.replace("https://", "https/")}?format=webp&width=300&height=300`;
} else {
if (msg.activity?.assets?.large_image)fe
msg.activity.assets.large_image = await fetchAssetId(
msg.activity.application_id,
msg.activity.assets.large_image,
);
if (msg.activity?.assets?.small_image)
msg.activity.assets.small_image = await fetchAssetId(
msg.activity.application_id,
msg.activity.assets.small_image,
);
}
if (msg.activity) {
// TODO - Support games from DB too lool
const appId = msg.activity.application_id;
if (!apps[appId]) apps[appId] = (await ApplicationStore.getApplication(appId)) || "Unknown";

const app = apps[appId];
if (!msg.activity.name) msg.activity.name = app.name;
}
console.warn(msg);
FluxDispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", ...msg }); // set RPC statusa
}))
}
5 changes: 5 additions & 0 deletions plugins/rpc/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "rpc",
"author": "S€th",
"description": "modded rpc server"
}

0 comments on commit a6e1715

Please sign in to comment.