aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commands/dev/eval.ts11
-rw-r--r--src/commands/utilities/viewraw.ts33
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts27
-rw-r--r--src/listeners/client/interactionCreate.ts11
-rw-r--r--yarn.lock4
5 files changed, 73 insertions, 13 deletions
diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts
index 19667dd..5b44db2 100644
--- a/src/commands/dev/eval.ts
+++ b/src/commands/dev/eval.ts
@@ -22,6 +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: 'code',
match: 'rest',
@@ -38,6 +43,7 @@ export default class EvalCommand extends BushCommand {
{ 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 }
],
ownerOnly: true
});
@@ -54,6 +60,7 @@ export default class EvalCommand extends BushCommand {
typescript: boolean;
hidden: boolean;
show_proto: boolean;
+ // show_methods: boolean;
}
): Promise<unknown> {
if (!message.author.isOwner())
@@ -114,11 +121,12 @@ export default class EvalCommand extends BushCommand {
try {
const rawOutput = code[code.lang].replace(/ /g, '').includes('9+10' || '10+9') ? '21' : await eval(code.js);
const output = await util.inspectCleanRedactCodeblock(rawOutput, 'js', {
- depth: args.sel_depth || 0,
+ depth: args.sel_depth ?? 0,
showHidden: args.hidden,
getters: true,
showProxy: true
});
+ // 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,
@@ -131,6 +139,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 (proto) embed.addField('⚙️ Proto', proto);
} catch (e) {
embed.setTitle(`${emojis.errorFull} Code was not able to be evaluated.`).setColor(colors.error);
diff --git a/src/commands/utilities/viewraw.ts b/src/commands/utilities/viewraw.ts
index 0a5f9e2..e783dec 100644
--- a/src/commands/utilities/viewraw.ts
+++ b/src/commands/utilities/viewraw.ts
@@ -31,12 +31,17 @@ export default class ViewRawCommand extends BushCommand {
retry: '{error} Choose a valid channel.',
optional: true
},
- default: (m) => m.channel
+ default: (m: Message) => m.channel
},
{
id: 'json',
match: 'flag',
flag: '--json'
+ },
+ {
+ id: 'js',
+ match: 'flag',
+ flag: '--js'
}
]
});
@@ -44,7 +49,7 @@ export default class ViewRawCommand extends BushCommand {
public override async exec(
message: BushMessage | BushSlashMessage,
- args: { message: Message | BigInt; channel: TextChannel | NewsChannel | DMChannel; json?: boolean }
+ args: { message: Message | BigInt; channel: TextChannel | NewsChannel | DMChannel; json?: boolean; js: boolean }
): Promise<unknown> {
let newMessage: Message | 0;
if (!(typeof args.message === 'object')) {
@@ -59,14 +64,24 @@ export default class ViewRawCommand extends BushCommand {
} else {
newMessage = args.message as Message;
}
- const content = args.json ? inspect(newMessage.toJSON()) || '[No Content]' : newMessage.content || '[No Content]';
- const messageEmbed = new MessageEmbed()
- .setFooter(newMessage.author.tag, newMessage.author.avatarURL({ dynamic: true }))
- .setTimestamp(newMessage.createdTimestamp)
- .setColor(newMessage.member?.roles?.color?.color || util.colors.default)
- .setTitle('Raw Message Information')
- .setDescription(await util.codeblock(content, 2048, 'js'));
+
+ const messageEmbed = await ViewRawCommand.getRawData(newMessage as BushMessage, { json: args.json, js: args.js });
return await message.util.reply({ embeds: [messageEmbed] });
}
+
+ public static async getRawData(message: BushMessage, options: { json?: boolean; js: boolean }): Promise<unknown> {
+ const content =
+ options.json || options.js
+ ? options.json
+ ? inspect(JSON.stringify(message.toJSON()))
+ : inspect(message.toJSON()) || '[No Content]'
+ : message.content || '[No Content]';
+ return new MessageEmbed()
+ .setFooter(message.author.tag, message.author.avatarURL({ dynamic: true }))
+ .setTimestamp(message.createdTimestamp)
+ .setColor(message.member?.roles?.color?.color || util.colors.default)
+ .setTitle('Raw Message Information')
+ .setDescription(await util.codeblock(content, 2048, 'js'));
+ }
}
diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts
index 2a01f6a..4f9f09b 100644
--- a/src/lib/extensions/discord-akairo/BushClientUtil.ts
+++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts
@@ -1371,4 +1371,31 @@ export class BushClientUtil extends ClientUtil {
public async sleep(s: number): Promise<unknown> {
return new Promise((resolve) => setTimeout(resolve, s * 1000));
}
+
+ // 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');
+ // }
}
diff --git a/src/listeners/client/interactionCreate.ts b/src/listeners/client/interactionCreate.ts
index 17249a9..e719517 100644
--- a/src/listeners/client/interactionCreate.ts
+++ b/src/listeners/client/interactionCreate.ts
@@ -1,5 +1,6 @@
-import { BushListener } from '@lib';
+import { BushListener, BushMessage } from '@lib';
import { ClientEvents } from 'discord.js';
+import ViewRawCommand from '../../commands/utilities/viewraw';
export default class InteractionCreateListener extends BushListener {
public constructor() {
@@ -32,6 +33,14 @@ export default class InteractionCreateListener extends BushListener {
}.`,
ephemeral: true
});
+ } else if (interaction.isContextMenu()) {
+ if (interaction.id === 'View Raw') {
+ const embed = await ViewRawCommand.getRawData(interaction.options.getMessage('message') as BushMessage, {
+ json: false,
+ js: false
+ });
+ return await interaction.reply({ embeds: [embed], ephemeral: true });
+ }
}
}
}
diff --git a/yarn.lock b/yarn.lock
index 2188c58..86b78c5 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1369,7 +1369,7 @@ discord-akairo@NotEnoughUpdates/discord-akairo:
discord.js@NotEnoughUpdates/discord.js:
version: 13.2.0-dev
- resolution: "discord.js@https://github.com/NotEnoughUpdates/discord.js.git#commit=ddd4772081be428d84959efc62f6cf915d2ecdbc"
+ resolution: "discord.js@https://github.com/NotEnoughUpdates/discord.js.git#commit=564f2e06b5c072239d8cc2a66374169ad314b392"
dependencies:
"@discordjs/builders": ^0.5.0
"@discordjs/collection": ^0.2.1
@@ -1379,7 +1379,7 @@ discord.js@NotEnoughUpdates/discord.js:
discord-api-types: ^0.22.0
node-fetch: ^2.6.1
ws: ^7.5.1
- checksum: 345b0649f1a02ef556eeae38987be46eebdcbba2c60e5b7b4fec415e6ea986125b4ac03a5ec4426a0ad93df1105de3432c3497b15f4edaf8d31f850e5bbf84e2
+ checksum: d78a07e59c59d3ae8d052a3c4381e3d2743ac7a32c4dd4010c0e45e80be1ff7acf4258fd77aa8a5601ccb44a59c9c5dd62a629e5afb16ee75a423d7b3e5b26d3
languageName: node
linkType: hard