meme: refactor

impossible: fix bug where it was eating all messages
This commit is contained in:
Chris Sexton 2021-02-07 15:05:30 -05:00 committed by Chris Sexton
parent 0891713523
commit 7dfa5bf891
2 changed files with 9 additions and 15 deletions

View File

@ -116,8 +116,9 @@ func (p *Impossible) register() {
p.b.Send(r.Conn, bot.Message, r.Msg.Channel, fmt.Sprintf("You guessed the last impossible wikipedia article: \"%s\"", p.title)) p.b.Send(r.Conn, bot.Message, r.Msg.Channel, fmt.Sprintf("You guessed the last impossible wikipedia article: \"%s\"", p.title))
for !p.refreshImpossible() { for !p.refreshImpossible() {
} }
return true
} }
return true return false
}}, }},
} }
p.b.RegisterTable(p, p.handlers) p.b.RegisterTable(p, p.handlers)

View File

@ -66,27 +66,20 @@ func New(b bot.Bot) *MemePlugin {
horizon = mp.c.GetInt("meme.horizon", horizon) horizon = mp.c.GetInt("meme.horizon", horizon)
b.Register(mp, bot.Message, mp.message) b.RegisterRegexCmd(mp, bot.Message, cmdMatch, mp.message)
b.Register(mp, bot.Help, mp.help) b.Register(mp, bot.Help, mp.help)
mp.registerWeb(b.DefaultConnector()) mp.registerWeb(b.DefaultConnector())
return mp return mp
} }
var cmdMatch = regexp.MustCompile(`(?i)meme (.+)`) var cmdMatch = regexp.MustCompile(`(?i)^meme (?P<content>.+)$`)
func (p *MemePlugin) message(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool { func (p *MemePlugin) message(r bot.Request) bool {
if message.Command && cmdMatch.MatchString(message.Body) { minusMeme := r.Values["content"]
subs := cmdMatch.FindStringSubmatch(message.Body) log.Debug().Msgf("Calling sendMeme with text: %s", minusMeme)
if len(subs) != 2 { p.sendMeme(r.Conn, r.Msg.Channel, r.Msg.ChannelName, r.Msg.ID, r.Msg.User, minusMeme)
p.bot.Send(c, bot.Message, message.Channel, "Invalid meme request.") return true
return true
}
minusMeme := subs[1]
p.sendMeme(c, message.Channel, message.ChannelName, message.ID, message.User, minusMeme)
return true
}
return false
} }
func (p *MemePlugin) help(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool { func (p *MemePlugin) help(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool {