From 598b121b9e3134686d4663a7cd23e19c95744d24 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Thu, 21 Oct 2021 00:29:29 -0400 Subject: b --- src/commands/utilities/_viewRaw.ts | 108 --------------------------- src/commands/utilities/viewRaw.ts | 108 +++++++++++++++++++++++++++ src/context-menu-commands/message/viewRaw.ts | 2 +- 3 files changed, 109 insertions(+), 109 deletions(-) delete mode 100644 src/commands/utilities/_viewRaw.ts create mode 100644 src/commands/utilities/viewRaw.ts diff --git a/src/commands/utilities/_viewRaw.ts b/src/commands/utilities/_viewRaw.ts deleted file mode 100644 index b7017c6..0000000 --- a/src/commands/utilities/_viewRaw.ts +++ /dev/null @@ -1,108 +0,0 @@ -import { DMChannel, MessageEmbed, NewsChannel, Snowflake, TextChannel } from 'discord.js'; -import { BushCommand, BushMessage, BushSlashMessage } from '../../lib'; - -export default class ViewRawCommand extends BushCommand { - public constructor() { - super('view-raw', { - aliases: ['view-raw', 'vr'], - category: 'utilities', - description: { - usage: 'viewraw ', - examples: ['viewraw 322862723090219008'], - content: 'Shows raw information about a message.' - }, - args: [ - { - id: 'message', - type: 'snowflake', - prompt: { - start: 'What message would you like to view?', - retry: '{error} Choose a valid message.', - optional: false - } - }, - { - id: 'channel', - type: 'channel', - prompt: { - start: 'What channel is the message in?', - retry: '{error} Choose a valid channel.', - optional: true - } - }, - { - id: 'json', - match: 'flag', - flag: '--json' - }, - { - id: 'js', - match: 'flag', - flag: '--js' - } - ], - slash: true, - slashOptions: [ - { - name: 'message', - description: 'What message would you like to view?', - type: 'STRING', - required: true - }, - { - name: 'channel', - description: 'What channel is the message in?', - type: 'CHANNEL', - required: false - }, - { - name: 'json', - description: 'Would you like to view the raw JSON message data?', - type: 'BOOLEAN', - required: false - }, - { - name: 'js', - description: 'Would you like to view the raw message data?', - type: 'BOOLEAN', - required: false - } - ], - channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), - userPermissions: [] - }); - } - - public override async exec( - message: BushMessage | BushSlashMessage, - args: { message: Snowflake; channel: TextChannel | NewsChannel | DMChannel; json?: boolean; js: boolean } - ): Promise { - 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 }); - - return await message.util.reply({ embeds: [messageEmbed] }); - } - - public static async getRawData(message: BushMessage, options: { json?: boolean; js: boolean }): Promise { - const content = - options.json || options.js - ? options.json - ? 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) - .setColor(message.member?.roles?.color?.color ?? util.colors.default) - .setTitle('Raw Message Information') - .setDescription(await util.codeblock(content, 2048, lang)); - } -} diff --git a/src/commands/utilities/viewRaw.ts b/src/commands/utilities/viewRaw.ts new file mode 100644 index 0000000..b7017c6 --- /dev/null +++ b/src/commands/utilities/viewRaw.ts @@ -0,0 +1,108 @@ +import { DMChannel, MessageEmbed, NewsChannel, Snowflake, TextChannel } from 'discord.js'; +import { BushCommand, BushMessage, BushSlashMessage } from '../../lib'; + +export default class ViewRawCommand extends BushCommand { + public constructor() { + super('view-raw', { + aliases: ['view-raw', 'vr'], + category: 'utilities', + description: { + usage: 'viewraw ', + examples: ['viewraw 322862723090219008'], + content: 'Shows raw information about a message.' + }, + args: [ + { + id: 'message', + type: 'snowflake', + prompt: { + start: 'What message would you like to view?', + retry: '{error} Choose a valid message.', + optional: false + } + }, + { + id: 'channel', + type: 'channel', + prompt: { + start: 'What channel is the message in?', + retry: '{error} Choose a valid channel.', + optional: true + } + }, + { + id: 'json', + match: 'flag', + flag: '--json' + }, + { + id: 'js', + match: 'flag', + flag: '--js' + } + ], + slash: true, + slashOptions: [ + { + name: 'message', + description: 'What message would you like to view?', + type: 'STRING', + required: true + }, + { + name: 'channel', + description: 'What channel is the message in?', + type: 'CHANNEL', + required: false + }, + { + name: 'json', + description: 'Would you like to view the raw JSON message data?', + type: 'BOOLEAN', + required: false + }, + { + name: 'js', + description: 'Would you like to view the raw message data?', + type: 'BOOLEAN', + required: false + } + ], + channel: 'guild', + clientPermissions: (m) => util.clientSendAndPermCheck(m, ['EMBED_LINKS'], true), + userPermissions: [] + }); + } + + public override async exec( + message: BushMessage | BushSlashMessage, + args: { message: Snowflake; channel: TextChannel | NewsChannel | DMChannel; json?: boolean; js: boolean } + ): Promise { + 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 }); + + return await message.util.reply({ embeds: [messageEmbed] }); + } + + public static async getRawData(message: BushMessage, options: { json?: boolean; js: boolean }): Promise { + const content = + options.json || options.js + ? options.json + ? 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) + .setColor(message.member?.roles?.color?.color ?? util.colors.default) + .setTitle('Raw Message Information') + .setDescription(await util.codeblock(content, 2048, lang)); + } +} diff --git a/src/context-menu-commands/message/viewRaw.ts b/src/context-menu-commands/message/viewRaw.ts index ebf8be7..77fd0b9 100644 --- a/src/context-menu-commands/message/viewRaw.ts +++ b/src/context-menu-commands/message/viewRaw.ts @@ -1,6 +1,6 @@ import { ContextMenuCommand } from 'discord-akairo'; import { ContextMenuInteraction } from 'discord.js'; -import ViewRawCommand from '../../commands/utilities/_viewRaw'; +import ViewRawCommand from '../../commands/utilities/viewRaw'; import { BushMessage } from '../../lib'; export default class ViewRawContextMenuCommand extends ContextMenuCommand { -- cgit