diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-09-03 09:49:14 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-09-03 09:49:14 -0400 |
commit | 87d58eb925d0bde22626eb3a1e9ea03ab97d3a29 (patch) | |
tree | bd3229128608c90fd57d7ae152c1b42df5b94ba2 /src/lib | |
parent | af845599600c3e3d72b3165bfbc9da7e4aa015bd (diff) | |
download | tanzanite-87d58eb925d0bde22626eb3a1e9ea03ab97d3a29.tar.gz tanzanite-87d58eb925d0bde22626eb3a1e9ea03ab97d3a29.tar.bz2 tanzanite-87d58eb925d0bde22626eb3a1e9ea03ab97d3a29.zip |
eval methods
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 56 |
1 files changed, 30 insertions, 26 deletions
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 |