1
0
Fork 1
mirror of https://github.com/Vendicated/Vencord.git synced 2025-01-10 18:06:22 +00:00
This commit is contained in:
sadan 2024-08-17 23:30:24 -04:00
parent 49be750a1a
commit 39ce554b26
No known key found for this signature in database

View file

@ -50,23 +50,7 @@ interface FunctionNode {
type: "function"; type: "function";
value: string; value: string;
} }
interface ExtractFindData {
extractType: string,
findType: string,
findArgs: string[];
}
interface ExtractData {
idOrSearch: string | number;
extractType: string;
}
enum ExtractResponseType {
OK,
ERROR,
NOT_FOUND
}
interface ReloadData {
native: boolean;
}
interface PatchData { interface PatchData {
find: string; find: string;
replacement: { replacement: {
@ -125,8 +109,9 @@ function findModuleId(find: CodeFilter) {
} }
interface SendData { interface SendData {
type: string, type: string,
data?: any, data: any,
status?: number, ok: boolean;
nonce?: number;
} }
function initWs(isManual = false) { function initWs(isManual = false) {
let wasConnected = isManual; let wasConnected = isManual;
@ -146,7 +131,8 @@ function initWs(isManual = false) {
replyData({ replyData({
type: "moduleList", type: "moduleList",
data: JSON.stringify(Object.keys(wreq.m)) data: Object.keys(wreq.m),
ok: true,
}); });
(settings.store.notifyOnAutoConnect || isManual) && showNotification({ (settings.store.notifyOnAutoConnect || isManual) && showNotification({
@ -203,12 +189,16 @@ function initWs(isManual = false) {
ws.send(JSON.stringify(data)); ws.send(JSON.stringify(data));
} }
function replyData<T extends SendData>(data: T) {
data.nonce = nonce;
ws.send(JSON.stringify(data));
}
logger.info("Received Message:", type, "\n", data); logger.info("Received Message:", type, "\n", data);
switch (type) { switch (type) {
case "extract": { case "extract": {
const { extractType, idOrSearch } = data as ExtractData; const { extractType, idOrSearch } = data;
switch (extractType) { switch (extractType) {
case "id": { case "id": {
console.log("ID!"); console.log("ID!");
@ -216,17 +206,14 @@ function initWs(isManual = false) {
if (typeof idOrSearch === "number") if (typeof idOrSearch === "number")
data = wreq.m[idOrSearch]?.toString() || null; data = wreq.m[idOrSearch]?.toString() || null;
else { else {
throw "fun times"; return reply(`the provided moduleID is not a number. Got: ${typeof idOrSearch}`);
} }
if (!data) if (!data)
replyData({ return reply(`Module(${idOrSearch}) not found`);
type: "extract",
status: ExtractResponseType.NOT_FOUND
});
else else
replyData({ replyData({
type: "extract", type: "extract",
status: ExtractResponseType.OK, ok: true,
data, data,
moduleNumber: idOrSearch moduleNumber: idOrSearch
}); });
@ -239,18 +226,12 @@ function initWs(isManual = false) {
const data = wreq.m[moduleId].toString(); const data = wreq.m[moduleId].toString();
replyData({ replyData({
type: "extract", type: "extract",
status: ExtractResponseType.OK, ok: true,
data, data,
moduleNumber: moduleId moduleNumber: +moduleId
}); });
} catch (e) { } catch (e) {
if (e instanceof Error) reply("Error: " + String(e));
return void replyData({
type: "extract",
status: ExtractResponseType.ERROR,
data: e.message
});
console.error(e);
} }
break; break;
} }
@ -291,12 +272,13 @@ function initWs(isManual = false) {
if (uniqueResultsCount === 0) throw "No results"; if (uniqueResultsCount === 0) throw "No results";
if (uniqueResultsCount > 1) throw "Found more than one result! Make this filter more specific"; if (uniqueResultsCount > 1) throw "Found more than one result! Make this filter more specific";
// best name ever // best name ever
const foundFind = [...results][0].toString(); const foundFind: string = [...results][0].toString();
replyData({ replyData({
type: "extract", type: "extract",
ok: true,
find: true, find: true,
data: foundFind, data: foundFind,
moduleNumber: findModuleId([foundFind]) moduleNumber: +findModuleId([foundFind])
}); });
} catch (err) { } catch (err) {
return reply("Failed to find: " + err); return reply("Failed to find: " + err);
@ -304,24 +286,11 @@ function initWs(isManual = false) {
break; break;
} }
default: default:
replyData({ reply(`Unknown Extract type. Got: ${extractType}`);
type: "extract",
status: ExtractResponseType.ERROR,
data: `Unknown Type: ${extractType}`
});
break; break;
} }
break; break;
} }
case "reload": {
const { native } = data as ReloadData;
if (native) {
VesktopNative;
} else {
window.location.reload();
}
break;
}
case "testPatch": { case "testPatch": {
const { find, replacement } = data as PatchData; const { find, replacement } = data as PatchData;