rmcafee / discord_ex

Discord Elixir Library
MIT License
48 stars 13 forks source link

Correct return type of actionable_message_for* helpers. #28

Closed dkolb closed 7 years ago

dkolb commented 8 years ago

The spec for actionable_message_for?/3 and actionable_message_for_me?/2 both explicitly state boolean for the return value.

However, _message_in_private_channel?/2, _message_mentions_user?/2, and _message_mentions_me?/2 all return either a single item from the list DiscordEx.RestClient.Resources.User.dm_channels/0 for the first or a single mention from payload["mentions"] for the second or third.

The result is that you end up executing what is essentially x || y where x and y are either nil or some non-nil, non-boolean value. The result is that you get back from the actionable helper functions either x if x is not nil, y if x is nil and y is not nil, or nil if both x and y are nil.

When using the if clause in Elixir, non-nil values are truthy and nil values are falsey, so you won't notice the error until you start leveraging case statements or the with clause, which use pattern matching.

This pull request fixes that by correcting the result of Enum.find/2.

rmcafee commented 7 years ago

Makes sense - thanks @dkolb for the PR!