aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commands/dev/eval.ts20
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts56
2 files changed, 40 insertions, 36 deletions
diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts
index cbc6518..2f61822 100644
--- a/src/commands/dev/eval.ts
+++ b/src/commands/dev/eval.ts
@@ -22,11 +22,11 @@ export default class EvalCommand extends BushCommand {
{ id: 'typescript', match: 'flag', flag: '--ts' },
{ id: 'hidden', match: 'flag', flag: '--hidden' },
{ id: 'show_proto', match: 'flag', flag: '--proto' },
- // {
- // id: 'show_methods',
- // match: 'flag',
- // flag: ['--func', '--function', '--functions', '--meth', '--method', '--methods']
- // },
+ {
+ id: 'show_methods',
+ match: 'flag',
+ flag: ['--func', '--function', '--functions', '--meth', '--method', '--methods']
+ },
{
id: 'code',
match: 'rest',
@@ -42,8 +42,8 @@ export default class EvalCommand extends BushCommand {
{ name: 'silent', description: 'Whether or not to make the response silent', type: 'BOOLEAN', required: false },
{ name: 'typescript', description: 'Whether or not the code is typescript.', type: 'BOOLEAN', required: false },
{ name: 'hidden', description: 'Whether or not to show hidden items.', type: 'BOOLEAN', required: false },
- { name: 'show_proto', description: 'Show prototype.', type: 'BOOLEAN', required: false }
- // { name: 'show_methods', description: 'Show class functions.', type: 'BOOLEAN', required: false }
+ { name: 'show_proto', description: 'Show prototype.', type: 'BOOLEAN', required: false },
+ { name: 'show_methods', description: 'Show class functions.', type: 'BOOLEAN', required: false }
],
ownerOnly: true
});
@@ -60,7 +60,7 @@ export default class EvalCommand extends BushCommand {
typescript: boolean;
hidden: boolean;
show_proto: boolean;
- // show_methods: boolean;
+ show_methods: boolean;
}
): Promise<unknown> {
if (!message.author.isOwner())
@@ -130,7 +130,7 @@ export default class EvalCommand extends BushCommand {
getters: true,
showProxy: true
});
- // const methods = args.show_methods ? await util.inspectCleanRedactCodeblock(util.getMethods(rawOutput), 'js') : undefined;
+ const methods = args.show_methods ? await util.inspectCleanRedactCodeblock(util.getMethods(rawOutput), 'js') : undefined;
const proto = args.show_proto
? await util.inspectCleanRedactCodeblock(Object.getPrototypeOf(rawOutput), 'js', {
depth: 1,
@@ -143,7 +143,7 @@ export default class EvalCommand extends BushCommand {
if (inputTS) embed.addField('📥 Input (typescript)', inputTS).addField('📥 Input (transpiled javascript)', inputJS);
else embed.addField('📥 Input', inputJS);
embed.addField('📤 Output', output);
- // if (methods) embed.addField('🔧 Methods', methods);
+ if (methods) embed.addField('🔧 Methods', methods);
if (proto) embed.addField('⚙️ Proto', proto);
} catch (e) {
embed.setTitle(`${emojis.errorFull} Unable to Evaluate Expression`).setColor(colors.error);
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