Skip to content

Commit

Permalink
All functionality is restored!
Browse files Browse the repository at this point in the history
Indicators show immediately
  • Loading branch information
SammCheese committed Dec 19, 2022
1 parent 3acbf63 commit 5f7af1b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/assets/indicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";

export const Indicator = React.createElement("img", {
src: "https://cdn-icons-png.flaticon.com/32/3064/3064130.png",
width: "20",
});
4 changes: 3 additions & 1 deletion src/components/EncryptionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ export function buildEncModal() {

webpack.common.messages.sendMessage(
webpack.common.channels.getCurrentlySelectedChannelId(),
{ content: toSend },
// Adds an indicator (\u200b)
// eslint-disable-next-line no-irregular-whitespace
{ content: `${toSend}​` },
);
// @ts-ignore
closeModal(s);
Expand Down
27 changes: 12 additions & 15 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Injector, OutgoingMessage, webpack } from "replugged";

import StegCloak from "./lib/stegcloak.js";
import { popoverIcon } from "./assets/popoverIcon";
import { chatbarLock } from "./assets/chatbarLock";
import { Indicator } from "./assets/indicator";

import { buildDecModal } from "./components/DecryptionModal";
import StegCloak from "./lib/stegcloak.js";

const inject = new Injector();
const steggo: StegCloak = new StegCloak(true, false);
Expand Down Expand Up @@ -35,6 +36,7 @@ export async function start(): Promise<void> {
INV_DETECTION,
receiver,
chatbarLock,
Indicator,
};
}

Expand All @@ -48,31 +50,25 @@ export function runPlaintextPatches(): void {
/.\?(..)\(\{key:"reply",label:.{1,40},icon:.{1,40},channel:(.{1,3}),message:(.{1,3}),onClick:.{1,5}\}\):null/gm,
replace: `$&,$3.content.match(window.invisiblechat.INV_DETECTION)?$1({key:"decrypt",label:"Decrypt Message",icon:window.invisiblechat.popoverIcon,channel:$2,message:$3,onClick:()=>window.invisiblechat.receiver($3)}):null`,
},
{
// Detection Lock
// TODO: Find a better way that doesnt need hovering over the message
match: /var .=(.)\.channel,.=.\.message,.=.\.expanded,.=.\.canCopy/gm,
replace: `window.invisiblechat.receiver($1.message, $1.canPin);$&`,
},
{
// Chatbar Lock
match: /.=.\.activeCommand,.=.\.activeCommandOption,(.)=\[\];/,
replace: "$&;$1.push(window.invisiblechat.chatbarLock);",
},
{
// Message Indicator
match: /var .,.,.=(.)\.className,.=.\.message,.=.\.children,.=.\.content,.=.\.onUpdate/,
replace:
"try{$1?.content[0].match(window.invisiblechat.INV_DETECTION)?$1?.content.push(window.invisiblechat.Indicator):null}catch(e){};$&",
},
],
},
]);
}

// Grab the data from the above Plantext Patches
function receiver(message: IncomingMessage, canPin: boolean | undefined): void {
if (typeof canPin !== "undefined") {
if (message.content.match(INV_DETECTION) && !message.content.includes("🔒")) {
message.content = `🔒${message.content}🔒`;
}
} else {
buildDecModal(message);
}
function receiver(message: IncomingMessage): void {
buildDecModal(message);
}

// Gets the Embed of a Link
Expand Down Expand Up @@ -133,6 +129,7 @@ export function encrypt(secret: string, password: string, cover: string): string
}

export function decrypt(secret: string, password: string): string {
// Remove the Indicator when revealing
// eslint-disable-next-line no-irregular-whitespace
return steggo.reveal(secret, password).replace("​", "");
}
56 changes: 56 additions & 0 deletions src/updater.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import { createWriteStream } from "fs";
import { get } from "https";
import { plugins } from "replugged";
import { CONFIG_PATHS } from "replugged/dist/util";
import { join } from "path";

const GITAPI_LINK = "https://api.github.com/repos/SammCheese/invisible-chat/releases/latest";
const FILENAME = "dev.sammcheese.InvisibleChat.asar";

async function fetchGithub(): Promise<JSON> {
return new Promise((resolve, reject) => {
fetch(GITAPI_LINK)
.then((resp) => resolve(resp.json()))
.catch((rej) => {
console.log(rej);
reject(rej);
});
});
}

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const downloadFile = (url: string, path: string) => {
const file = createWriteStream(path);
get(url, (res) => {
res.pipe(file);

file.on("finish", () => {
file.close();
});
});
};

export async function checkUpdate(): Promise<void> {
const gitResult = await fetchGithub();
// @ts-expect-error response type not declared
const localVersion = await plugins.get("dev.sammcheese.InvisibleChat")?.manifest?.version;

// @ts-expect-error type not declared
if (isNewAvailable(localVersion, gitResult.tag_name)) {
// @ts-expect-error type not declared
downloadFile(gitResult.assets.browser_download_url, join(CONFIG_PATHS.plugins, FILENAME));
/*rename(join(CONFIG_PATHS.plugins, FILENAME), `${FILENAME}.update`, (e) => {
// @ts-expect-error type not declared
if (e) unlinkSync(file);
});*/
}
}

function isNewAvailable(localVersion: string, remoteVersion: string): boolean {
if (!localVersion || !remoteVersion) return false;

localVersion.replaceAll(".", "").replace("v", "");
remoteVersion.replaceAll(".", "").replace("v", "");

return parseInt(remoteVersion, 10) > parseInt(localVersion, 10);
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */

/* Language and Environment */
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"target": "es2021" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"jsx": "react" /* Specify what JSX code is generated. */,
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
Expand Down

0 comments on commit 5f7af1b

Please sign in to comment.