mirror of https://github.com/velour/catbase.git
meme: refactor
impossible: fix bug where it was eating all messages
This commit is contained in:
parent
0891713523
commit
7dfa5bf891
|
@ -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)
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue