diff options
Diffstat (limited to 'src/commands/info')
-rw-r--r-- | src/commands/info/color.ts | 47 | ||||
-rw-r--r-- | src/commands/info/help.ts | 42 | ||||
-rw-r--r-- | src/commands/info/userInfo.ts | 2 |
3 files changed, 58 insertions, 33 deletions
diff --git a/src/commands/info/color.ts b/src/commands/info/color.ts index 4db20e7..45c2545 100644 --- a/src/commands/info/color.ts +++ b/src/commands/info/color.ts @@ -1,6 +1,15 @@ -import { BushCommand, BushMessage, BushSlashMessage } from '@lib'; -import { Constants } from 'discord-akairo'; -import { ColorResolvable, MessageEmbed } from 'discord.js'; +import { BushCommand, BushGuildMember, BushMessage, BushRole, BushSlashMessage } from '@lib'; +import { Argument } from 'discord-akairo'; +import { ColorResolvable, MessageEmbed, Role } from 'discord.js'; +import { Constructor } from 'tinycolor2'; + +// eslint-disable-next-line @typescript-eslint/no-var-requires +const tinycolor: Constructor = require('tinycolor2'); // this is the only way I got it to work consistently +const isValidTinyColor = (_message: BushMessage, phase: string) => { + // if the phase is a number it converts it to hex incase it could be representing a color in decimal + const newPhase = Number.isNaN(phase) ? phase : `#${Number(phase).toString(16)}`; + return tinycolor(newPhase).isValid() ? newPhase : null; +}; export default class ColorCommand extends BushCommand { public constructor() { @@ -8,18 +17,17 @@ export default class ColorCommand extends BushCommand { aliases: ['color'], category: 'info', description: { - content: 'See what color a hex code is.', - usage: 'color <color>', + content: 'Find the color of a hex code, user, or role.', + usage: 'color <color|role|user>', examples: ['color #0000FF'] }, args: [ { id: 'color', - type: /^#?(?<code>[0-9A-F]{6})$/i, - match: Constants.ArgumentMatches.PHRASE, + type: Argument.union(isValidTinyColor, 'role', 'member'), prompt: { - start: 'What color value would you like to see the color of', - retry: '{error} Choose a valid hex color code.' + start: 'What color code, role, or user would you like to find the color of?', + retry: '{error} Choose a valid color, role, or member.' } } ], @@ -28,14 +36,27 @@ export default class ColorCommand extends BushCommand { }); } + public removePrefixAndParenthesis(color: string): string{ + return color.substr(4, color.length-5) + } + public async exec( message: BushMessage | BushSlashMessage, - { color: { match } }: { color: { match: RegExpMatchArray; matches: RegExpMatchArray[] } } + args: { color: string | BushRole | BushGuildMember } ): Promise<unknown> { + const color = + typeof args.color === 'string' + ? tinycolor(args.color) + : args.color instanceof Role + ? tinycolor(args.color.hexColor) + : tinycolor(args.color.displayHexColor); + const embed = new MessageEmbed() - .addField('Hex', match.groups.code, false) - .addField('RGB', this.client.util.hexToRgb(match.groups.code), false) - .setColor(match.groups.code as ColorResolvable); + .addField('» Hexadecimal', color.toHexString()) + .addField('» Decimal', `${parseInt(color.toHex(), 16)}`) + .addField('» HSL', this.removePrefixAndParenthesis(color.toHslString())) + .addField('» RGB', this.removePrefixAndParenthesis(color.toRgbString())) + .setColor(color.toHex() as ColorResolvable); return await message.util.reply({ embeds: [embed] }); } diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 0977c36..a0b03a0 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -47,16 +47,19 @@ export default class HelpCommand extends BushCommand { args: { command: BushCommand | string; showHidden?: boolean } ): Promise<unknown> { const prefix = this.client.config.dev ? 'dev ' : message.util.parsed.prefix; - let ButtonRow: MessageActionRow; - if (!this.client.config.dev) { - ButtonRow = new MessageActionRow().addComponents( - new MessageButton({ - style: 'LINK', - label: 'Invite Me', - url: `https://discord.com/api/oauth2/authorize?client_id=${this.client.user.id}&permissions=2147483647&scope=bot%20applications.commands` - }) - ); - } + const components = + !this.client.config.dev || !this.client.guilds.cache.some((guild) => guild.ownerId === message.author.id) + ? [ + new MessageActionRow().addComponents( + new MessageButton({ + style: 'LINK', + label: 'Invite Me', + url: `https://discord.com/api/oauth2/authorize?client_id=${this.client.user.id}&permissions=2147483647&scope=bot%20applications.commands` + }) + ) + ] + : undefined; + const isOwner = this.client.isOwner(message.author); const isSuperUser = this.client.isSuperUser(message.author); const command = args.command @@ -65,20 +68,21 @@ export default class HelpCommand extends BushCommand { : args.command : null; if (!isOwner) args.showHidden = false; - if (!command) { + if (!command || command.completelyHide) { const embed = new MessageEmbed().setColor(this.client.util.colors.default).setTimestamp(); if (message.guild) { - embed.setFooter(`For more information about a command use '${prefix}help <command>'`); + embed.setFooter(`For more information about a command use ${prefix}help <command>`); } for (const [, category] of this.handler.categories) { const categoryFilter = category.filter((command) => { + if (command.completelyHide) return false; if (command.hidden && !args.showHidden) return false; if (command.channel == 'guild' && !message.guild && !args.showHidden) return false; if (command.ownerOnly && !isOwner) return false; if (command.superUserOnly && !isSuperUser) { return false; } - return !(command.restrictedGuilds?.includes(message.guild.id) == false && !args.showHidden); + return !(command.restrictedGuilds?.includes(message.guild.id) === false && !args.showHidden); }); const categoryNice = category.id .replace(/(\b\w)/gi, (lc): string => lc.toUpperCase()) @@ -90,24 +94,24 @@ export default class HelpCommand extends BushCommand { embed.addField(`${categoryNice}`, `${categoryCommands.join(' ')}`); } } - return await message.util.reply({ embeds: [embed], components: ButtonRow ? [ButtonRow] : undefined }); + return await message.util.reply({ embeds: [embed], components }); } const embed = new MessageEmbed() .setColor(this.client.util.colors.default) - .setTitle(`\`${command.description?.usage ? command.description.usage : 'This command does not have usages.'}\``) + .setTitle(`\`${command.description?.usage || `${this.client.util.emojis.error} This command does not have usages.`}\``) .addField( 'Description', - `${command.description?.content ? command.description.content : '*This command does not have a description.*'} ${ - command.ownerOnly ? '\n__Dev Only__' : '' + `${command.description?.content || `${this.client.util.emojis.error} This command does not have a description.`} ${ + command.ownerOnly ? '\n__Developer Only__' : '' } ${command.superUserOnly ? '\n__Super User Only__' : ''}` ); if (command.aliases?.length > 1) embed.addField('Aliases', `\`${command.aliases.join('` `')}\``, true); - if (command.description?.examples && command.description.examples.length) { + if (command.description?.examples?.length) { embed.addField('Examples', `\`${command.description.examples.join('`\n`')}\``, true); } - return await message.util.reply({ embeds: [embed], components: ButtonRow ? [ButtonRow] : undefined }); + return await message.util.reply({ embeds: [embed], components }); } } diff --git a/src/commands/info/userInfo.ts b/src/commands/info/userInfo.ts index 50756a6..5e70323 100644 --- a/src/commands/info/userInfo.ts +++ b/src/commands/info/userInfo.ts @@ -78,7 +78,7 @@ export default class UserInfoCommand extends BushCommand { if (user.premiumSinceTimestamp) emojis.push(this.client.consts.mappings.otherEmojis.BOOSTER); const createdAt = user.user.createdAt.toLocaleString(), - createdAtDelta = moment(user.user.createdAt).diff(moment()).toLocaleString(), + createdAtDelta = moment(moment(user.user.createdAt).diff(moment())).toLocaleString(), joinedAt = user.joinedAt?.toLocaleString(), joinedAtDelta = moment(user.joinedAt)?.diff(moment()).toLocaleString(), premiumSince = user.premiumSince?.toLocaleString(), |