From b1a4fd20503a62019a372f30f2c76b6476a71975 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Thu, 27 Sep 2018 22:47:24 -0400 Subject: [PATCH] merge a spaced out count into one in the case of an emojy or anything with a space really --- plugins/counter/counter.go | 5 ++++- plugins/counter/counter_test.go | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/plugins/counter/counter.go b/plugins/counter/counter.go index 7b7c94f..790396b 100644 --- a/plugins/counter/counter.go +++ b/plugins/counter/counter.go @@ -358,7 +358,10 @@ func (p *CounterPlugin) Message(message msg.Message) bool { itemName)) return true - } else if len(parts) == 1 { + } else if len(parts) <= 2 { + if (len(parts) == 2) && (parts[1] == "++" || parts[1] == "--") { + parts = []string{parts[0] + parts[1]} + } // Need to have at least 3 characters to ++ or -- if len(parts[0]) < 3 { return false diff --git a/plugins/counter/counter_test.go b/plugins/counter/counter_test.go index 868de7b..a83b6aa 100644 --- a/plugins/counter/counter_test.go +++ b/plugins/counter/counter_test.go @@ -99,6 +99,15 @@ func TestCounterOne(t *testing.T) { assert.Equal(t, mb.Messages[0], "tester has 1 test.") } +func TestCounterOneWithSpace(t *testing.T) { + mb := bot.NewMockBot() + c := New(mb) + assert.NotNil(t, c) + c.Message(makeMessage(":test: ++")) + assert.Len(t, mb.Messages, 1) + assert.Equal(t, mb.Messages[0], "tester has 1 :test:.") +} + func TestCounterFour(t *testing.T) { mb := bot.NewMockBot() c := New(mb)