Closed grahamb closed 8 years ago
Looks great, nice that you added unit tests too!
Just re-pushed with fixes for the issues you found above.
Landed in b12c58ab7fd0d10f68e4cf984a84bbc1ce61b1f5. Took the liberty of renaming the decorate function to highlightUsername
. Thanks again!
Most IRC clients will highlight/notify on occurrences of your username/nick, without requiring that it be prefixed by a @ character. Slack normally works this way as well; if a human user types either 'grahamb' or '@grahamb' into Slack, I'll get a notification.
Bot users, however, only trigger notifications when the username has a @-prefix. This appears to be by design; see https://twitter.com/kylefuller/status/538475098416480256 for more details. It's unlikely that Slack will change this behaviour.
This commit adds a helper function to transform occurrences of a 'bare' username to one prefixed by an @ character. For example, "Hey grahamb, are you around?" gets transformed to "Hey @grahamb, are you around?", and thus triggers a notification. It does not replace inside a URL, so http://github.com/grahamb/slack-irc gets left alone.
Tests have been added for the decorator itself, as well as its implementation inside the Bot class. When a Bot receives a message and runs
sendToSlack
, it gets the usernames of the Slack users currently in the Slack channel, and runsdecorateBareUsernameWithAt
against each user and the message text.