From ee1962b71ce5c3abe0d7efdd94ec7cd9c1044b93 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Mon, 18 Mar 2013 17:44:49 -0400 Subject: [PATCH] Adding ~= and =~ equality for factoids --- plugins/factoid.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/factoid.go b/plugins/factoid.go index 636a189..23f55cc 100644 --- a/plugins/factoid.go +++ b/plugins/factoid.go @@ -217,9 +217,14 @@ func (p *FactoidPlugin) learnAction(message bot.Message, action string) bool { return true } -// Checks body for the ~= operator -func changeOperator(body string) bool { - return strings.Contains(body, "=~") +// Checks body for the ~= operator returns it +func changeOperator(body string) string { + if strings.Contains(body, "=~") { + return "=~" + } else if strings.Contains(body, "~=") { + return "~=" + } + return "" } // If the user requesting forget is either the owner of the last learned fact or @@ -247,7 +252,8 @@ func (p *FactoidPlugin) forgetLastFact(message bot.Message) bool { // Allow users to change facts with a simple regexp func (p *FactoidPlugin) changeFact(message bot.Message) bool { - parts := strings.SplitN(message.Body, "=~", 2) + oper := changeOperator(message.Body) + parts := strings.SplitN(message.Body, oper, 2) userexp := strings.TrimSpace(parts[1]) trigger := strings.TrimSpace(parts[0]) @@ -342,7 +348,7 @@ func (p *FactoidPlugin) Message(message bot.Message) bool { return p.forgetLastFact(message) } - if changeOperator(message.Body) { + if changeOperator(message.Body) != "" { return p.changeFact(message) }