Compare commits

..

3 Commits

Author SHA1 Message Date
Chris Sexton 2395f7b33d meme: empty text 2020-05-04 17:31:28 -04:00
Chris Sexton b0aa04ce78 meme: add placeholder text in web form 2020-05-04 13:46:15 -04:00
Chris Sexton d7b0bed0db untappd: defer checkins without media 2020-05-04 13:46:15 -04:00
3 changed files with 31 additions and 6 deletions

View File

@ -15,6 +15,7 @@ import (
"github.com/jmoiron/sqlx" "github.com/jmoiron/sqlx"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
"github.com/velour/catbase/bot" "github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg" "github.com/velour/catbase/bot/msg"
"github.com/velour/catbase/plugins/counter" "github.com/velour/catbase/plugins/counter"
@ -27,6 +28,8 @@ const itemName = ":beer:"
type BeersPlugin struct { type BeersPlugin struct {
Bot bot.Bot Bot bot.Bot
db *sqlx.DB db *sqlx.DB
untapdCache map[int]bool
} }
type untappdUser struct { type untappdUser struct {
@ -51,6 +54,8 @@ func New(b bot.Bot) *BeersPlugin {
p := &BeersPlugin{ p := &BeersPlugin{
Bot: b, Bot: b,
db: b.DB(), db: b.DB(),
untapdCache: make(map[int]bool),
} }
for _, channel := range b.Config().GetArray("Untappd.Channels", []string{}) { for _, channel := range b.Config().GetArray("Untappd.Channels", []string{}) {
go p.untappdLoop(b.DefaultConnector(), channel) go p.untappdLoop(b.DefaultConnector(), channel)
@ -440,6 +445,14 @@ func (p *BeersPlugin) checkUntappd(c bot.Connector, channel string) {
URL: checkin.Media.Items[0].Photo.Photo_img_lg, URL: checkin.Media.Items[0].Photo.Photo_img_lg,
AltTxt: "Here's a photo", AltTxt: "Here's a photo",
}) })
} else if !p.untapdCache[checkin.Checkin_id] {
// Mark checkin as "seen" but not complete, continue to next checkin
log.Debug().Msgf("Deferring checkin: %#v", checkin)
p.untapdCache[checkin.Checkin_id] = true
continue
} else {
// We've seen this checkin, so unmark and accept that there's no media
delete(p.untapdCache, checkin.Checkin_id)
} }
user.lastCheckin = checkin.Checkin_id user.lastCheckin = checkin.Checkin_id

View File

@ -74,10 +74,9 @@ func (p *MemePlugin) help(c bot.Connector, kind bot.Kind, message msg.Message, a
formats := p.c.GetMap("meme.memes", defaultFormats) formats := p.c.GetMap("meme.memes", defaultFormats)
msg := "Use `/meme [format] [text]` to create a meme.\nI know the following formats:" msg := "Use `/meme [format] [text]` to create a meme.\nI know the following formats:"
msg += "\n`[format]` can be a URL" msg += "\n`[format]` can be a URL"
for k := range formats { msg += fmt.Sprintf("\nor a format from the list of %d pre-made memes listed on the website", len(formats))
msg += "\n" + k msg += fmt.Sprintf("\nHead over to %s/meme to view and add new meme formats", webRoot)
} msg += "\nYou can use `_` as a placeholder for empty text and a newline to separate top vs bottom."
msg += fmt.Sprintf("\nHead over to %s/meme to add new meme formats", webRoot)
p.bot.Send(c, bot.Message, message.Channel, msg) p.bot.Send(c, bot.Message, message.Channel, msg)
return true return true
} }
@ -202,6 +201,12 @@ func (p *MemePlugin) slashMeme(c bot.Connector) http.HandlerFunc {
top, bottom = parts[0], parts[1] top, bottom = parts[0], parts[1]
} }
if top == "_" {
message = bottom
} else if bottom == "_" {
message = top
}
id, err := p.genMeme(format, top, bottom) id, err := p.genMeme(format, top, bottom)
if err != nil { if err != nil {
msg := fmt.Sprintf("Hey %s, I couldn't download that image you asked for.", from) msg := fmt.Sprintf("Hey %s, I couldn't download that image you asked for.", from)
@ -326,6 +331,13 @@ func (p *MemePlugin) genMeme(meme, top, bottom string) (string, error) {
} }
} }
if top == "_" {
top = ""
}
if bottom == "_" {
bottom = ""
}
// Apply black stroke // Apply black stroke
m.SetHexColor("#000") m.SetHexColor("#000")
strokeSize := 6 strokeSize := 6

View File

@ -39,10 +39,10 @@ var memeIndex = `
<b-container> <b-container>
<b-row> <b-row>
<b-col cols="5"> <b-col cols="5">
<b-input v-model="name"></b-input> <b-input placeholder="Name..." v-model="name"></b-input>
</b-col> </b-col>
<b-col cols="5"> <b-col cols="5">
<b-input v-model="url"></b-input> <b-input placeholder="URL..." v-model="url"></b-input>
</b-col> </b-col>
<b-col cols="2"> <b-col cols="2">
<b-button type="submit">Add Meme</b-button> <b-button type="submit">Add Meme</b-button>