mirror of https://github.com/velour/catbase.git
meme: configify the default meme config
This commit is contained in:
parent
69cee328e7
commit
104f48b1c3
|
@ -170,13 +170,13 @@ func (p *MemePlugin) sendMeme(c bot.Connector, channel, channelName, msgID strin
|
||||||
allConfigs := p.c.GetMap("meme.memeconfigs", map[string]string{})
|
allConfigs := p.c.GetMap("meme.memeconfigs", map[string]string{})
|
||||||
configtxt, ok := allConfigs[format]
|
configtxt, ok := allConfigs[format]
|
||||||
if !ok {
|
if !ok {
|
||||||
config = defaultFormatConfig()
|
config = p.defaultFormatConfig()
|
||||||
log.Debug().Msgf("Did not find %s in %+v", format, allConfigs)
|
log.Debug().Msgf("Did not find %s in %+v", format, allConfigs)
|
||||||
} else {
|
} else {
|
||||||
err = json.Unmarshal([]byte(configtxt), &config)
|
err = json.Unmarshal([]byte(configtxt), &config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msgf("Could not parse config for %s:\n%s", format, configtxt)
|
log.Error().Err(err).Msgf("Could not parse config for %s:\n%s", format, configtxt)
|
||||||
config = defaultFormatConfig()
|
config = p.defaultFormatConfig()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -343,15 +343,25 @@ func (p *MemePlugin) findFontSize(config []memeText, fontLocation string, w, h i
|
||||||
return fontSize
|
return fontSize
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultFormatConfig() []memeText {
|
func (p *MemePlugin) defaultFormatConfig() []memeText {
|
||||||
|
allConfigs := p.c.GetMap("meme.memeconfigs", map[string]string{})
|
||||||
|
if configtxt, ok := allConfigs["default"]; ok {
|
||||||
|
var config []memeText
|
||||||
|
err := json.Unmarshal([]byte(configtxt), &config)
|
||||||
|
if err != nil {
|
||||||
|
goto ret
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
}
|
||||||
|
ret:
|
||||||
return []memeText{
|
return []memeText{
|
||||||
{XPerc: 0.5, YPerc: 0.05, Caps: true},
|
{XPerc: 0.5, YPerc: 0.1, Caps: true},
|
||||||
{XPerc: 0.5, YPerc: 0.95, Caps: true},
|
{XPerc: 0.5, YPerc: 0.9, Caps: true},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultFormatConfigJSON() string {
|
func (p *MemePlugin) defaultFormatConfigJSON() string {
|
||||||
c, _ := json.Marshal(defaultFormatConfig())
|
c, _ := json.Marshal(p.defaultFormatConfig())
|
||||||
return string(c)
|
return string(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ func (p *MemePlugin) all(w http.ResponseWriter, r *http.Request) {
|
||||||
for n, u := range memes {
|
for n, u := range memes {
|
||||||
config, ok := configs[n]
|
config, ok := configs[n]
|
||||||
if !ok {
|
if !ok {
|
||||||
b, _ := json.Marshal(defaultFormatConfig())
|
b, _ := json.Marshal(p.defaultFormatConfig())
|
||||||
config = string(b)
|
config = string(b)
|
||||||
}
|
}
|
||||||
realURL, err := url.Parse(u)
|
realURL, err := url.Parse(u)
|
||||||
|
@ -126,7 +126,7 @@ func (p *MemePlugin) addMeme(w http.ResponseWriter, r *http.Request) {
|
||||||
checkError(err)
|
checkError(err)
|
||||||
|
|
||||||
if values.Config == "" {
|
if values.Config == "" {
|
||||||
values.Config = defaultFormatConfigJSON()
|
values.Config = p.defaultFormatConfigJSON()
|
||||||
}
|
}
|
||||||
configs := p.c.GetMap("meme.memeconfigs", map[string]string{})
|
configs := p.c.GetMap("meme.memeconfigs", map[string]string{})
|
||||||
configs[values.Name] = values.Config
|
configs[values.Name] = values.Config
|
||||||
|
|
Loading…
Reference in New Issue