// @flow const commandsSym = Symbol("__commands"); function init(obj: Object) { obj.demon[commandsSym] = {}; obj.demon.patcher.after( "sendMessage", obj.demon.webpack.findByProps("sendMessage"), (args, otherRes) => { let res; for (const key of Reflect.ownKeys(obj.demon[commandsSym])) { let command = obj.demon[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) => string }): () => void { let sym = Symbol(command.name); window.demon[commandsSym][sym] = command; return () => { delete window.demon[commandsSym][sym]; }; } export default { add: add, init: init };