mirror of https://github.com/velour/catbase.git
commit
0c867ceeb1
|
@ -129,6 +129,23 @@ func (p *ReminderPlugin) Message(message msg.Message) bool {
|
||||||
|
|
||||||
return true
|
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
|
return false
|
||||||
|
|
|
@ -64,6 +64,32 @@ func TestReminderParse(t *testing.T) {
|
||||||
assert.Contains(t, mb.Messages[0], "Easy cowboy, not sure I can parse that duration.")
|
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) {
|
func TestHelp(t *testing.T) {
|
||||||
mb := bot.NewMockBot()
|
mb := bot.NewMockBot()
|
||||||
c := New(mb)
|
c := New(mb)
|
||||||
|
|
Loading…
Reference in New Issue