From 699532d789bc69ebf459bdf5de0aa723edf1d837 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Fri, 1 May 2020 09:11:34 -0400 Subject: [PATCH] meme: fix a crash --- plugins/meme/meme.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/meme/meme.go b/plugins/meme/meme.go index 65c2579..debdbe0 100644 --- a/plugins/meme/meme.go +++ b/plugins/meme/meme.go @@ -83,13 +83,19 @@ func (p *MemePlugin) registerWeb(c bot.Connector) { channel := r.PostForm.Get("channel_id") channelName := r.PostForm.Get("channel_name") from := r.PostForm.Get("user_name") + text := r.PostForm.Get("text") log.Debug().Msgf("channel: %s", channel) - parts := strings.SplitN(r.PostForm.Get("text"), " ", 2) + parts := strings.SplitN(text, " ", 2) + if len(parts) != 2 { + log.Debug().Msgf("Bad meme request: %s, %s", from, text) + p.bot.Send(c, bot.Message, channel, fmt.Sprintf("%s tried to send me a bad meme request.", from)) + return + } isCmd, message := bot.IsCmd(p.c, parts[1]) format := parts[0] - log.Debug().Strs("parts", parts).Msgf("Meme:\n%+v", r.PostForm.Get("text")) + log.Debug().Strs("parts", parts).Msgf("Meme:\n%+v", text) w.WriteHeader(200) w.Write(nil)