diff --git a/plugins/reminder/reminder.go b/plugins/reminder/reminder.go index cd9803d..f610412 100644 --- a/plugins/reminder/reminder.go +++ b/plugins/reminder/reminder.go @@ -129,6 +129,23 @@ func (p *ReminderPlugin) Message(message msg.Message) bool { return true } + } else if len(parts) == 2 && strings.ToLower(parts[0]) == "list" && strings.ToLower(parts[1]) == "reminders" { + var response string + p.mutex.Lock() + if len(p.reminders) == 0 { + response = "no pending reminders" + } else { + counter := 1 + for _, reminder := range p.reminders { + if reminder.channel == channel { + response += fmt.Sprintf("%d) %s -> %s :: %s @ %s\n", counter, reminder.from, reminder.who, reminder.what, reminder.when) + counter++ + } + } + } + p.mutex.Unlock() + p.Bot.SendMessage(channel, response) + return true } return false diff --git a/plugins/reminder/reminder_test.go b/plugins/reminder/reminder_test.go index 5337ab6..907f1b5 100644 --- a/plugins/reminder/reminder_test.go +++ b/plugins/reminder/reminder_test.go @@ -64,6 +64,32 @@ func TestReminderParse(t *testing.T) { assert.Contains(t, mb.Messages[0], "Easy cowboy, not sure I can parse that duration.") } +func TestEmptyList(t *testing.T) { + mb := bot.NewMockBot() + c := New(mb) + assert.NotNil(t, c) + res := c.Message(makeMessage("!list reminders")) + assert.Len(t, mb.Messages, 1) + assert.True(t, res) + assert.Contains(t, mb.Messages[0], "no pending reminders") +} + +func TestList(t *testing.T) { + mb := bot.NewMockBot() + c := New(mb) + assert.NotNil(t, c) + res := c.Message(makeMessage("!remind testuser in 5m don't fail this test 1")) + assert.True(t, res) + res = c.Message(makeMessage("!remind testuser in 5m don't fail this test 2")) + assert.True(t, res) + res = c.Message(makeMessage("!list reminders")) + assert.True(t, res) + assert.Len(t, mb.Messages, 3) + assert.Contains(t, mb.Messages[2], "1) tester -> testuser :: don't fail this test 1 @ ") + assert.Contains(t, mb.Messages[2], "2) tester -> testuser :: don't fail this test 2 @ ") +} + + func TestHelp(t *testing.T) { mb := bot.NewMockBot() c := New(mb)