From 87d58eb925d0bde22626eb3a1e9ea03ab97d3a29 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 3 Sep 2021 09:49:14 -0400 Subject: eval methods --- .../extensions/discord-akairo/BushClientUtil.ts | 56 ++++++++++++---------- 1 file changed, 30 insertions(+), 26 deletions(-) (limited to 'src/lib') diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index c80bfb2..56e2c13 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -1430,32 +1430,36 @@ export class BushClientUtil extends ClientUtil { return client.constants.pronounMapping[apiRes.pronouns]; } - //~ modified from https://stackoverflow.com/questions/31054910/get-functions-methods-of-a-class - //~ answer by Bruno Grieder - //~ public getMethods(obj: any): string { - //~ let props = []; - - //~ do { - //~ const l = Object.getOwnPropertyNames(obj) - //~ .concat(Object.getOwnPropertySymbols(obj).map((s) => s.toString())) - //~ .sort() - //~ .filter( - //~ (p, i, arr) => - //~ typeof obj[p] === 'function' && //only the methods - //~ p !== 'constructor' && //not the constructor - //~ (i == 0 || p !== arr[i - 1]) && //not overriding in this prototype - //~ props.indexOf(p) === -1 //not overridden in a child - //~ ); - //~ props = props.concat( - //~ l /* .map((p) => (obj[p] && obj[p][Symbol.toStringTag] === 'AsyncFunction' ? 'async ' : '' + p + '();')) */ - //~ ); - //~ } while ( - //~ (obj = Object.getPrototypeOf(obj)) && //walk-up the prototype chain - //~ Object.getPrototypeOf(obj) //not the the Object prototype methods (hasOwnProperty, etc...) - //~ ); - - //~ return props.join('\n'); - //~ } + // modified from https://stackoverflow.com/questions/31054910/get-functions-methods-of-a-class + // answer by Bruno Grieder + public getMethods(obj: any): string { + let props: string[] = []; + + do { + const l = Object.getOwnPropertyNames(obj) + .concat(Object.getOwnPropertySymbols(obj).map((s) => s.toString())) + .sort() + .filter( + (p, i, arr) => + typeof Object.getOwnPropertyDescriptor(obj, p)?.['get'] !== 'function' && // ignore getters + typeof Object.getOwnPropertyDescriptor(obj, p)?.['set'] !== 'function' && // ignore setters + typeof obj[p] === 'function' && //only the methods + p !== 'constructor' && //not the constructor + (i == 0 || p !== arr[i - 1]) && //not overriding in this prototype + props.indexOf(p) === -1 //not overridden in a child + ); + l.forEach((p) => console.debug(Object.getOwnPropertyDescriptor(obj, p))); + + props = props.concat( + l.map((p) => (obj[p] && obj[p][Symbol.toStringTag] === 'AsyncFunction' ? `async ${p}();` : `${p}();`)) + ); + } while ( + (obj = Object.getPrototypeOf(obj)) && //walk-up the prototype chain + Object.getPrototypeOf(obj) //not the the Object prototype methods (hasOwnProperty, etc...) + ); + + return props.join('\n'); + } /** * Discord.js's Util class -- cgit