picker: make pick a command

This commit is contained in:
Chris Sexton 2020-01-08 08:17:34 -05:00 committed by Chris Sexton
parent 595492a16b
commit 99817ad621
2 changed files with 18 additions and 1 deletions

View File

@ -35,7 +35,7 @@ func New(b bot.Bot) *PickerPlugin {
// This function returns true if the plugin responds in a meaningful way to the users message. // This function returns true if the plugin responds in a meaningful way to the users message.
// Otherwise, the function returns false and the bot continues execution of other plugins. // Otherwise, the function returns false and the bot continues execution of other plugins.
func (p *PickerPlugin) message(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool { func (p *PickerPlugin) message(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool {
if !strings.HasPrefix(message.Body, "pick") { if !strings.HasPrefix(message.Body, "pick") || !message.Command {
return false return false
} }

View File

@ -98,3 +98,20 @@ func TestKnownBrokenPick(t *testing.T) {
assert.NotContains(t, mb.Messages[0], "hot picks") assert.NotContains(t, mb.Messages[0], "hot picks")
log.Debug().Str("resp", mb.Messages[0]).Msg("choose") log.Debug().Str("resp", mb.Messages[0]).Msg("choose")
} }
func TestPickIsCommand(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
_ = c.message(makeMessage("!pick⌘ { bagel/egg/smoked turkey/butte/cheese ⌘ fuck all that, just have a bagel and cream cheese }"))
assert.Len(t, mb.Messages, 1)
assert.Contains(t, mb.Messages[0], "I've chosen")
assert.NotContains(t, mb.Messages[0], "hot picks")
log.Debug().Str("resp", mb.Messages[0]).Msg("choose")
}
func TestPickMustBeCommand(t *testing.T) {
mb := bot.NewMockBot()
c := New(mb)
_ = c.message(makeMessage("pick⌘ { bagel/egg/smoked turkey/butte/cheese ⌘ fuck all that, just have a bagel and cream cheese }"))
assert.Len(t, mb.Messages, 0)
}