You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.2 KiB
46 lines
1.2 KiB
// @flow
|
|
const commandsSym = Symbol("__commands");
|
|
|
|
function init(obj: Object) {
|
|
const { after } = window.demon.require("patcher")
|
|
const { findByProps } = window.demon.require("webpack")
|
|
window.demonCommands = {}
|
|
window.demonCommands[commandsSym] = {};
|
|
after(
|
|
"sendMessage",
|
|
findByProps("sendMessage"),
|
|
(args, otherRes) => {
|
|
let res;
|
|
for (const key of Reflect.ownKeys(window.demonCommands[commandsSym])) {
|
|
let command = window.demonCommands[commandsSym][key];
|
|
if (args[1].content.split(" ")[0] === ">" + command.name) {
|
|
res = command.callback(args);
|
|
break;
|
|
}
|
|
}
|
|
if (res !== undefined) args[1].content = res;
|
|
return args;
|
|
}
|
|
);
|
|
}
|
|
|
|
// command = {
|
|
// name: "name",
|
|
// callback: (args)=>"Hello, world!"
|
|
// }
|
|
function add(command: {
|
|
name: string,
|
|
callback: (args: Array<any>) => string
|
|
}): () => void {
|
|
let sym = Symbol(command.name);
|
|
window.demonCommands[commandsSym][sym] = command;
|
|
return () => {
|
|
delete window.demonCommands[commandsSym][sym];
|
|
};
|
|
}
|
|
|
|
export default {
|
|
add: add,
|
|
init: init
|
|
};
|