diff options
Diffstat (limited to 'src/commands/utilities/viewraw.ts')
-rw-r--r-- | src/commands/utilities/viewraw.ts | 51 |
1 files changed, 20 insertions, 31 deletions
diff --git a/src/commands/utilities/viewraw.ts b/src/commands/utilities/viewraw.ts index bc79b7a..bd185d4 100644 --- a/src/commands/utilities/viewraw.ts +++ b/src/commands/utilities/viewraw.ts @@ -1,5 +1,4 @@ -import { DMChannel, Message, MessageEmbed, NewsChannel, Snowflake, TextChannel } from 'discord.js'; -import { inspect } from 'util'; +import { DMChannel, MessageEmbed, NewsChannel, Snowflake, TextChannel } from 'discord.js'; import { BushCommand, BushMessage, BushSlashMessage } from '../../lib'; export default class ViewRawCommand extends BushCommand { @@ -8,15 +7,16 @@ export default class ViewRawCommand extends BushCommand { aliases: ['viewraw'], category: 'utilities', clientPermissions: ['EMBED_LINKS'], + channel: 'guild', description: { usage: 'viewraw <message id> <channel>', examples: ['viewraw 322862723090219008'], - content: 'Gives information about a specified user.' + content: 'Shows raw information about a message.' }, args: [ { id: 'message', - customType: util.arg.union('message', 'bigint'), + type: 'snowflake', prompt: { start: 'What message would you like to view?', retry: '{error} Choose a valid message.', @@ -30,8 +30,7 @@ export default class ViewRawCommand extends BushCommand { start: 'What channel is the message in?', retry: '{error} Choose a valid channel.', optional: true - }, - default: (m: Message) => m.channel + } }, { id: 'json', @@ -49,21 +48,14 @@ export default class ViewRawCommand extends BushCommand { public override async exec( message: BushMessage | BushSlashMessage, - args: { message: Message | BigInt; channel: TextChannel | NewsChannel | DMChannel; json?: boolean; js: boolean } + args: { message: Snowflake; channel: TextChannel | NewsChannel | DMChannel; json?: boolean; js: boolean } ): Promise<unknown> { - let newMessage: Message | 0; - if (!(typeof args.message === 'object')) { - newMessage = await args.channel.messages.fetch(`${args.message}` as Snowflake).catch(() => { - return 0; - }); - if (!newMessage) { - return await message.util.reply( - `${util.emojis.error} There was an error fetching that message, try supplying a channel.` - ); - } - } else { - newMessage = args.message as Message; - } + if (!args.channel) args.channel = (message.channel as TextChannel | NewsChannel | DMChannel)!; + const newMessage = await args.channel.messages.fetch(`${args.message}` as Snowflake).catch(() => null); + if (!newMessage) + return await message.util.reply( + `${util.emojis.error} There was an error fetching that message, make sure that is a valid id and if the message is not in this channel, please provide a channel.` + ); const messageEmbed = await ViewRawCommand.getRawData(newMessage as BushMessage, { json: args.json, js: args.js }); @@ -74,18 +66,15 @@ export default class ViewRawCommand extends BushCommand { const content = options.json || options.js ? options.json - ? inspect(JSON.stringify(message.toJSON())) - : inspect(message.toJSON()) || '[No Content]' + ? JSON.stringify(message.toJSON(), undefined, 2) + : util.inspect(message.toJSON()) || '[No Content]' : message.content || '[No Content]'; const lang = options.json ? 'json' : options.js ? 'js' : undefined; - return ( - new MessageEmbed() - .setFooter(message.author.tag, message.author.avatarURL({ dynamic: true }) ?? undefined) - .setTimestamp(message.createdTimestamp) - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - .setColor(message.member?.roles?.color?.color || util.colors.default) - .setTitle('Raw Message Information') - .setDescription(await util.codeblock(content, 2048, lang)) - ); + return new MessageEmbed() + .setFooter(message.author.tag, message.author.avatarURL({ dynamic: true }) ?? undefined) + .setTimestamp(message.createdTimestamp) + .setColor(message.member?.roles?.color?.color ?? util.colors.default) + .setTitle('Raw Message Information') + .setDescription(await util.codeblock(content, 2048, lang)); } } |