From ca629b6521abe58b2164b3383165804f80e3988c Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Tue, 28 Apr 2020 14:58:23 -0400 Subject: [PATCH 1/2] meme: use urls --- plugins/meme/meme.go | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/plugins/meme/meme.go b/plugins/meme/meme.go index f9cfe70..4ef72fc 100644 --- a/plugins/meme/meme.go +++ b/plugins/meme/meme.go @@ -2,7 +2,6 @@ package meme import ( "bytes" - "fmt" "image" "image/png" "net/http" @@ -87,16 +86,15 @@ func (p *MemePlugin) registerWeb(c bot.Connector) { }) } -func DownloadTemplate(file string) image.Image { - url := fmt.Sprintf("https://imgflip.com/s/meme/%s", file) - res, err := http.Get(url) +func DownloadTemplate(u *url.URL) image.Image { + res, err := http.Get(u.String()) if err != nil { - log.Error().Msgf("%s template from %s failed because of %v", file, url, err) + log.Error().Msgf("template from %s failed because of %v", u.String(), err) } defer res.Body.Close() image, _, err := image.Decode(res.Body) if err != nil { - log.Error().Msgf("Could not decode %s because of %v", file, err) + log.Error().Msgf("Could not decode %v because of %v", u, err) } return image } @@ -122,7 +120,13 @@ func (p *MemePlugin) genMeme(meme, text string) string { if !ok { imgName = meme } - img := DownloadTemplate(imgName) + + u, err := url.Parse(imgName) + if err != nil { + u, _ = url.Parse("https://imgflip.com/s/meme/" + imgName) + } + + img := DownloadTemplate(u) r := img.Bounds() w := r.Dx() h := r.Dy() @@ -130,7 +134,7 @@ func (p *MemePlugin) genMeme(meme, text string) string { m := gg.NewContext(w, h) m.DrawImage(img, 0, 0) fontLocation := p.c.Get("meme.font", "impact.ttf") - err := m.LoadFontFace(fontLocation, fontSize) // problem + err = m.LoadFontFace(fontLocation, fontSize) // problem if err != nil { log.Error().Err(err).Msg("could not load font") } From 15dcd5ba7c0e71c22fda2d4b8ef5865703b1b418 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Tue, 28 Apr 2020 15:00:44 -0400 Subject: [PATCH 2/2] meme: text --- plugins/meme/meme.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/meme/meme.go b/plugins/meme/meme.go index 4ef72fc..1daf49d 100644 --- a/plugins/meme/meme.go +++ b/plugins/meme/meme.go @@ -2,6 +2,7 @@ package meme import ( "bytes" + "fmt" "image" "image/png" "net/http" @@ -73,7 +74,7 @@ func (p *MemePlugin) registerWeb(c bot.Connector) { log.Debug().Msgf("image is at %s", u.String()) p.bot.Send(c, bot.Message, channel, "", bot.ImageAttachment{ URL: u.String(), - AltTxt: user, + AltTxt: fmt.Sprintf("%s: %s", user, parts[1]), }) w.Write(nil) })