aboutsummaryrefslogtreecommitdiff
path: root/src/commands/utilities/viewraw.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-08-16 10:04:46 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-08-16 10:04:46 -0400
commit4501e9f3bdd016736844146020e6b2c15e2ab3d2 (patch)
tree6e8a7c3d2b11dac7dcfd6afe0c46e4f42e682da3 /src/commands/utilities/viewraw.ts
parent59087bf0d8fa504da997594fc62787695e689476 (diff)
downloadtanzanite-4501e9f3bdd016736844146020e6b2c15e2ab3d2.tar.gz
tanzanite-4501e9f3bdd016736844146020e6b2c15e2ab3d2.tar.bz2
tanzanite-4501e9f3bdd016736844146020e6b2c15e2ab3d2.zip
add viewraw context menu command
Diffstat (limited to 'src/commands/utilities/viewraw.ts')
-rw-r--r--src/commands/utilities/viewraw.ts33
1 files changed, 24 insertions, 9 deletions
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'));
+ }
}