Skip to main content

Preview Color

This command allows you to preview how colours look. Also includes some information about the colour, such as its hexadecimal/decimal equivalent.

Trigger

Type: Regex
Trigger: \A(-|<@!?204255221017214977>\s*)(preview|color)(\s+|\z)

Usage

  • -preview <hex> - Previews the color with the hex provided.
  • -preview <dec> -dec - Previews the color with the decimal value provided.
note

The reason we have -dec is to distinguish hex from decimal in ambiguous cases. For example, 111111 is both a valid hex and decimal color.

Aliases

Instead of preview, you can also use color.

Code

{{/*
Allows you to preview how colors look. Converts hex to dec and vice versa as well.
See <https://yagpdb-cc.github.io/utilities/color-preview> for more information.

Author: jo3-l <https://github.com/jo3-l>
*/}}

{{ $multipliers := cslice 1048576 65536 4096 256 16 1 }}
{{ $hex2dec := sdict "A" 10 "B" 11 "C" 12 "D" 13 "E" 14 "F" 15 }}
{{ $stripped := .StrippedMsg }}
{{ $force := or (reFind `-(d|dec)` $stripped) "" }}
{{ $regex := `(?:#?([a-fA-F\d]{1,6}))` }}
{{ if $force }}
{{ $regex = `(\d+)` }}
{{ end }}
{{ with reFindAllSubmatches $regex $stripped }}
{{ $hex := (printf "%06s" (index . 0 1)) | upper }}
{{ $dec := 0 }}
{{ with and $force (toInt (index . 0 1)) }}
{{ $hex = (printf "%06x" .) | upper }}
{{ $dec = . }}
{{ end }}
{{ if not $dec }}
{{ range $k, $v := split $hex "" }}
{{- $multiplier := index $multipliers $k }}
{{- $num := or ($hex2dec.Get $v) $v}}
{{- $dec = add $dec (mult $num $multiplier) -}}
{{ end }}
{{ end }}
{{ sendMessage nil (cembed
"title" "❯ Color Preview"
"color" $dec
"description" (printf "❯ **Decimal:** %d\n❯ **Hex:** #%s" $dec $hex)
"thumbnail" (sdict "url" (printf "https://dummyimage.com/400x400/%s/%s" $hex $hex))
) }}
{{ else }}
Correct usage is `-preview <hex>`.
{{ end }}

Author

This custom command was written by @jo3-l.