Compare commits

...

9 Commits

Author SHA1 Message Date
Chris Sexton 15645526d5 Merge branch 'master' into covfefe
* master:
  meme: text
  meme: use urls
2020-04-28 15:17:45 -04:00
Chris Sexton 66460159cd meme: fix shortcuts 2020-04-28 15:16:45 -04:00
Chris Sexton 15dcd5ba7c meme: text 2020-04-28 15:04:59 -04:00
Chris Sexton ca629b6521 meme: use urls 2020-04-28 15:04:59 -04:00
Chris Sexton d2089279be Merge branch 'covfefe' of github.com:velour/catbase into covfefe
* 'covfefe' of github.com:velour/catbase:
  meme: add user name
2020-04-28 15:02:20 -04:00
Chris Sexton 9704406fe5 meme: text 2020-04-28 15:00:44 -04:00
Chris Sexton 27a80fdfcc
Merge branch 'master' into covfefe 2020-04-28 14:59:40 -04:00
Chris Sexton 5a1e572645 meme: use urls 2020-04-28 14:58:23 -04:00
Chris Sexton 2e746f7b80 meme: add user name 2020-04-28 11:48:39 -04:00
1 changed files with 16 additions and 8 deletions

View File

@ -74,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)
})
@ -87,16 +87,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 +121,16 @@ func (p *MemePlugin) genMeme(meme, text string) string {
if !ok {
imgName = meme
}
img := DownloadTemplate(imgName)
u, err := url.Parse(imgName)
if err != nil || u.Scheme == "" {
log.Debug().Err(err).Str("imgName", imgName).Msgf("url not detected")
u, _ = url.Parse("https://imgflip.com/s/meme/" + imgName)
}
log.Debug().Msgf("Attempting to download url: %s", u.String())
img := DownloadTemplate(u)
r := img.Bounds()
w := r.Dx()
h := r.Dy()
@ -130,7 +138,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")
}