typescriptification: part webpack

typescript
Drake 2 years ago
parent 0c97beef46
commit e8722c4999

@ -1,8 +1,12 @@
import webpack from "./webpack.js";
import { instead } from "./patcher.js";
import { leak } from "./utils/memory.js";
const sins = {
type Sins = Record<string, (() => void) | null>
const sins: Sins = {
Lust: null,
Pride: null,
Greed: null,
@ -41,7 +45,7 @@ const rulers = {
Belphegor: "Sloth"
};
function ritualFail(sin) {
function ritualFail(sin: string) {
if (Math.random() > 0.5) {
//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
@ -51,6 +55,7 @@ function ritualFail(sin) {
if (!sins[sin]) {
throw `Illegal Invocation of a sin!`;
} else {
//@ts-ignore
sins[sin]();
}
} else {
@ -61,7 +66,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 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"?
@ -72,7 +77,7 @@ function findByRitual(incantation) {
args.shift() !== "upon" ||
args.shift() !== "the"
) {
ritualFail(sins[Math.floor(Math.random() * sins.length)]);
ritualFail(Object.keys(sins)[Math.floor(Math.random() * Object.keys(sins).length)]);
return;
}
const embodiment = args.shift();
@ -84,27 +89,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
//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;
}
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(",", "");
if (!(sin in sins)) {
//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;
}
//@ts-expect-error 2532
const ruler = args.shift().replace(",", "");
if (!(ruler in rulers)) {
//invalid ruler, so we still can't use it
//use the sin punishment
ritualFail(sin);
}
//@ts-expect-error 2532
if (rulers[ruler] !== sin) {
//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
//@ts-expect-error 2532
ritualFail(rulers[ruler]);
}
if (args.shift() !== "to") {
@ -138,6 +147,7 @@ function findByRitual(incantation) {
ritualFail(sin);
}
//TODO: HOW THE FUCK ARE WE SUPPOSED TO DO MULTIPLE PROPS?
//@ts-expect-error 2532
const prop = args.shift().slice(0, -1);
switch (filter) {
case "display":

@ -1,10 +1,20 @@
let getModules;
type Filter = (module: any) => boolean
interface Module {
exports: {
default?: any
__esModule?: any
}
}
let getModules: () => [];
//check for hummus
//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)
if (!window.webpackChunkdiscord_app) {
let modules = webpackJsonp(
let modules: {
c: []
} = window.webpackJsonp(
[],
[
(mod, _exports, req) => {
@ -14,18 +24,20 @@ if (!window.webpackChunkdiscord_app) {
);
getModules = () => modules.c;
} else {
let modules = {};
let modules: {
c: []
};
window.webpackChunkdiscord_app.push([
[Math.random().toString(36)],
{},
(e) => {
(e: {c:[]}) => {
modules = e;
}
]);
getModules = () => modules.c;
}
function filter(filter, moduleList) {
function filter(filter: Filter, moduleList: Module[]) {
let modules = [];
for (const mod in moduleList) {
const module = moduleList[mod].exports;
@ -44,25 +56,25 @@ let webpack = {
modules: getModules(),
getModules,
filter: filter,
find: (filter) => webpack.filter(filter, webpack.modules)[0],
findAll: (filter) => webpack.filter(filter, webpack.modules),
findByProps: (...props) => {
find: (filter: Filter) => webpack.filter(filter, webpack.modules)[0],
findAll: (filter: Filter) => webpack.filter(filter, webpack.modules),
findByProps: (...props: any[]) => {
return webpack.find((module) => {
return props.every((prop) => module[prop] !== undefined);
});
},
findByPropsAll: (...props) => {
findByPropsAll: (...props: any[]) => {
return webpack.findAll((module) =>
props.every((prop) => module[prop] !== undefined)
);
},
findByDisplayName: (prop) => {
findByDisplayName: (prop: any) => {
return webpack.find((m) => m?.displayName === prop);
},
findByDisplayNameAll: (prop) => {
findByDisplayNameAll: (prop: any) => {
return webpack.findAll((m) => m?.displayName === prop);
},
findByStrings: (...props) => {
findByStrings: (...props: string[]) => {
return webpack.find((module) =>
props.every((prop) => module.toString().contains(prop))
);

1
src/global.d.ts vendored

@ -19,6 +19,7 @@ const demon: {
interface Window {
beelzejuice: Uint8Array[]
webpackChunkdiscord_app: any
webpackJsonp: (thing1: [], thing2: [(mod: any, _exports: any, req: any) => void]) => any
}
namespace JSX {

Loading…
Cancel
Save