prettierify: post-typescriptification edition

cleanup
Drake 2 years ago
parent 58a699f174
commit 7ad06970a5

@ -11,6 +11,12 @@ module.exports = {
options: { options: {
parser: "babel" parser: "babel"
} }
},
{
files: "*.d.ts",
options: {
semi: false
}
} }
] ]
}; };

@ -8,7 +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'; import typescript from "@rollup/plugin-typescript";
const projectRootDir = resolvePath(__dirname); const projectRootDir = resolvePath(__dirname);

@ -1,12 +1,16 @@
type BeforeFunc = (args: any[]) => void type BeforeFunc = (args: any[]) => void;
type InsteadFunc = (args: any[], orig: (...args: any) => any) => any type InsteadFunc = (args: any[], orig: (...args: any) => any) => any;
type AfterFunc = (args: any[], res: any) => any type AfterFunc = (args: any[], res: any) => any;
function wackyPatch(parentObj: any, name: string, patches: { function wackyPatch(
before?: BeforeFunc, parentObj: any,
instead?: InsteadFunc, name: string,
after?: AfterFunc 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;
@ -18,12 +22,16 @@ function wackyPatch(parentObj: any, name: string, patches: {
const instead = patches["instead"]; const instead = patches["instead"];
const after = patches["after"]; const after = patches["after"];
const handler = { const handler = {
apply: (target: () => any, thisArg: any, [ctx, args]: [ctx: any, 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) ? //@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;
return after.apply(ctx, [args, res]); return after.apply(ctx, [args, res]);

@ -13,10 +13,13 @@ import logger from "./utils/logger";
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) 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: Nest<{plugins: any}>; let pluginNest: Nest<{ plugins: any }>;
const pluginEval = (iife: string) => (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: string, { path, value }: { path: string[] | string, value: any }) { 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}`

@ -2,7 +2,7 @@ import webpack from "./webpack";
import { instead } from "./patcher"; import { instead } from "./patcher";
import { leak } from "./utils/memory"; import { leak } from "./utils/memory";
type Sins = Record<string, (() => void) | null> type Sins = Record<string, (() => void) | null>;
const sins: Sins = { const sins: Sins = {
Lust: null, Lust: null,
@ -75,7 +75,11 @@ function findByRitual(incantation: string) {
args.shift() !== "upon" || args.shift() !== "upon" ||
args.shift() !== "the" args.shift() !== "the"
) { ) {
ritualFail(Object.keys(sins)[Math.floor(Math.random() * Object.keys(sins).length)]); ritualFail(
Object.keys(sins)[
Math.floor(Math.random() * Object.keys(sins).length)
]
);
return; return;
} }
const embodiment = args.shift(); const embodiment = args.shift();
@ -87,17 +91,29 @@ function findByRitual(incantation: string) {
) { ) {
//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(Object.keys(sins)[Math.floor(Math.random() * Object.keys(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(Object.keys(sins)[Math.floor(Math.random() * Object.keys(sins).length)]); ritualFail(
Object.keys(sins)[
Math.floor(Math.random() * Object.keys(sins).length)
]
);
} }
//@ts-expect-error 2532 //@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(Object.keys(sins)[Math.floor(Math.random() * Object.keys(sins).length)]); ritualFail(
Object.keys(sins)[
Math.floor(Math.random() * Object.keys(sins).length)
]
);
return; return;
} }
//@ts-expect-error 2532 //@ts-expect-error 2532

@ -5,7 +5,7 @@ import webpack from "../../webpack";
const Checkbox = webpack.findByDisplayName("Checkbox"); const Checkbox = webpack.findByDisplayName("Checkbox");
interface HummusUI extends React.Component { interface HummusUI extends React.Component {
state: { tg: number } //we love jank! state: { tg: number }; //we love jank!
} }
class HummusUI extends React.Component { class HummusUI extends React.Component {
@ -31,9 +31,9 @@ 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]) as HTMLInputElement; )[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";
@ -54,4 +54,4 @@ class HummusUI extends React.Component {
} }
} }
export default HummusUI export default HummusUI;

@ -10,10 +10,7 @@ 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 }) => {
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

@ -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: Nest<{plugins: any}> = 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: {key: string}) => { 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)

@ -6,8 +6,11 @@ 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: (...msg: string[]) => void, noDemoncord: boolean = false) { function makeLogger(
return function(locs: string[], ...messages: string[]): void { print: (...msg: string[]) => void,
noDemoncord: boolean = false
) {
return function (locs: string[], ...messages: string[]): void {
let message = messages.join(""); let message = messages.join("");
if (locs === undefined) { if (locs === undefined) {
locs = ["Default"]; locs = ["Default"];

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

@ -8,7 +8,12 @@ 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: any, props: any, insideProps: any, insideContent: any) { function rawOpenConfirmModal(
component: any,
props: any,
insideProps: any,
insideContent: any
) {
if (insideProps === undefined) { if (insideProps === undefined) {
insideProps = {}; insideProps = {};
} }
@ -16,7 +21,7 @@ function rawOpenConfirmModal(component: any, props: any, insideProps: any, insid
insideContent = ""; insideContent = "";
} }
let confirmed; let confirmed;
openModal((e: {transitionState: any, onClose: () => void}) => { 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,10 +29,10 @@ function rawOpenConfirmModal(component: any, props: any, insideProps: any, insid
return ( return (
<ConfirmModal <ConfirmModal
transitionState={e.transitionState} transitionState={e.transitionState}
onClose={() => (confirmed = false)} onClose={() => (confirmed = false)}
//@ts-ignore //@ts-ignore
onCancel={() => (confirmed = false & e.onClose())} onCancel={() => (confirmed = false & e.onClose())}
//@ts-ignore //@ts-ignore
onConfirm={() => (confirmed = true & e.onClose())} onConfirm={() => (confirmed = true & e.onClose())}
{...props} {...props}
> >
@ -40,12 +45,16 @@ function rawOpenConfirmModal(component: any, props: any, insideProps: any, insid
return confirmed; return confirmed;
} }
function openConfirmModal(content: string, type: string, opts: { function openConfirmModal(
header: string, content: string,
confirmText: string, type: string,
cancelText: string, opts: {
color: any 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,9 +1,9 @@
type Filter = (module: any) => boolean type Filter = (module: any) => boolean;
interface Module { interface Module {
exports: { exports: {
default?: any default?: any;
__esModule?: any __esModule?: any;
} };
} }
let getModules: () => []; let getModules: () => [];
@ -13,7 +13,7 @@ let getModules: () => [];
//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: { let modules: {
c: [] c: [];
} = window.webpackJsonp( } = window.webpackJsonp(
[], [],
[ [
@ -25,12 +25,12 @@ if (!window.webpackChunkdiscord_app) {
getModules = () => modules.c; getModules = () => modules.c;
} else { } else {
let modules: { let modules: {
c: [] c: [];
}; };
window.webpackChunkdiscord_app.push([ window.webpackChunkdiscord_app.push([
[Math.random().toString(36)], [Math.random().toString(36)],
{}, {},
(e: {c:[]}) => { (e: { c: [] }) => {
modules = e; modules = e;
} }
]); ]);

35
src/global.d.ts vendored

@ -1,19 +1,25 @@
interface Nest<Schema> { interface Nest<Schema> {
ghost: Schema, ghost: Schema
store: Schema, store: Schema
on: (event: string, callback: (eve: string, { path, value }: { path: string[] | string, value: any }) => void) => void, on: (
get: any, event: string,
set: any, callback: (
delete: any, eve: string,
update: any, { path, value }: { path: string[] | string; value: any }
listeners: any, ) => void
once: any, ) => void
off: any, get: any
set: any
delete: any
update: any
listeners: any
once: any
off: any
emit: any emit: any
} }
type DemonGlobal = { type DemonGlobal = {
summon: (mod: string) => any summon: (mod: string) => any
} }
const demon: DemonGlobal const demon: DemonGlobal
@ -22,7 +28,10 @@ interface Window {
demon: DemonGlobal demon: DemonGlobal
beelzejuice: Uint8Array[] beelzejuice: Uint8Array[]
webpackChunkdiscord_app: any webpackChunkdiscord_app: any
webpackJsonp: (thing1: [], thing2: [(mod: any, _exports: any, req: any) => void]) => any webpackJsonp: (
thing1: [],
thing2: [(mod: any, _exports: any, req: any) => void]
) => any
} }
namespace JSX { namespace JSX {
@ -36,4 +45,4 @@ namespace JSX {
} }
} }
const _: any const _: any

@ -2,7 +2,7 @@
"compilerOptions": { "compilerOptions": {
"jsx": "preserve", "jsx": "preserve",
"paths": { "paths": {
"nests/*": ["./node_modules/nests/esm/*"] "nests/*": ["./node_modules/nests/esm/*"]
}, },
/* Visit https://aka.ms/tsconfig.json to read more about this file */ /* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Language and Environment */ /* Language and Environment */
@ -10,7 +10,7 @@
/* Modules */ /* Modules */
"module": "ESNext" /* Specify what module code is generated. */, "module": "ESNext" /* Specify what module code is generated. */,
// "rootDir": "./", /* Specify the root folder within your source files. */ // "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ "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. */ // "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. */ // "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. */ // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
@ -82,6 +82,6 @@
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */ "skipLibCheck": true /* Skip type checking all .d.ts files. */
}, },
"include": ["src/*", "src/**/*"], "include": ["src/*", "src/**/*"],
"exclude": [], "exclude": []
} }

Loading…
Cancel
Save