From 7dfa5bf8913225062ac62ff15f33c2527bdededb Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sun, 7 Feb 2021 15:05:30 -0500 Subject: [PATCH] meme: refactor impossible: fix bug where it was eating all messages --- plugins/impossible/impossible.go | 3 ++- plugins/meme/meme.go | 21 +++++++-------------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/plugins/impossible/impossible.go b/plugins/impossible/impossible.go index 64b2cce..6060a07 100644 --- a/plugins/impossible/impossible.go +++ b/plugins/impossible/impossible.go @@ -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)) for !p.refreshImpossible() { } + return true } - return true + return false }}, } p.b.RegisterTable(p, p.handlers) diff --git a/plugins/meme/meme.go b/plugins/meme/meme.go index 6b39bd9..ab1ca9d 100644 --- a/plugins/meme/meme.go +++ b/plugins/meme/meme.go @@ -66,27 +66,20 @@ func New(b bot.Bot) *MemePlugin { 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) mp.registerWeb(b.DefaultConnector()) return mp } -var cmdMatch = regexp.MustCompile(`(?i)meme (.+)`) +var cmdMatch = regexp.MustCompile(`(?i)^meme (?P.+)$`) -func (p *MemePlugin) message(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool { - if message.Command && cmdMatch.MatchString(message.Body) { - subs := cmdMatch.FindStringSubmatch(message.Body) - if len(subs) != 2 { - p.bot.Send(c, bot.Message, message.Channel, "Invalid meme request.") - return true - } - minusMeme := subs[1] - p.sendMeme(c, message.Channel, message.ChannelName, message.ID, message.User, minusMeme) - return true - } - return false +func (p *MemePlugin) message(r bot.Request) bool { + minusMeme := r.Values["content"] + log.Debug().Msgf("Calling sendMeme with text: %s", minusMeme) + p.sendMeme(r.Conn, r.Msg.Channel, r.Msg.ChannelName, r.Msg.ID, r.Msg.User, minusMeme) + return true } func (p *MemePlugin) help(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool {