From ceb6986749d4bf70595752e1e259ac24ecd1f742 Mon Sep 17 00:00:00 2001 From: mavolin <48887425+mavolin@users.noreply.github.com> Date: Fri, 15 May 2020 21:28:35 +0200 Subject: [PATCH] Discord: add ImageType --- discord/url.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/discord/url.go b/discord/url.go index 50bab02..52f0d1a 100644 --- a/discord/url.go +++ b/discord/url.go @@ -1,4 +1,34 @@ package discord +import "strings" + +type ImageType string + +const ( + // AutoImage chooses automatically between a PNG and GIF. + AutoImage ImageType = "auto" + + // JPEGImage is a JPEG image type. + JPEGImage ImageType = ".jpeg" + // PNGImage is the PNG image type. + PNGImage ImageType = ".png" + // WebPImage is the WebP image type. + WebPImage ImageType = ".webp" + // GIFImage is the GIF image type. + GIFImage ImageType = ".gif" +) + +func (t ImageType) format(name string) string { + if t == AutoImage { + if strings.HasPrefix(name, "a_") { + return name + ".gif" + } + + return name + ".png" + } + + return name + string(t) +} + type URL = string type Hash = string