mirror of https://github.com/velour/catbase.git
Compare commits
3 Commits
0c94d71960
...
91d21c1076
Author | SHA1 | Date |
---|---|---|
Chris Sexton | 91d21c1076 | |
Chris Sexton | 690fd01fd2 | |
Chris Sexton | e2c55fab00 |
|
@ -204,6 +204,7 @@ func (p *Cowboy) mkOverlayCB(overlay string) func(s *discordgo.Session, i *disco
|
||||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
Data: &discordgo.InteractionResponseData{
|
Data: &discordgo.InteractionResponseData{
|
||||||
Content: msg,
|
Content: msg,
|
||||||
|
Flags: discordgo.MessageFlagsEphemeral,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -313,15 +313,15 @@ var defaultFormats = map[string]string{
|
||||||
"raptor": "https://imgflip.com/s/meme/Philosoraptor.jpg",
|
"raptor": "https://imgflip.com/s/meme/Philosoraptor.jpg",
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindFontSizeConfigs(configs []memeText, fontLocation string, w, h int, sizes []float64) float64 {
|
func FindFontSizeConfigs(c *config.Config, configs []memeText, fontLocation string, w, h int, sizes []float64) float64 {
|
||||||
texts := []string{}
|
texts := []string{}
|
||||||
for _, c := range configs {
|
for _, c := range configs {
|
||||||
texts = append(texts, c.Text)
|
texts = append(texts, c.Text)
|
||||||
}
|
}
|
||||||
return FindFontSize(texts, fontLocation, w, h, sizes)
|
return FindFontSize(c, texts, fontLocation, w, h, sizes)
|
||||||
}
|
}
|
||||||
|
|
||||||
func FindFontSize(config []string, fontLocation string, w, h int, sizes []float64) float64 {
|
func FindFontSize(c *config.Config, config []string, fontLocation string, w, h int, sizes []float64) float64 {
|
||||||
fontSize := 12.0
|
fontSize := 12.0
|
||||||
|
|
||||||
m := gg.NewContext(w, h)
|
m := gg.NewContext(w, h)
|
||||||
|
@ -329,7 +329,7 @@ func FindFontSize(config []string, fontLocation string, w, h int, sizes []float6
|
||||||
longestStr, longestW := "", 0.0
|
longestStr, longestW := "", 0.0
|
||||||
|
|
||||||
for _, s := range config {
|
for _, s := range config {
|
||||||
err := m.LoadFontFace(fontLocation, 12) // problem
|
err := m.LoadFontFace(getFont(c, fontLocation), 12)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("could not load font")
|
log.Error().Err(err).Msg("could not load font")
|
||||||
return fontSize
|
return fontSize
|
||||||
|
@ -343,7 +343,7 @@ func FindFontSize(config []string, fontLocation string, w, h int, sizes []float6
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, sz := range sizes {
|
for _, sz := range sizes {
|
||||||
err := m.LoadFontFace(fontLocation, sz) // problem
|
err := m.LoadFontFace(getFont(c, fontLocation), sz) // problem
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("could not load font")
|
log.Error().Err(err).Msg("could not load font")
|
||||||
return fontSize
|
return fontSize
|
||||||
|
@ -464,7 +464,7 @@ func (p *MemePlugin) genMeme(spec specification) ([]byte, error) {
|
||||||
// Apply black stroke
|
// Apply black stroke
|
||||||
m.SetHexColor("#000")
|
m.SetHexColor("#000")
|
||||||
strokeSize := 6
|
strokeSize := 6
|
||||||
fontSize := FindFontSizeConfigs(spec.Configs, defaultFont, w, h, fontSizes)
|
fontSize := FindFontSizeConfigs(p.c, spec.Configs, defaultFont, w, h, fontSizes)
|
||||||
for dy := -strokeSize; dy <= strokeSize; dy++ {
|
for dy := -strokeSize; dy <= strokeSize; dy++ {
|
||||||
for dx := -strokeSize; dx <= strokeSize; dx++ {
|
for dx := -strokeSize; dx <= strokeSize; dx++ {
|
||||||
// give it rounded corners
|
// give it rounded corners
|
||||||
|
@ -476,7 +476,7 @@ func (p *MemePlugin) genMeme(spec specification) ([]byte, error) {
|
||||||
if fontLocation == "" {
|
if fontLocation == "" {
|
||||||
fontLocation = defaultFont
|
fontLocation = defaultFont
|
||||||
}
|
}
|
||||||
m.LoadFontFace(fontLocation, fontSize)
|
m.LoadFontFace(getFont(p.c, fontLocation), fontSize)
|
||||||
x := float64(w)*c.XPerc + float64(dx)
|
x := float64(w)*c.XPerc + float64(dx)
|
||||||
y := float64(h)*c.YPerc + float64(dy)
|
y := float64(h)*c.YPerc + float64(dy)
|
||||||
m.DrawStringAnchored(c.Text, x, y, 0.5, 0.5)
|
m.DrawStringAnchored(c.Text, x, y, 0.5, 0.5)
|
||||||
|
@ -491,7 +491,7 @@ func (p *MemePlugin) genMeme(spec specification) ([]byte, error) {
|
||||||
if fontLocation == "" {
|
if fontLocation == "" {
|
||||||
fontLocation = defaultFont
|
fontLocation = defaultFont
|
||||||
}
|
}
|
||||||
m.LoadFontFace(fontLocation, fontSize)
|
m.LoadFontFace(getFont(p.c, fontLocation), fontSize)
|
||||||
x := float64(w) * c.XPerc
|
x := float64(w) * c.XPerc
|
||||||
y := float64(h) * c.YPerc
|
y := float64(h) * c.YPerc
|
||||||
m.DrawStringAnchored(c.Text, x, y, 0.5, 0.5)
|
m.DrawStringAnchored(c.Text, x, y, 0.5, 0.5)
|
||||||
|
@ -506,6 +506,15 @@ func (p *MemePlugin) genMeme(spec specification) ([]byte, error) {
|
||||||
return p.images[jsonSpec].repr, nil
|
return p.images[jsonSpec].repr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getFont(c *config.Config, name string) string {
|
||||||
|
location := c.Get("meme.fontLocation", "")
|
||||||
|
fontShortcuts := c.GetMap("meme.fontShortcuts", map[string]string{"impact": "impact.ttf"})
|
||||||
|
if file, ok := fontShortcuts[name]; ok {
|
||||||
|
name = file
|
||||||
|
}
|
||||||
|
return path.Join(location, name)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *MemePlugin) applyStamp(img image.Image, bullyURL string) (image.Image, error) {
|
func (p *MemePlugin) applyStamp(img image.Image, bullyURL string) (image.Image, error) {
|
||||||
u, _ := url.Parse(bullyURL)
|
u, _ := url.Parse(bullyURL)
|
||||||
bullyImg, err := DownloadTemplate(u)
|
bullyImg, err := DownloadTemplate(u)
|
||||||
|
|
|
@ -112,8 +112,6 @@ func (p *NewsBid) bidCmd(r bot.Request) bool {
|
||||||
ch := r.Msg.Channel
|
ch := r.Msg.Channel
|
||||||
conn := r.Conn
|
conn := r.Conn
|
||||||
|
|
||||||
log.Debug().Interface("request", r).Msg("bid request")
|
|
||||||
|
|
||||||
parts := strings.Fields(body)
|
parts := strings.Fields(body)
|
||||||
if len(parts) != 3 {
|
if len(parts) != 3 {
|
||||||
p.bot.Send(conn, bot.Message, ch, "You must bid with an amount and a URL.")
|
p.bot.Send(conn, bot.Message, ch, "You must bid with an amount and a URL.")
|
||||||
|
@ -122,6 +120,13 @@ func (p *NewsBid) bidCmd(r bot.Request) bool {
|
||||||
|
|
||||||
amount, _ := strconv.Atoi(parts[1])
|
amount, _ := strconv.Atoi(parts[1])
|
||||||
url := parts[2]
|
url := parts[2]
|
||||||
|
log.Debug().Msgf("URL: %s", url)
|
||||||
|
if id, err := strconv.Atoi(url); err == nil {
|
||||||
|
url = fmt.Sprintf("https://news.ycombinator.com/item?id=%d", id)
|
||||||
|
log.Debug().Msgf("New URL: %s", url)
|
||||||
|
}
|
||||||
|
log.Debug().Msgf("URL: %s", url)
|
||||||
|
|
||||||
if bid, err := p.ws.Bid(r.Msg.User.Name, amount, parts[1], url); err != nil {
|
if bid, err := p.ws.Bid(r.Msg.User.Name, amount, parts[1], url); err != nil {
|
||||||
p.bot.Send(conn, bot.Message, ch, fmt.Sprintf("Error placing bid: %s", err))
|
p.bot.Send(conn, bot.Message, ch, fmt.Sprintf("Error placing bid: %s", err))
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -78,7 +78,7 @@ func (p *Tappd) overlay(img image.Image, texts []textSpec) ([]byte, error) {
|
||||||
txts = append(txts, t.text)
|
txts = append(txts, t.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
fontSize := meme.FindFontSize(txts, font, w, h, fontSizes)
|
fontSize := meme.FindFontSize(p.c, txts, font, w, h, fontSizes)
|
||||||
|
|
||||||
m := gg.NewContext(w, h)
|
m := gg.NewContext(w, h)
|
||||||
m.DrawImage(img, 0, 0)
|
m.DrawImage(img, 0, 0)
|
||||||
|
|
Loading…
Reference in New Issue