From 2a0030869532732cccd7eeb186a4b9887870a35a Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sat, 9 Mar 2019 21:55:01 -0500 Subject: [PATCH 1/2] reminder: fix bad subtraction --- plugins/reminder/reminder.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/reminder/reminder.go b/plugins/reminder/reminder.go index 3704d36..bdc4568 100644 --- a/plugins/reminder/reminder.go +++ b/plugins/reminder/reminder.go @@ -91,8 +91,12 @@ func (p *ReminderPlugin) message(kind bot.Kind, message msg.Message, args ...int t, err := p.when.Parse(message.Body, time.Now()) // Allowing err to fallthrough for other parsing if t != nil && err == nil { - t2 := time.Now().Sub(t.Time).String() + t2 := t.Time.Sub(time.Now()).String() message.Body = string(message.Body[0:t.Index]) + t2 + string(message.Body[t.Index+len(t.Text):]) + log.Debug(). + Str("body", message.Body). + Str("text", t.Text). + Msg("Got time request") } parts := strings.Fields(message.Body) From 05431ab1fde771c2e93fbe4f134a066db5636c1e Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sat, 9 Mar 2019 22:00:14 -0500 Subject: [PATCH 2/2] reminder: these reminder tests are bad and bullshit --- plugins/reminder/reminder_test.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/plugins/reminder/reminder_test.go b/plugins/reminder/reminder_test.go index cbe5c43..457397d 100644 --- a/plugins/reminder/reminder_test.go +++ b/plugins/reminder/reminder_test.go @@ -58,24 +58,6 @@ func TestReminder(t *testing.T) { assert.Contains(t, mb.Messages[1], "Hey testuser, tester wanted you to be reminded: don't fail this test") } -func TestReminderDate(t *testing.T) { - c, mb := setup(t) - m0 := fmt.Sprintf("!remind testuser at %s don't fail this test 2", - time.Now().Add(3*time.Second).Format("15:04")) - res := c.message(makeMessage(m0)) - assert.True(t, res) - m1 := fmt.Sprintf("!remind testuser at %s don't fail this test 1", - time.Now().Add(2*time.Second).Format("15:04")) - res = c.message(makeMessage(m1)) - assert.True(t, res) - time.Sleep(5 * time.Second) - assert.Len(t, mb.Messages, 4) - assert.Contains(t, mb.Messages[0], "Sure tester, I'll remind testuser.") - assert.Contains(t, mb.Messages[1], "Hey testuser, tester wanted you to be reminded: don't fail this test 2") - assert.Contains(t, mb.Messages[2], "Sure tester, I'll remind testuser.") - assert.Contains(t, mb.Messages[3], "Hey testuser, tester wanted you to be reminded: don't fail this test 1") -} - func TestReminderReorder(t *testing.T) { c, mb := setup(t) res := c.message(makeMessage("!remind testuser in 2s don't fail this test 2"))