prettierify: post-typescriptification edition

cleanup
Drake 2 years ago
parent 58a699f174
commit 7ad06970a5

@ -11,6 +11,12 @@ module.exports = {
options: {
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 jscc from "rollup-plugin-jscc";
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);

@ -1,12 +1,16 @@
type BeforeFunc = (args: any[]) => void
type InsteadFunc = (args: any[], orig: (...args: any) => any) => any
type AfterFunc = (args: any[], res: any) => any
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
}) {
function wackyPatch(
parentObj: any,
name: string,
patches: {
before?: BeforeFunc;
instead?: InsteadFunc;
after?: AfterFunc;
}
) {
if (typeof parentObj === "string") {
//assume parentObj and name are switched around (for backcompat/convienence)
const tmp = parentObj;
@ -18,12 +22,16 @@ function wackyPatch(parentObj: any, name: string, patches: {
const instead = patches["instead"];
const after = patches["after"];
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]);
const res =
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)])
? //@ts-ignore; TS thinks that `instead` possibly being undefined is bad (meanwhile we literally check for that)
instead.apply(ctx, [args, target.bind(ctx)])
: target.apply(ctx, args);
if (after === undefined) return 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)
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
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(
["Plugins"],
`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 { leak } from "./utils/memory";
type Sins = Record<string, (() => void) | null>
type Sins = Record<string, (() => void) | null>;
const sins: Sins = {
Lust: null,
@ -75,7 +75,11 @@ function findByRitual(incantation: string) {
args.shift() !== "upon" ||
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;
}
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
//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;
}
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
const sin = args.shift().replace(",", "");
if (!(sin in sins)) {
//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;
}
//@ts-expect-error 2532

@ -5,7 +5,7 @@ import webpack from "../../webpack";
const Checkbox = webpack.findByDisplayName("Checkbox");
interface HummusUI extends React.Component {
state: { tg: number } //we love jank!
state: { tg: number }; //we love jank!
}
class HummusUI extends React.Component {
@ -31,9 +31,9 @@ class HummusUI extends React.Component {
onChange={async () => {
toggle(k);
const ele =
(document.getElementsByClassName(
document.getElementsByClassName(
`demon-stub-plugin-checkbox-${k}`
)[0]) as HTMLInputElement;
)[0] as HTMLInputElement;
//ele.value = extNest.ghost.pluginsStatus[k].running
if (!extNest.ghost.plugins[k].enabled) {
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 Switch = webpack.findByDisplayName("Switch");
export default (props: {
nest: Nest<{plugins: any}>,
name: string
}) => {
export default (props: { nest: Nest<{ plugins: any }>; name: string }) => {
nestsReact.useNest(props.nest);
if (!props.nest.ghost.plugins[props.name]) {
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");
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("");
nestsReact.useNest(extNest);
return (
@ -28,7 +28,7 @@ export default () => {
type="text"
value={input}
onChange={setInput}
onKeyDown={async (eve: {key: string}) => {
onKeyDown={async (eve: { key: string }) => {
if (eve.key === "Enter") {
const text = await (
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;`;
//TODO: make setting to save logs in idb, for debugging and troubleshooting purposes
function makeLogger(print: (...msg: string[]) => void, noDemoncord: boolean = false) {
return function(locs: string[], ...messages: string[]): void {
function makeLogger(
print: (...msg: string[]) => void,
noDemoncord: boolean = false
) {
return function (locs: string[], ...messages: string[]): void {
let message = messages.join("");
if (locs === undefined) {
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
}
const id = Math.random().toString(36).slice(2);
window.beelzejuice.push(new Uint8Array(Math.floor(mb * 1024 * 1024)).fill(
666
));
window.beelzejuice.push(
new Uint8Array(Math.floor(mb * 1024 * 1024)).fill(666)
);
}

@ -8,7 +8,12 @@ const Colors = findByProps("button", "colorRed");
const ConfirmModal = findByDisplayName("ConfirmModal");
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) {
insideProps = {};
}
@ -16,7 +21,7 @@ function rawOpenConfirmModal(component: any, props: any, insideProps: any, insid
insideContent = "";
}
let confirmed;
openModal((e: {transitionState: any, onClose: () => void}) => {
openModal((e: { transitionState: any; onClose: () => void }) => {
if (e.transitionState === 3) {
return false; //TODO: the fuck does this do?
}
@ -24,10 +29,10 @@ function rawOpenConfirmModal(component: any, props: any, insideProps: any, insid
return (
<ConfirmModal
transitionState={e.transitionState}
onClose={() => (confirmed = false)}
onClose={() => (confirmed = false)}
//@ts-ignore
onCancel={() => (confirmed = false & e.onClose())}
//@ts-ignore
//@ts-ignore
onConfirm={() => (confirmed = true & e.onClose())}
{...props}
>
@ -40,12 +45,16 @@ function rawOpenConfirmModal(component: any, props: any, insideProps: any, insid
return confirmed;
}
function openConfirmModal(content: string, type: string, opts: {
header: string,
confirmText: string,
cancelText: string,
color: any
}) {
function openConfirmModal(
content: string,
type: string,
opts: {
header: string;
confirmText: string;
cancelText: string;
color: any;
}
) {
let buttonColor;
if (!!opts.color) {
buttonColor = opts.color;

@ -1,9 +1,9 @@
type Filter = (module: any) => boolean
type Filter = (module: any) => boolean;
interface Module {
exports: {
default?: any
__esModule?: any
}
default?: any;
__esModule?: any;
};
}
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)
if (!window.webpackChunkdiscord_app) {
let modules: {
c: []
c: [];
} = window.webpackJsonp(
[],
[
@ -25,12 +25,12 @@ if (!window.webpackChunkdiscord_app) {
getModules = () => modules.c;
} else {
let modules: {
c: []
c: [];
};
window.webpackChunkdiscord_app.push([
[Math.random().toString(36)],
{},
(e: {c:[]}) => {
(e: { c: [] }) => {
modules = e;
}
]);

35
src/global.d.ts vendored

@ -1,19 +1,25 @@
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,
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
summon: (mod: string) => any
}
const demon: DemonGlobal
@ -22,7 +28,10 @@ interface Window {
demon: DemonGlobal
beelzejuice: Uint8Array[]
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 {
@ -36,4 +45,4 @@ namespace JSX {
}
}
const _: any
const _: any

@ -2,7 +2,7 @@
"compilerOptions": {
"jsx": "preserve",
"paths": {
"nests/*": ["./node_modules/nests/esm/*"]
"nests/*": ["./node_modules/nests/esm/*"]
},
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Language and Environment */
@ -10,7 +10,7 @@
/* 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. */
"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. */
@ -82,6 +82,6 @@
// "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": [],
"include": ["src/*", "src/**/*"],
"exclude": []
}

Loading…
Cancel
Save