Merge pull request 'TSification' (#2) from typescript into master

Reviewed-on: #2
cleanup
Drake 2 years ago
commit 58a699f174

2
dist/build.js vendored

File diff suppressed because one or more lines are too long

@ -2,7 +2,7 @@
"name": "demoncord-rewrite", "name": "demoncord-rewrite",
"version": "0.0.1", "version": "0.0.1",
"description": "A client mod for sinners.", "description": "A client mod for sinners.",
"main": "src/index.js", "main": "src/index.ts",
"scripts": { "scripts": {
"build": "rollup --config rollup.config.js", "build": "rollup --config rollup.config.js",
"watch": "node watchbuild" "watch": "node watchbuild"
@ -11,18 +11,22 @@
"license": "BSD-3-Clause", "license": "BSD-3-Clause",
"dependencies": { "dependencies": {
"@ltd/j-toml": "^1.30.0", "@ltd/j-toml": "^1.30.0",
"@types/react": "^18.0.17",
"chokidar": "^3.5.3", "chokidar": "^3.5.3",
"idb-keyval": "^6.2.0", "idb-keyval": "^6.2.0",
"nests": "^2.3.1", "nests": "^2.3.1",
"rollup-plugin-jscc": "^2.0.0", "rollup-plugin-jscc": "^2.0.0",
"rollup-plugin-visualizer": "^5.7.0", "rollup-plugin-visualizer": "^5.7.0",
"spitroast": "^1.4.2" "spitroast": "^1.4.2",
"tslib": "^2.4.0"
}, },
"devDependencies": { "devDependencies": {
"@rollup/plugin-alias": "^3.1.9", "@rollup/plugin-alias": "^3.1.9",
"@rollup/plugin-node-resolve": "^13.3.0", "@rollup/plugin-node-resolve": "^13.3.0",
"@rollup/plugin-typescript": "^8.4.0",
"@swc/core": "^1.2.215", "@swc/core": "^1.2.215",
"rollup": "^2.73.0", "rollup": "^2.73.0",
"rollup-plugin-swc3": "^0.3.0" "rollup-plugin-swc3": "^0.3.0",
"typescript": "^4.8.2"
} }
} }

@ -8,6 +8,7 @@ import { visualizer } from "rollup-plugin-visualizer";
import TOML from "@ltd/j-toml"; import TOML from "@ltd/j-toml";
import jscc from "rollup-plugin-jscc"; import jscc from "rollup-plugin-jscc";
import { readFileSync as readFile, existsSync as fileExists } from "fs"; import { readFileSync as readFile, existsSync as fileExists } from "fs";
import typescript from '@rollup/plugin-typescript';
const projectRootDir = resolvePath(__dirname); const projectRootDir = resolvePath(__dirname);
@ -43,11 +44,12 @@ export default defineConfig({
find: "react", find: "react",
replacement: resolvePath( replacement: resolvePath(
projectRootDir, projectRootDir,
"src/shim_react.js" "src/shim_react.ts"
) )
} }
] ]
}), }),
typescript(),
nodeResolve(), nodeResolve(),
swc({ swc({
jsc: { jsc: {
@ -55,8 +57,8 @@ export default defineConfig({
compress: true compress: true
}, },
parser: { parser: {
syntax: "ecmascript", syntax: "typescript",
jsx: true tsx: true
}, },
target: "es2022", target: "es2022",
baseUrl: "./src" baseUrl: "./src"

@ -10,7 +10,6 @@ const React = findByProps("createElement");
export default { export default {
React, React,
ReactDOM: findByProps("hydrate"), ReactDOM: findByProps("hydrate"),
//dispatch: findByProps("dirtyDispatch").__proto__,
idb, idb,
nests nests
}; };

@ -1,11 +1,11 @@
function injectCSS(str) { function injectCSS(str: string) {
const style = document.createElement("style"); const style = document.createElement("style");
style.className = "demon-element-css"; style.className = "demon-element-css";
style.innerHTML = str; style.innerHTML = str;
document.head.appendChild(style); document.head.appendChild(style);
} }
function createClass(name, style) { function createClass(name: string, style: object) {
const stylestr = Object.entries(style) const stylestr = Object.entries(style)
.map(([k, v]) => `${k}:${v}`) .map(([k, v]) => `${k}:${v}`)
.join(";"); .join(";");

@ -1,4 +1,12 @@
function wackyPatch(parentObj, name, patches) { type BeforeFunc = (args: any[]) => void
type InsteadFunc = (args: any[], orig: (...args: any) => any) => any
type AfterFunc = (args: any[], res: any) => any
function wackyPatch(parentObj: any, name: string, patches: {
before?: BeforeFunc,
instead?: InsteadFunc,
after?: AfterFunc
}) {
if (typeof parentObj === "string") { if (typeof parentObj === "string") {
//assume parentObj and name are switched around (for backcompat/convienence) //assume parentObj and name are switched around (for backcompat/convienence)
const tmp = parentObj; const tmp = parentObj;
@ -10,10 +18,11 @@ function wackyPatch(parentObj, name, patches) {
const instead = patches["instead"]; const instead = patches["instead"];
const after = patches["after"]; const after = patches["after"];
const handler = { const handler = {
apply: (target, thisArg, [ctx, args]) => { apply: (target: () => any, thisArg: any, [ctx, args]: [ctx: any, args: []]) => {
if (before !== undefined) before.apply(ctx, [args]); if (before !== undefined) before.apply(ctx, [args]);
const res = const res =
patches["instead"] !== undefined patches["instead"] !== undefined
//@ts-ignore; TS thinks that `instead` possibly being undefined is bad (meanwhile we literally check for that)
? instead.apply(ctx, [args, target.bind(ctx)]) ? instead.apply(ctx, [args, target.bind(ctx)])
: target.apply(ctx, args); : target.apply(ctx, args);
if (after === undefined) return res; if (after === undefined) return res;
@ -36,15 +45,15 @@ function wackyPatch(parentObj, name, patches) {
return unpatch; return unpatch;
} }
function before(parentObj, name, func) { function before(parentObj: any, name: string, func: BeforeFunc) {
return wackyPatch(parentObj, name, { before: func }); return wackyPatch(parentObj, name, { before: func });
} }
function instead(parentObj, name, func) { function instead(parentObj: any, name: string, func: InsteadFunc) {
return wackyPatch(parentObj, name, { instead: func }); return wackyPatch(parentObj, name, { instead: func });
} }
function after(parentObj, name, func) { function after(parentObj: any, name: string, func: AfterFunc) {
return wackyPatch(parentObj, name, { after: func }); return wackyPatch(parentObj, name, { after: func });
} }

@ -11,12 +11,12 @@
import { idb, nests } from "./common"; import { idb, nests } from "./common";
import logger from "./utils/logger"; import logger from "./utils/logger";
const ctxNest = nests.make(); //Plugin context nest (I would create this in index, but it's not a good idea to expose that) const ctxNest: Nest<any> = nests.make(); //Plugin context nest (I would create this in index, but it's not a good idea to expose that)
let pluginNest; let pluginNest: Nest<{plugins: any}>;
const pluginEval = (iife) => (0, eval)(iife); //defined as a separate function in case we want to do more things on plugin eval later const pluginEval = (iife: string) => (0, eval)(iife); //defined as a separate function in case we want to do more things on plugin eval later
async function savePlugin(eve, { path, value }) { async function savePlugin(eve: string, { path, value }: { path: string[] | string, value: any }) {
logger.debug( logger.debug(
["Plugins"], ["Plugins"],
`Got ${eve} event for plugin manager's nest with path ${path} and val ${value}` `Got ${eve} event for plugin manager's nest with path ${path} and val ${value}`
@ -48,7 +48,7 @@ async function init() {
}); });
} }
function add(iife) { function add(iife: string) {
const exports = pluginEval(iife); const exports = pluginEval(iife);
logger.debug(["Plugins"], `Adding ${exports.meta.name}`); logger.debug(["Plugins"], `Adding ${exports.meta.name}`);
pluginNest.store.plugins[exports.meta.name] = { pluginNest.store.plugins[exports.meta.name] = {
@ -58,7 +58,7 @@ function add(iife) {
}; };
} }
function del(name) { function del(name: string) {
if (!!pluginNest.ghost.plugins[name]) { if (!!pluginNest.ghost.plugins[name]) {
logger.debug(["Plugins"], `Removing ${name}`); logger.debug(["Plugins"], `Removing ${name}`);
delete pluginNest.store.plugins[name]; delete pluginNest.store.plugins[name];
@ -67,7 +67,7 @@ function del(name) {
} }
} }
function toggle(name) { function toggle(name: string) {
if (!!pluginNest.ghost.plugins[name]) { if (!!pluginNest.ghost.plugins[name]) {
if (pluginNest.ghost.plugins[name].enabled) { if (pluginNest.ghost.plugins[name].enabled) {
logger.debug(["Plugins"], `Disabling ${name}`); logger.debug(["Plugins"], `Disabling ${name}`);

@ -1,8 +1,10 @@
import webpack from "./webpack.js"; import webpack from "./webpack";
import { instead } from "./patcher.js"; import { instead } from "./patcher";
import { leak } from "./utils/memory.js"; import { leak } from "./utils/memory";
const sins = { type Sins = Record<string, (() => void) | null>
const sins: Sins = {
Lust: null, Lust: null,
Pride: null, Pride: null,
Greed: null, Greed: null,
@ -41,7 +43,7 @@ const rulers = {
Belphegor: "Sloth" Belphegor: "Sloth"
}; };
function ritualFail(sin) { function ritualFail(sin: string) {
if (Math.random() > 0.5) { if (Math.random() > 0.5) {
//use generic failstates //use generic failstates
//TODO: add nerd moxxie image and make it play the MLG clip on top of the screen and also make it patch sendMessage and replace every message with something funny idk i'll figure it out later //TODO: add nerd moxxie image and make it play the MLG clip on top of the screen and also make it patch sendMessage and replace every message with something funny idk i'll figure it out later
@ -51,6 +53,7 @@ function ritualFail(sin) {
if (!sins[sin]) { if (!sins[sin]) {
throw `Illegal Invocation of a sin!`; throw `Illegal Invocation of a sin!`;
} else { } else {
//@ts-ignore
sins[sin](); sins[sin]();
} }
} else { } else {
@ -61,7 +64,7 @@ function ritualFail(sin) {
} }
} }
function findByRitual(incantation) { function findByRitual(incantation: string) {
// I call upon the ___ of ___, ___, to ___ the ___ ___ with a ___ of name ___! // I call upon the ___ of ___, ___, to ___ the ___ ___ with a ___ of name ___!
// I call upon the embodiment of lust, Asmodeus, to bring forth the imposing object with a property of name FluxDispatcher! // I call upon the embodiment of lust, Asmodeus, to bring forth the imposing object with a property of name FluxDispatcher!
//TODO: should we do "I call upon the [great/almighty/etc].." instead of just "the"? //TODO: should we do "I call upon the [great/almighty/etc].." instead of just "the"?
@ -72,7 +75,7 @@ function findByRitual(incantation) {
args.shift() !== "upon" || args.shift() !== "upon" ||
args.shift() !== "the" args.shift() !== "the"
) { ) {
ritualFail(sins[Math.floor(Math.random() * sins.length)]); ritualFail(Object.keys(sins)[Math.floor(Math.random() * Object.keys(sins).length)]);
return; return;
} }
const embodiment = args.shift(); const embodiment = args.shift();
@ -84,27 +87,31 @@ function findByRitual(incantation) {
) { ) {
//absolutely no clue where i heard them referred to as "king sin of X" before, but i think it sounds cool so i'll keep it //absolutely no clue where i heard them referred to as "king sin of X" before, but i think it sounds cool so i'll keep it
//how did you even fuck this one up //how did you even fuck this one up
ritualFail(sins[Math.floor(Math.random() * sins.length)]); ritualFail(Object.keys(sins)[Math.floor(Math.random() * Object.keys(sins).length)]);
return; return;
} }
if (args.shift() !== "of") { if (args.shift() !== "of") {
ritualFail(sin); ritualFail(Object.keys(sins)[Math.floor(Math.random() * Object.keys(sins).length)]);
} }
//@ts-expect-error 2532
const sin = args.shift().replace(",", ""); const sin = args.shift().replace(",", "");
if (!(sin in sins)) { if (!(sin in sins)) {
//invalid sin, so we can't use it //invalid sin, so we can't use it
ritualFail(sins[Math.floor(Math.random() * sins.length)]); ritualFail(Object.keys(sins)[Math.floor(Math.random() * Object.keys(sins).length)]);
return; return;
} }
//@ts-expect-error 2532
const ruler = args.shift().replace(",", ""); const ruler = args.shift().replace(",", "");
if (!(ruler in rulers)) { if (!(ruler in rulers)) {
//invalid ruler, so we still can't use it //invalid ruler, so we still can't use it
//use the sin punishment //use the sin punishment
ritualFail(sin); ritualFail(sin);
} }
//@ts-expect-error 2532
if (rulers[ruler] !== sin) { if (rulers[ruler] !== sin) {
//sin/ruler mismatch //sin/ruler mismatch
//i feel it's more fitting to call the sin of the demon, instead of the sin you provided, as you would've angered the ruler for calling them for the wrong sin //i feel it's more fitting to call the sin of the demon, instead of the sin you provided, as you would've angered the ruler for calling them for the wrong sin
//@ts-expect-error 2532
ritualFail(rulers[ruler]); ritualFail(rulers[ruler]);
} }
if (args.shift() !== "to") { if (args.shift() !== "to") {
@ -138,6 +145,7 @@ function findByRitual(incantation) {
ritualFail(sin); ritualFail(sin);
} }
//TODO: HOW THE FUCK ARE WE SUPPOSED TO DO MULTIPLE PROPS? //TODO: HOW THE FUCK ARE WE SUPPOSED TO DO MULTIPLE PROPS?
//@ts-expect-error 2532
const prop = args.shift().slice(0, -1); const prop = args.shift().slice(0, -1);
switch (filter) { switch (filter) {
case "display": case "display":

@ -4,8 +4,12 @@ import webpack from "../../webpack";
const Checkbox = webpack.findByDisplayName("Checkbox"); const Checkbox = webpack.findByDisplayName("Checkbox");
export default class HummusUI extends React.Component { interface HummusUI extends React.Component {
constructor(props) { state: { tg: number } //we love jank!
}
class HummusUI extends React.Component {
constructor(props: any) {
super(props); super(props);
this.state = { this.state = {
tg: 0 tg: 0
@ -27,9 +31,9 @@ export default class HummusUI extends React.Component {
onChange={async () => { onChange={async () => {
toggle(k); toggle(k);
const ele = const ele =
document.getElementsByClassName( (document.getElementsByClassName(
`demon-stub-plugin-checkbox-${k}` `demon-stub-plugin-checkbox-${k}`
)[0]; )[0]) as HTMLInputElement;
//ele.value = extNest.ghost.pluginsStatus[k].running //ele.value = extNest.ghost.pluginsStatus[k].running
if (!extNest.ghost.plugins[k].enabled) { if (!extNest.ghost.plugins[k].enabled) {
ele.value = "on"; ele.value = "on";
@ -49,3 +53,5 @@ export default class HummusUI extends React.Component {
); );
} }
} }
export default HummusUI

@ -10,7 +10,10 @@ const Button = webpack.findByProps("BorderColors", "Colors");
const FormDivider = webpack.findByDisplayName("FormDivider"); const FormDivider = webpack.findByDisplayName("FormDivider");
const Switch = webpack.findByDisplayName("Switch"); const Switch = webpack.findByDisplayName("Switch");
export default (props) => { export default (props: {
nest: Nest<{plugins: any}>,
name: string
}) => {
nestsReact.useNest(props.nest); nestsReact.useNest(props.nest);
if (!props.nest.ghost.plugins[props.name]) { if (!props.nest.ghost.plugins[props.name]) {
return null; //you wouldn't think i'd have to do this but return null; //you wouldn't think i'd have to do this but

@ -6,7 +6,7 @@
import { React, nests, nestsReact } from "../../common"; import { React, nests, nestsReact } from "../../common";
import { add } from "../../plugin"; import { add } from "../../plugin";
import webpack from "../../webpack"; import webpack from "../../webpack";
import PlugCard from "./plugincard.jsx"; import PlugCard from "./plugincard";
const Header = webpack.findByProps("Sizes", "Tags"); const Header = webpack.findByProps("Sizes", "Tags");
const FormDivider = webpack.findByDisplayName("FormDivider"); const FormDivider = webpack.findByDisplayName("FormDivider");
@ -15,7 +15,7 @@ const TextInput = webpack.findByDisplayName("TextInput");
const Button = webpack.findByProps("BorderColors", "Colors"); const Button = webpack.findByProps("BorderColors", "Colors");
export default () => { export default () => {
const extNest = demon.summon("internal/nest"); const extNest: Nest<{plugins: any}> = demon.summon("internal/nest");
const [input, setInput] = React.useState(""); const [input, setInput] = React.useState("");
nestsReact.useNest(extNest); nestsReact.useNest(extNest);
return ( return (
@ -28,7 +28,7 @@ export default () => {
type="text" type="text"
value={input} value={input}
onChange={setInput} onChange={setInput}
onKeyDown={async (eve) => { onKeyDown={async (eve: {key: string}) => {
if (eve.key === "Enter") { if (eve.key === "Enter") {
const text = await ( const text = await (
await fetch("$_CORS_URL" + input) await fetch("$_CORS_URL" + input)

@ -1,7 +1,7 @@
import webpack from "../../webpack"; import webpack from "../../webpack";
import { after } from "../../patcher"; import { after } from "../../patcher";
import plugins from "./plugins.jsx"; import plugins from "./plugins";
import hummus from "./hummus.jsx"; import hummus from "./hummus";
import css from "../../css"; import css from "../../css";
import { React } from "../../common"; import { React } from "../../common";
@ -106,11 +106,11 @@ function init() {
} }
} }
function add(name, ele) { function add(name: string, ele: () => JSX.Element) {
const idx = const idx =
pluginSettings.push({ pluginSettings.push({
section: "demoncord-plugins", section: "demoncord-plugins",
label: "name", label: name,
element: ele element: ele
}) - 1; }) - 1;
return () => { return () => {

@ -6,14 +6,14 @@ const styleBg = `${styleBase} color: #1d1131; background-color: #aa8dd8; font-we
const styleTxt = `${styleBase} color: #E2EECE; font-weight: 500; font-size: 0.9em;`; const styleTxt = `${styleBase} color: #E2EECE; font-weight: 500; font-size: 0.9em;`;
//TODO: make setting to save logs in idb, for debugging and troubleshooting purposes //TODO: make setting to save logs in idb, for debugging and troubleshooting purposes
function makeLogger(print, noDemoncord = false) { function makeLogger(print: (...msg: string[]) => void, noDemoncord: boolean = false) {
return function (locs, ...message) { return function(locs: string[], ...messages: string[]): void {
message = message.join(""); let message = messages.join("");
if (locs === undefined) { if (locs === undefined) {
locs = ["Default"]; locs = ["Default"];
makeLogger("warn")( makeLogger(console.warn)(
"Requested hierarchy has not been passed to logger function, defaulting to default string", ["Logger"],
["Logger"] "Requested hierarchy has not been passed to logger function, defaulting to default string"
); );
} }
if (typeof locs === "string") { if (typeof locs === "string") {
@ -21,7 +21,7 @@ function makeLogger(print, noDemoncord = false) {
locs = ["Default"]; locs = ["Default"];
} }
let rawParts = ["Demoncord", ...locs, message]; let rawParts = ["Demoncord", ...locs, message];
let styleParts = []; let styleParts: string[] = [];
let content = ""; let content = "";
if (noDemoncord) rawParts.splice(0, 1); if (noDemoncord) rawParts.splice(0, 1);

@ -1,12 +0,0 @@
//memory leaker
export function leak(mb) {
if (!window.beelzejuice) {
window.beelzejuice = {}; //weird fanfic reference; i've seen this name used multiple times for alcoholic beverages
}
const id = Math.random().toString(36).slice(2);
window.beelzejuice[id] = new Uint8Array(Math.floor(mb * 1024 * 1024)).fill(
666
);
return () => delete window.beelzejuice[id];
}

@ -0,0 +1,11 @@
//memory leaker
export function leak(mb: number): void {
if (!window.beelzejuice) {
window.beelzejuice = []; //weird fanfic reference; i've seen this name used multiple times for alcoholic beverages
}
const id = Math.random().toString(36).slice(2);
window.beelzejuice.push(new Uint8Array(Math.floor(mb * 1024 * 1024)).fill(
666
));
}

@ -8,7 +8,7 @@ const Colors = findByProps("button", "colorRed");
const ConfirmModal = findByDisplayName("ConfirmModal"); const ConfirmModal = findByDisplayName("ConfirmModal");
const Markdown = findByDisplayNameAll("Markdown")[1]; const Markdown = findByDisplayNameAll("Markdown")[1];
function rawOpenConfirmModal(component, props, insideProps, insideContent) { function rawOpenConfirmModal(component: any, props: any, insideProps: any, insideContent: any) {
if (insideProps === undefined) { if (insideProps === undefined) {
insideProps = {}; insideProps = {};
} }
@ -16,7 +16,7 @@ function rawOpenConfirmModal(component, props, insideProps, insideContent) {
insideContent = ""; insideContent = "";
} }
let confirmed; let confirmed;
openModal((e) => { openModal((e: {transitionState: any, onClose: () => void}) => {
if (e.transitionState === 3) { if (e.transitionState === 3) {
return false; //TODO: the fuck does this do? return false; //TODO: the fuck does this do?
} }
@ -24,11 +24,14 @@ function rawOpenConfirmModal(component, props, insideProps, insideContent) {
return ( return (
<ConfirmModal <ConfirmModal
transitionState={e.transitionState} transitionState={e.transitionState}
onClose={() => (confirmed = false)} onClose={() => (confirmed = false)}
//@ts-ignore
onCancel={() => (confirmed = false & e.onClose())} onCancel={() => (confirmed = false & e.onClose())}
//@ts-ignore
onConfirm={() => (confirmed = true & e.onClose())} onConfirm={() => (confirmed = true & e.onClose())}
{...props} {...props}
> >
{/* @ts-ignore */}
<component {...insideProps}>{insideContent}</component> <component {...insideProps}>{insideContent}</component>
</ConfirmModal> </ConfirmModal>
); );
@ -37,7 +40,12 @@ function rawOpenConfirmModal(component, props, insideProps, insideContent) {
return confirmed; return confirmed;
} }
function openConfirmModal(content, type, opts) { function openConfirmModal(content: string, type: string, opts: {
header: string,
confirmText: string,
cancelText: string,
color: any
}) {
let buttonColor; let buttonColor;
if (!!opts.color) { if (!!opts.color) {
buttonColor = opts.color; buttonColor = opts.color;

@ -1,10 +1,20 @@
let getModules; type Filter = (module: any) => boolean
interface Module {
exports: {
default?: any
__esModule?: any
}
}
let getModules: () => [];
//check for hummus //check for hummus
//TODO: nested conditional so we can *maybe* work with RN? //TODO: nested conditional so we can *maybe* work with RN?
//TODO: account for different versions of webpackJsonp, ie ones that aren't a function (if/when hummus-like things come out) //TODO: account for different versions of webpackJsonp, ie ones that aren't a function (if/when hummus-like things come out)
if (!window.webpackChunkdiscord_app) { if (!window.webpackChunkdiscord_app) {
let modules = webpackJsonp( let modules: {
c: []
} = window.webpackJsonp(
[], [],
[ [
(mod, _exports, req) => { (mod, _exports, req) => {
@ -14,18 +24,20 @@ if (!window.webpackChunkdiscord_app) {
); );
getModules = () => modules.c; getModules = () => modules.c;
} else { } else {
let modules = {}; let modules: {
c: []
};
window.webpackChunkdiscord_app.push([ window.webpackChunkdiscord_app.push([
[Math.random().toString(36)], [Math.random().toString(36)],
{}, {},
(e) => { (e: {c:[]}) => {
modules = e; modules = e;
} }
]); ]);
getModules = () => modules.c; getModules = () => modules.c;
} }
function filter(filter, moduleList) { function filter(filter: Filter, moduleList: Module[]) {
let modules = []; let modules = [];
for (const mod in moduleList) { for (const mod in moduleList) {
const module = moduleList[mod].exports; const module = moduleList[mod].exports;
@ -44,25 +56,25 @@ let webpack = {
modules: getModules(), modules: getModules(),
getModules, getModules,
filter: filter, filter: filter,
find: (filter) => webpack.filter(filter, webpack.modules)[0], find: (filter: Filter) => webpack.filter(filter, webpack.modules)[0],
findAll: (filter) => webpack.filter(filter, webpack.modules), findAll: (filter: Filter) => webpack.filter(filter, webpack.modules),
findByProps: (...props) => { findByProps: (...props: any[]) => {
return webpack.find((module) => { return webpack.find((module) => {
return props.every((prop) => module[prop] !== undefined); return props.every((prop) => module[prop] !== undefined);
}); });
}, },
findByPropsAll: (...props) => { findByPropsAll: (...props: any[]) => {
return webpack.findAll((module) => return webpack.findAll((module) =>
props.every((prop) => module[prop] !== undefined) props.every((prop) => module[prop] !== undefined)
); );
}, },
findByDisplayName: (prop) => { findByDisplayName: (prop: any) => {
return webpack.find((m) => m?.displayName === prop); return webpack.find((m) => m?.displayName === prop);
}, },
findByDisplayNameAll: (prop) => { findByDisplayNameAll: (prop: any) => {
return webpack.findAll((m) => m?.displayName === prop); return webpack.findAll((m) => m?.displayName === prop);
}, },
findByStrings: (...props) => { findByStrings: (...props: string[]) => {
return webpack.find((module) => return webpack.find((module) =>
props.every((prop) => module.toString().contains(prop)) props.every((prop) => module.toString().contains(prop))
); );

39
src/global.d.ts vendored

@ -0,0 +1,39 @@
interface Nest<Schema> {
ghost: Schema,
store: Schema,
on: (event: string, callback: (eve: string, { path, value }: { path: string[] | string, value: any }) => void) => void,
get: any,
set: any,
delete: any,
update: any,
listeners: any,
once: any,
off: any,
emit: any
}
type DemonGlobal = {
summon: (mod: string) => any
}
const demon: DemonGlobal
interface Window {
demon: DemonGlobal
beelzejuice: Uint8Array[]
webpackChunkdiscord_app: any
webpackJsonp: (thing1: [], thing2: [(mod: any, _exports: any, req: any) => void]) => any
}
namespace JSX {
interface IntrinsicElements {
hr: any
svg: any
path: any
div: any
label: any
span: any
}
}
const _: any

@ -1,17 +1,17 @@
import webpack from "./api/webpack.js"; import webpack from "./api/webpack";
import common from "./api/common.js"; import common from "./api/common";
import utils from "./api/utils/index.js"; import utils from "./api/utils/index";
import plugins from "./api/plugin.js"; import plugins from "./api/plugin";
import settings from "./api/ui/settings/settings.js"; import settings from "./api/ui/settings/settings";
import css from "./api/css.js"; import css from "./api/css";
import patcher from "./api/patcher.js"; import patcher from "./api/patcher";
import findByRitual from "./api/ritual.js"; import findByRitual from "./api/ritual";
Object.assign(webpack, { Object.assign(webpack, {
findByRitual findByRitual
}); });
const demon = { const demon: Record<string, any> = {
modules: { modules: {
webpack, webpack,
common common
@ -37,7 +37,7 @@ const demon = {
settings settings
}; };
function summon(mod) { function summon(mod: string) {
const mods = mod.split("/"); const mods = mod.split("/");
let res = demon; let res = demon;
mods.forEach((m) => { mods.forEach((m) => {

@ -0,0 +1,87 @@
{
"compilerOptions": {
"jsx": "preserve",
"paths": {
"nests/*": ["./node_modules/nests/esm/*"]
},
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Language and Environment */
"target": "ESNext",
/* Modules */
"module": "ESNext" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
// "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
// "resolveJsonModule": true, /* Enable importing .json files */
// "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
/* JavaScript Support */
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
/* Emit */
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
// "outDir": "./", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */,
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
/* Type Checking */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
// "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
// "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
// "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
// "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
// "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
// "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
/* Completeness */
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"include": ["src/*", "src/**/*"],
"exclude": [],
}
Loading…
Cancel
Save